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
  • 1
  • 6
  • See duplicate question for an approach. If you've tried to adapt this and it didn't work, please update your post here and explain what exactly you have done so far and where you got stuck. – slhck Sep 20 '19 at 13:06
  • 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 Sep 20 '19 at 17:46
  • -1 if you are asking how to do the context menu with command on a file, then you can use a simpler example than the wildly complex ffmpeg command first. Like the DIR command or COPY command. Then apply the principle to ffmpeg. And being so specific as to ask re ffmpeg and with the context menu is not very useful to many people – barlop Sep 20 '19 at 18:41
  • 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) – G-Man Says 'Reinstate Monica' Sep 20 '19 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](https://superuser.com/q/1484557/354511#comment2239171_1484557).  (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) – G-Man Says 'Reinstate Monica' Sep 20 '19 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. – G-Man Says 'Reinstate Monica' Sep 20 '19 at 19:36
  • G-Man> Jesus man. If you wanted additional information you could have asked, irony and nitpicking every little thing I've said in such a negative manner isn't being helpful. 1+2). I do think my question was clear. My goal was to have a context menu entry where it would use FFmpeg to encode any video file to .mp4 losslessly. I've merely asked how to do that. It's possible for questions to have more than one part anyway but in this case, there are multiple steps to reach the goal. Also, AFAIK, creating just a .bat file to do the encoding vs. creating a .bat file to use it as a part of (cont'd) – Slade Sep 20 '19 at 23:34
  • (cont'd) a context menu entry would need a different command so I thought I'd tell people what I want to do exactly. Why jumping to the conclusion I haven't researched? I have (re)searched, including several ffmpeg/cmd related questions from this site. They weren't able to help me to do what I want. You can insult my intelligence if you like, I maintain sites like this exist in order to ask questions and learn stuff. 5). That's a mistake on my part, I meant to say "my question is about changing the container rather than converting". 6+7). These are valid points. I'll take them into account. – Slade Sep 20 '19 at 23:51
  • barlop> That doesn't even make sense. Both your -1 and your reasoning.My question was about FFMpeg because I wanted to do use that to do something. Commands would be different if I wanted something different and/or I was using another program. There are all kinds of questions in here, some about really specific "niche" stuff. I do believe being able to convert any video file to another losslessly with two clicks, using the context menu would be something quite useful to many people, since it's simple and fast, without using a gui or typing commands. it's fine if you disagree, it is my opinion. – Slade Sep 21 '19 at 00:02
  • 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) – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:12
  • 1
    (Cont’d) …  comes to you and says, ‘‘I need to drive to Chicago; what do I need to know?’’  You’re going to assume that he’s asking for directions; which route is shortest and which is fastest; is there a scenic route; are there tolls or other restrictions; can you recommend any places to stop along the way.  You might refer him to an article that gives directions and addresses those other points.  You’re going to ***assume*** that he knows how to read English, knows how to drive, has a driver’s license, has a vehicle (or has access to one), … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:12
  • 1
    (Cont’d) …  understands the concept of American money, ***has*** some money (or a credit card), knows how to buy gasoline, and probably other things.  If it turns out that he doesn’t, you’ll throw your hands in the air in despair and say that he’s asking for too much information in the guise of a single question.  That’s my point ①.  (11) Why do you jump to the conclusion that I jumped to the conclusion that you didn’t do any research?  I *asked* whether you had researched your question because you showed so little evidence of having done so.  You cited *one* (external) reference.   … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:12
  • 1
    (Cont’d) …  Well, [SU] has over 4000 questions about FFmpeg, over 2500 of which have answers.   How many of them did you read?   Did you, for example, read [this₁](https://superuser.com/q/758080/354511 "ffmpeg: Converting MKV to MP4 losslessly"), [this₂](https://superuser.com/q/932730/354511 "FFmpeg MKV to MP4 conversion loses subtitles"), [this₃](https://superuser.com/q/903257/354511 ".MKV to .MP4 with two soundtracks"), [this₄](https://superuser.com/q/1436294/354511 "How do I convert an MKV file to MP4 that has two audio streams and I need only one of them, with ffmpeg?"),   … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:13
  • 1
    (Cont’d) …  [this₅](https://superuser.com/q/1231460/354511 "FFmpeg MKV to MP4 results in black screen with no sound"), [this₆](https://superuser.com/q/1092685/354511 "Use FFmpeg To Convert .MKV to .MP4 With Conversion Settings"), [this₇](https://superuser.com/q/1081457/354511 "How to convert a video file from MKV …?") and/or [this₈](https://superuser.com/q/472420/354511 "... convert[ing] MKV to MP4 while retaining the original quality")? (Disclosure: I didn’t do more than skim them, so I don’t know whether they *answer* your question; but they came up in a quick search.) … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:13
  • 1
    (Cont’d) …  (12) OK, I said that I didn’t really want any additional information from you, but I did (in point ④) ask you to tell us how your attempts failed.  Again, I was trying to help you to ask a better question.  Imagine that you call your doctor and say “I’m sick; what should I do?”, but you refuse to describe your symptoms.  How much help do you expect your doctor to be able to provide?  Same deal here; if you don’t tell people what’s going wrong with what you’re trying, they’ll be less able to help you. … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:14
  • 1
    (Cont’d) …  (13) Regarding my original point ⑤ (“my question is about changing the container rather than converting”), thank you for validating and vindicating my attention to details (a.k.a. “nitpicking”).  (14) I haven’t down voted this question, and I’m undecided as to whether it deserves a down vote.  But I partially agree with @barlop’s point, because it’s the same as the point I made in my initial comments, and illustrated with my driving-to-Chicago example.  … (Cont’d) – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:14
  • 1
    (Cont’d) …  Here’s a simpler analogy: if you have no skill at juggling or walking on stilts, you shouldn’t start off by trying to do both at once. Get one thing working, then add the next layer of complexity. barlop’s criticism isn’t so much about your question as it is about your approach. barlop is suggesting that you (a) develop an FFmpeg command that you can type at the command prompt, (b) learn how to write a batch script that does something simple (like copy files), (c) learn how to do a context menu entry that does something simple, *and **only then*** start to combine them. – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:14

2 Answers2

1

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
  • 10,831
  • 10
  • 47
  • 78
  • 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 Sep 23 '19 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:https://www.sevenforums.com/tutorials/19449-default-file-type-associations-restore.html but that only resulted in having to set an "open with" program again – Slade Sep 23 '19 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 Sep 23 '19 at 14:31
  • I've tried manually adding them with filetypesman and while they appear that way, clicking at the command either opens the "open with" window or gives a " is not a valid win32 application" error message, depending whether I quote or double-quote the "C:\Users\username\Documents\Programs\Portable\FFmpeg 20190916\bin\ffmpeg.exe -i \"%1\" -c copy \"%1.mp4\"" command. Not sure what to do next :/ – Slade Sep 23 '19 at 14:36
  • 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) – G-Man Says 'Reinstate Monica' Sep 25 '19 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. – G-Man Says 'Reinstate Monica' Sep 25 '19 at 20:17
  • @G-Man Where you wrote "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 " <-- The poster "Slade", has no interest or understanding even in the most basic troubleshooting. – barlop Sep 26 '19 at 00:01
  • @G-Man Considering you've found so many flaws with his question, and he has not addressed it, why have you not downvoted it? What does it take for you to downvote a qusetion? – barlop Sep 26 '19 at 00:06
  • @G-Man I do understand your intentions were good but I still believe you've also been overly negative and judgemental for no good reason. 1. I've already addressed your "3 questions in 1" argument, I'm not sure why you repeat it. Again: a). In my question, I've mentioned I've been experimenting with .bat files and the "with a "Send to" menu shortcut perhaps?" point signals clearly I have *some* experience with context menu entries too. It's not like I've asked how to write a novel in japanese without being able to write the alphabet. (continued) – Slade Sep 27 '19 at 00:08
  • b). Things are connected and I am sure you know better than me that depending on what I'd want to do and the given conditions, different procedures, let alone commands apply. I wanted to describe the whole picture. Not sure why my answer didn't satisfy you the first time but I can't do anything about that. To be honest, I wouldn't make a fuzz or point the finger at someone even he had asked twenty (20) questions but hey that's just me. 2. I've already mentioned I've tried Biswapriyo advice and I couldn't get it work. I've even mentioned the error messages I've received. (continued) – Slade Sep 27 '19 at 00:10
  • I've actually got it to work now so I am gonna go ahead and mark his as the right answer (and eventually remove my "I couldn't make it work" comments since they would only confuse anyone looking to achieve something similar, running into this question in the future. My problems were a). I was trying to convert some files which for some reason couldn't be converted anyway + b). Yes, the spaces in the pathfile you've also mentioned. Which is the second thing among all your arguments (along with your original point #5) I recognize as a valid point and I've actually wanted to thank you about that. – Slade Sep 27 '19 at 00:12
  • But: 3. It's statements like the whole "you jump to the conclusion I jumped to" thing that cross the line of being snarky to the point of being almost ouright spiteful. Both your tone with repeating stuff I've said, theatrical rants like the "I am disappointed that" one, as much as asking me whether I've read the question #1, 2#, #5 etc. I did. But in the same spirit you could very well ask: "yes, but have you read the question #17, how about the question #141?". I am honestly sure you understand how unecessary all this is. Which brings me to my main point and the reason I am typing all this: – Slade Sep 27 '19 at 00:16
  • Life is short my friend. I don't have a crystal ball but If I had to guess, you appear to be a grown man (like me), certainly above the average intelligence. Just ask yourself: "Do I really need to be like this, with random strangers online even?". "Couldn't I make my point without all the semi-venomous sarcasm?. "Couldn't I just go ahead and give an answer to the dude?" – Slade Sep 27 '19 at 00:17
  • (the fact someone, Biswapriyo in this case spent his valueable time and simply answered to me without demonstrating the same behaviour shows that maybe, just maybe, there might be another point of view, a much more positive one you could maybe consider adopting? Not for me. For you. Or if you couldn't provide an answer maybe just share the piece of knoweledge you are able to. "Hey guy, don't use spaces (you did say that...well...in a very certain manner) or if you do, use quotes (haven't said that from the start)" without the aforementioned tone? – Slade Sep 27 '19 at 00:19
  • Or even If you can't help or think that a question is completely asinine and the OP is a plain idiot...perhaps not say anything at all? But again, that's my point of view. You don't have to agree. Go ahead and trash it if you want, I am telling you with the best of intentions really and without being ironic or patronizing at all. I mean, at the end of the day, it's your choice, I am merely suggesting another way to look at things. Or at least please don't end up like barlop who every night, thinks of all the questions he downvoted in here (prolly Reddit too), feels proud then go to bed. :-) – Slade Sep 27 '19 at 00:23
  • You guys are really spamming this comments section with lots and lots of comments in a row. You should not post 7 comments in a row in comments, that is abusing the system. Well used Upvotes and Downvotes are vital for the quality of the site. Poor quality material should be downvoted. – barlop May 12 '21 at 14:09
  • You guys are really spamming this comments section with lots and lots of comments in a row. You should not post 7 comments in a row in comments, that is abusing the system. Well used Upvotes and Downvotes are vital for the quality of the site. Poor quality material should be downvoted. Also Gwen where you say " Slade obviously is sloppy, crude & nót-smart" Indeed but there is no benefit to pointing out that he isn't smart. – barlop May 12 '21 at 14:18
  • @barlop spam? Says the toxic guy who has FOUR repetitive comments. Dude, you're asking for downvotes in a venomous despicable manner. YOU are what makes this site so eeewwwww, and drives people away. Delete that comment FIRST. Until then you got NO credit whatsoever. And if you ask for a downvote ..... ***give reasons!***. What you do is ***completely*** unproductive, helps no-one except you. Hiding behind "quality" while you especially so clearly ***lower*** the quality, is ridiculous. Why NOT 7 comments in a row, as long as they make sense. Your comments don't even make sense in pairs. – GwenKillerby May 12 '21 at 18:12
  • Wow, this thread of comments shows us what is so _WRONG_ with ***Superuser*** in particular & possibly, all of online commenting. All 3 posters are _WRONG_ in different degrees. Of the three posters, @barlop is the móst wrong, especially when he says ***"why have you not downvoted it? What does it take for you to downvote a qusetion?"***. This is proof of the sick culture here, where downvoting is some sort of síck sport, & people apparently derive _status_ from doing that a LOT. G-man has a point that Slade is unclear in what doesn't work for , but he's just a tat too emotional about it... => – GwenKillerby May 12 '21 at 18:37
  • And Slade is of course also below par with his way of non-response, not saying what he did or DIDNT do, in following Biswapriyo's advice. I admit to a soft spot for @G-ManSays'ReinstateMonica' cause of Monica, he should be just a bit more forgiving. While Slade obviously is a bit sloppy, there's no need to be so b!tshy about it. Slade is overreacting with all his "ooo you so 'judgemental' stuff", I mean really dude, GROW UP. Both Slade and G-man are overreacting a bit. It would be good for the atmosphere if everyone tried to stay on topic, businesslike, leave the emostuff. But both are in most – GwenKillerby May 12 '21 at 18:40
  • both are in most aspects very precise and do _quite_ a good job of commenting and clarificaton. Not all of the time, but most of the time you can see the effort they both put into it. Having said that, while @Slade and G-Man are overreacting in a manner that is a leettle emo, it's Barlop who is the truly evil one here. I mean, ASKING for downvotes? This is sooooo not what downvoting is intended for!! This borders on evil. Perhaps bored evilness, but still. It's like asking for a booking or a red card in football, also a thing which is ***Just. Not. Done!*** I have spoken. GK – GwenKillerby May 12 '21 at 18:49
  • @GwenKillerby You are now just copy pasting your comments and by copy pasting now, you are just spamming even more blatantly. I don't know if you are doing it just as vandalism or if you are trying to cover up the fact that you insulted a user saying " " Slade obviously is sloppy, crude & nót-smart"" Either way, copy pasting heaps of your comments and spamming the comment section with them is not right. – barlop May 12 '21 at 20:08
  • @barlop I repeated my comments, because it seemed as if someone had deleted them. I've now deleted the duplicates. Follow my example, and delete the **repetitive stuff** YOU wrote, and **apologize** for asking for downvotes. IMO, that's sick, just unhealthy behavior. – GwenKillerby May 25 '21 at 14:15
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

  • 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. – GwenKillerby May 25 '21 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. – Phani Rithvij May 26 '21 at 13:11
  • funny, but batch is the only one i have some knowledge of.... – GwenKillerby Jul 01 '21 at 13:12