Hello all! Was hoping I could procure a little help here, I'm in a bit over my head. I'm using FFmpeg for Windows, trying to write a batch file that'll transfer a large folder of MKV videos into MP4 containers. No conversion or video format changes, just a container change.
I have been using the line
ffmpeg -i INPUT.mkv -codec:a copy -codec:v copy OUTPUT.mp4
This works well, but it only copies across one audio track (my MKV has two), and it requires me to name the input and output.
What I'd like is a batch file that performs that action on all MKVs in a certain folder, one at a time, and outputs them with an identical name. Something like
ffmpeg -i f:\videos\*.mkv -codec:a copy -codec:a2 copy -codec:v copy f:\newvideos\*.mp4
If possible, it would erase the MKV after it generates the MP4 version.
I don't know enough about ffmpeg or about batch files to write that properly, though. Can someone offer me a little help and show me how that's done, if it can be at all? I'd very much appreciate it.
+ Reply to Thread
Results 1 to 15 of 15
I don't recommend auto erase , because if there are errors, you lost your source file. (remove the del line)
This is for copying 1video and 1st 2 audio streams into mp4
for %%a in ("*.mkv") do ffmpeg -i %%a -map 0:0 -vcodec copy -map 0:1 -acodec copy -map 0:2 %%~na.mp4 del *.mkv pause
In case you haven't used batch files before
1) place copy of ffmpeg.exe in same directory as videos to be converted
2) open file in notepad in same directory, copy & paste that code (again, I would remove the "del *.mkv" line), save it, rename .txt extension to .bat
3) double click .bat
If they are not in the same directory, then you have to specify full pathnames
Another reason NOT to auto delete, is this code assumes video is track 0, 1st audio is track 1, 2nd audio is track 2. But you can have different numbering in mkv's.... e.g. -map 0:0 specifies track 0 (usually it's the video track, but not always)
Thank you for that, poisondeathray, does exactly what I wanted!
Only problem is that it doesn't seem to enjoy the company of spaces in filenames. It works flawlessly if I have a video called "Sandwich.mkv" in the folder, but if I have "Tomato sandwich.mkv" it'll say "Tomato: no such file or directory". I tried putting some quote marks around particular parts of the command, assuming that was what it needed, but couldn't find the right part. Is there something I need to do to have it process spaces in filenames?
Other than that, thanks a ton.
I don't know of any way around having spaces. I'm not a programmer but IIRC, DOS filenames require no spaces. Most CLI programs will "barf" if you have spaces, because the word after the space is assumed to be a new command. So use a batch file rename utility, to insert underscore or rename (search google) before running the .bat
A slight modification should do the trick.
for %%a in (*.mkv) do ffmpeg -i "%%a" -map 0:0 -vcodec copy -map 0:1 -acodec copy -map 0:2 "%%~na".mp4 del *.mkv pausePB
Nice autodidact, I'll have to remember that trick
ffmpeg.exe can be invoked from any directory / folder by adding its location (for example, C:\ffmpeg) to PATH which has worked from the DOS days through Windows 7. Just a bit of a shortcut that has been very useful to me.
http://en.wikipedia.org/wiki/PATH_%28variable%29 has some info about PATH.
Last edited by russell_t; 14th Jan 2012 at 18:51.
Blackwindow, Your question is off the subject of this thread (ffmpeg-script-batch-file) but since it's here... With ffmpeg easiest way is make a video of the image as long as the length of your video. To make a 30 second video from your image:
"C:\Users\Bud\Desktop\MEGA_Trimmed_Tabbed_2\bin\De bug\ffmpeg" -loop 1 -f image2 -i "C:\Users\Bud\Desktop\img001.jpg" -c:v libx264 -t 30 "C:\Users\Bud\Desktop\img001_IMG2VID_2.mp4"
Now overlay it with the video insertion:
ffmpeg -i "C:\Users\Bud\Desktop\img001_IMG2VID_1.mp4" -vf "movie='C\:\\Users\\Bud\\Desktop\\birthday with audio.flv'",scale=100:75[video1];[in][video1]overlay=10:10 -crf 20 -q:v 2 "C:\Users\Bud\Desktop\img001_IMG2VID_1_OVRLY_3.mp4 "
That will put the video in the top left corner and sized to 200x150. To move /adjust change the Scale=w:h parameter and the overlay=X:Y
You will get:
Took 2 minutes:
Last edited by Budman1; 26th Aug 2015 at 02:06.
which one is input and output video. i really dont understand your commands.
img001.jpg its image file isnt it? Im trying to understand your commands.
I just want to use 1 videofile and 1 images.
you use 3 video file. so i dont understand which one is input and output.
Last edited by blackwindow11; 25th Aug 2015 at 23:50.
Blackwindow11, The first string takes a JPG (img001.jpg) and turns it into a 30 second MP4 (img001_IMG2VID_2.mp4).
The second string uses the MP4 (JPG image 30 seconds long) and overlays it with the movie (birthday with audio.flv), scaled to 200X150 and placed at overlay position 0:0 and creates the final MP4(img001_IMG2VID_1_OVRLY_2.mp4)
Blackwindow11, It would save space and time if you would have included your command and error so I could check it.??? Also I know of no way to keep an Image displayed for long enough to play the overlayed video of perhaps several minutes unless you turn the image into a constant video the same length as the overlayed one.
I double checked the internet and only found how to overlay an image onto a video not the other way around. If I understand you correctly, you want a stable 'IMAGE' with a 'VIDEO' playing within it. correct.?? Please post the command you used to try it (cut and paste).