3

I want to create a right click/context menu entry named "Convert to MP4" available to every video file (or at least MKV, if every video file isn't possible), where it would do launch FFmpeg from a set location (let's say "C:\Users\Username\Documents\Programs\Portable\FFmpeg 20190916\bin") and do just that, create a MP4 version (lossless encoding / just change the container) of the input video file. The output file (MP4) should appear in the same folder with the input file. Ideally, I'd like to be able to do that with selecting (Ctrl+click) more than one file at a time too (but not necessarily every video file in the folder).

I understand this should be possible by creating a bat file and then somehow integrating it in the context menu (with a "Send to" menu shortcut perhaps?). I don't really know CMD that well, though, and I am not sure what should I do so FFmpeg catches the specific file(s) and how to get the output file(s) in the same folder with the input.

For starters, I've tried to adapt a bat file based on this answer to the question you've linked as a duplicate to see, seeing If I can come up with a bat file that works (before I do the "context menu/registry" part), but, as I've said, I really don't know how to use cmd properly and it didn't work. I don't think my question is a duplicate of that question you've suggested, because mine deals with video rather than audio (I'm not saying it's much different in principle, I just don't know what to type instead of those audio codecs in order to adapt it) and most importantly, mine is about changing the container rather than converting so I would need different commands. So based on that answer and info found in A quick guide to using FFmpeg to convert media files at Opensource.com, I've created bat files with commands such as:

ffmpeg -i %1 copy "%~n1.mp4

ffmpeg -i "%1" "%1.mp4

ffmpeg -i "%1.mkv" "%1.mp4

ffmpeg -i input.mkv -c:av copy output.mp4

(I used the full pathname to FFmpeg, but omitted it here for ease of reading) then tried to drop an MKV file to them, but none work. I've already checked several questions in here dealing with cmd and FFmpeg but they weren't able to help so I'll appreciate any help given!

Slade
  • 87

2 Answers2

2

Procedure:

  • Get the associated file type for .MKV extension with assoc .mkv command. For example, the default output is .mkv=WMP11.AssocFile.MKV.

  • Open the associated file type in Registry Editor (aka. regedit). For example, the default registry is HKEY_CLASSES_ROOT\WMP11.AssocFile.MKV.

  • To add a command in registry first modify ffmpeg command to correct format. The simple command to convert mkv to mp4 is ffmpeg -i abc.mkv -c copy abc.mp4. The file name has to be replaced with a placeholder variable %1. So, the command becomes ffmpeg -i %1 -c copy %1.mp4.

  • Add the registry with this following command run as administrator.

REG ADD "HKCR\WMP11.AssocFile.MKV\Shell\Convert to MP4\command" /VE /T REG_EXPAND_SZ /D "ffmpeg.exe -i \"%1\" -c copy \"%1.mp4\"" 

This command adds the ffmpeg -i %1 -c copy %1.mp4 command in HKCR\WMP11.AssocFile.MKV\Shell\Convert to MP4\command registry key to default value. The REG_EXPAND_SZ type is necessary so that shell can deduce %1 to the file name. The back slash and double quote are to handle spaces in full path of MKV file.

  • The command can be changed or configured in different ways. Make sure to change the default file association WMP11.AssocFile.MKV to your current setup. Also put the full path of ffmpeg.exe executable file. To suppress the popup of command prompt window, append cmd /Q /C with the ffmpeg command. See this answer for that trick.
Biswapriyo
  • 11,584
0

There is a sample github repo at https://github.com/kachurovskiy/VideoContextMenu

Note: I'm not the author, Adding this as an answer because the comments above are too many.

It does the following

all.reg - use this to set the explorer menu option

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT*\shell\Video: to h264\command] @="C:\VideoContextMenu\convert.bat "%1""

convert.bat - this is the main command located in C:\VideoContextMenu (or at another location)

set i=%~n1
set x=%~x1
set o=%i%.mp4
if exist %o% (
  set o=%i%-h264.mp4
)
ffmpeg -i "%i%%x%" -vcodec libx264 -preset slow -acodec aac "%o%"
exit

Also, follow the accepted answer to constrain it to specific file types.

i.e. HKCR\WMP11.AssocFile.MKV\Shell\Convert to MP4 for .mkv