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!

17
  • 1
    Most of the commands you included are missing a " at the end. Aside from that, open the command prompt, cd into the directory where the .bat file is and run it from there so you can see the errors it gives you.
    – Worthwelle
    Commented Sep 20, 2019 at 17:46
  • 1
    (1) So you’re saying that (a) you don’t know the FFmpeg command to do what you want, (b) you need help with batch files, and (c) you want help incorporating the functionality into the Windows Explorer context menu?  Perhaps you should have asked two or three separate questions, or at least been clearer about the fact that you had multiple separate areas of uncertainty.  Or better yet, you should have done the research to find the existing question(s) and answers about putting things into the context menu.  … (Cont’d) Commented Sep 20, 2019 at 19:36
  • 1
    (Cont’d) …  (2) I applaud you for actually trying things, and not just expecting to be given an answer. But have you tried researching your “a” question?  (3) See Worthwelle’s comment.  (4) Please don’t just say that the things you tried “didn’t work” — tell us how they failed.  (5) What you do say is confusing. In your first paragraph, you say that you want to change the container of the input video file, but in your third paragraph you lament that “it’s changing the container rather than converting”.  … (Cont’d) Commented Sep 20, 2019 at 19:36
  • 1
    (Cont’d) …  (6) Have you tried it with a pathname that doesn’t contain a space?  (7) Please don’t refer to “the second answer” of a question; different people see the answers in different orders. Link to the one you are talking about, or identify it uniquely some other way. Commented Sep 20, 2019 at 19:36
  • 1
    (8a) I didn’t really want any additional information from you. I was trying to help you, and I believe that my comments were helpful. (8b) Nothing I said was meant ironically, and I believe that I wasn’t inappropriately negative. (8c) When did I insult your intelligence? (9) As to nitpicking: well, the devil, obviously, is in the details. If you wanted a non-technical, non-detailed answer, you could have gone to Philosophy.SE and been told “Do or do not; there is no try.” and “Just do it.” (10) Suppose you live in New York, and somebody you know slightly (e.g., a friend of a friend) … (Cont’d) Commented Sep 25, 2019 at 20:12

2 Answers 2

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.
23
  • Hello there, thanks a lot for your reply! I really appreciate the fact you took your time to write it and actually explaining how things work.Unfortunately, that didn't work. 1. First of all, for some reason, I don't have a file association such as WMP11.AssocFile.MKV for mkv files. I've got WMP11.AssocFile.x for pretty much every other video file. assoc .mkv command revealed .mkv=mkvFile. I've tried doing what you've said for that anyway but although the command is added in the default value in the registry, it doesn't appear at the right click/context menu. (continued)
    – Slade
    Commented Sep 23, 2019 at 14:13
  • A while ago,for some reason (I think after deleting temp fles) something messed my extensions up. I've managed to set the default programs and actions again using programs such as Filetypesman but the .mkv extension didn't even appear there so I went ahead and added it manually. Which explains the associated file type being "mkvFile" rather than "WMP11.AssocFile.MKV". Is there any way to completely reset it btw? I tried the reg files from:sevenforums.com/tutorials/… but that only resulted in having to set an "open with" program again
    – Slade
    Commented Sep 23, 2019 at 14:22
  • Recognizing there's an issue with mkv. files I've just tried the procedure with avi. and mp4. files (made it "Convert to MKV" for mp4 files, my intention was to see whether the command gets added in the context menu at this point, not necessarily getting the ffmpeg command to work, although it should) but again although I've got a successful output in the cmd window and they appear in the registry at the location you've mentioned, they don't still don't appear at the right click/context menu. (continued)
    – Slade
    Commented Sep 23, 2019 at 14:31
  • 1
    Slade: (15) Having encouraged you to report on how things are failing, I’m a little disappointed that I don’t see any clear indication that you’ve tried Biswapriyo’s ffmpeg -i abc.mkv -c copy abc.mp4 command, and, if so, whether it works.  You were complaining that the “duplicate” question focused on the context menu part of the question, without telling you how to do the video processing.  Now @Biswapriyo is giving you a command to do the video processing, and you aren’t giving any feedback on it. … (Cont’d) Commented Sep 25, 2019 at 20:16
  • 1
    (Cont’d) …  (16) Having encouraged you to try a pathname that doesn’t contain spaces, I’m disappointed to see that you’re still using a path to FFmpeg that contains a space — and, apparently, not quoting it.   (16b) Since you use Windows 7, you may be able to use short names. Commented Sep 25, 2019 at 20:17
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

3
  • Could you perhaps comment each line of the batch file? Thanks! As far as I can see: - set i=%~n1 => Fills variable i with the filename but not the extension? - set x=%~x1 => Fills variable x with the extension? - set o=%i%.mp4 => Determines the output file as an MP4? - if exist %o% (set o=%i%-h264.mp4) => Adds a suffix h264 to the filename? WHY? - ffmpeg -i "%i%%x%" -vcodec libx264 -preset slow -acodec aac "%o%" => This does the actual conversion, but what exactly happens, is unclear to me. Commented May 25, 2021 at 12:18
  • @GwenKillerby that h264 suffix is just added to not overwrite an existing MP4 file with same name. You are right about all other steps. The ffmpeg command takes the original filename which is %i%%x% filename + extention as input and outputs to either %i%.mp4 if it already exists then to %i%-h264.mp4. Two things to note here 1. The main point is the registry file format 2. You need not write scripts in batch you can choose anything else like c++/py/c# just path to the executable needs to be correctly registered in the registry. Commented May 26, 2021 at 13:11
  • funny, but batch is the only one i have some knowledge of.... Commented Jul 1, 2021 at 13:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .