With ffmpeg can you convert and multiplex almost every video file. And as it's a command line converter can you batch convert all your files at once with a basic windows/dos script. Like convert all your video files to mp4 with custom ffmpeg commands. Convert all video files audio to wav.
Tools:
ffmpeg
Guide:
Download ffmpeg from https://www.videohelp.com/software/ffmpeg
Extract the ffmpeg.exe from the 7z file with 7zip and put it in same folder as your video files.
Create a folder named newfiles in your video folder.
Start notepad and type the following to convert all your video files to mp4 with h264 video and aac audio. See more examples at the bottom of this guide.
Now save it, File->Save as, change to All files under Save as type and save it as batch.bat.Code:for %%a in ("*.*") do ffmpeg -i "%%a" -c:v libx264 -preset slow -crf 20 -c:a libvo_aacenc -b:a 128k "newfiles\%%~na.mp4" pause
Just double click on the batch.bat to start converting. You will see any errors in the command line box.
When it's done just press enter in the command line window.
Done!
Batch ffmpeg examples:
Convert all *.avi files to mp4 with h264 and aac audio
Code:for %%a in ("*.avi") do ffmpeg -i "%%a" -c:v libx264 -preset slow -crf 20 -c:a aac -b:a 128k "newfiles\%%~na.mp4" pause
Convert *.mkv files to mp4 and just copy the video and audio streams
Code:for %%a in ("*.mkv") do ffmpeg -i "%%a" -vcodec copy -acodec copy "newfiles\%%~na.mp4" pause
Convert *.* files to wav audio
Code:for %%a in ("*.*") do ffmpeg -i "%%a" "newfiles\%%~na.wav" pause
Multiplex *.avi and *.wav files with same name to avi
Code:for %%a in ("*.avi") do ffmpeg -i "%%~na.wav" -i "%%~na.avi" -acodec copy -vcodec copy "newfiles\%%~na.avi" pause
Other tips:
Put ffmpeg.exe in for example C:\ffmpeg and make the newfiles folder under C:\newfiles and you never have to move around the ffmpeg.exe and make new newfiles folder all the time. You just make the batch.bat file in the video folder.
Your batch.bat script should look this then:
Code:for %%a in ("*.*") do "C:\ffmpeg\ffmpeg" -i "%%a" -c:v libx264 -preset slow -crf 20 -c:a aac -b:a 128k "C:\newfiles\%%~na.mp4" pause
More ffmpeg examples:
http://ffmpeg.org/trac/ffmpeg/wiki
http://cfc.kizzx2.com/index.php/muxing-audio-and-video-with-ffmpeg/
ffmpeg commands explained:
http://ffmpeg.org/ffmpeg.html
+ Reply to Thread
Results 1 to 30 of 216
-
Last edited by Baldrick; 7th Apr 2021 at 16:23.
-
I believe "Video to Video " from Media Converter does exactly this once you have selected and set your presets. Best part is that you can mix the source files such as avi,. mp4, m4v or mkv and may be in any location and they will all be ripped to the same parameter set in the preset. This will most certainly prevent any typing errors.
-
This is a batch ffmpeg tutorial...not how to batch convert in general.
-
Hello!
First of all, many thanks to Baldric for this guide (ffmpeg batch convert scripting is surely saving me an awful lot of time!).
I'm currently investigating a way to enhance the process described in this topic.
My ideal batch script would do the following:
1. load all *.SOMETHING files in a folder for conversion with ffmpeg; (OK, this works so far)
2. scan if all streams contained into each single *.SOMETHING file match certain codecs:
a) if so, simply -a:c copy and -v:c copy them into an MP4 container;
b) if not, just convert the relevant stream(s), then multiplex it/them into an MP4 container with the matching ones.
Any tips on how to do this?
(I'll be sure to post mine here as well, as soon as I can find some...)
-
Scanning what it contains would be very complex from just a batch file.
Last edited by Baldrick; 16th Sep 2013 at 08:28.
-
-
Hey, some great info you've got there. I was just wondering if there's a way that ffmpeg can copy one audio channel to another (overwriting it, not combining it) in an AVI file without having to re-encode the video... and do it in a batch file?
I've got a couple hundred videos with only 1 audio channel and I'd like to clone the left to the right. (or vise-versa)
Thanks.Last edited by Doctorwhok9; 5th Oct 2013 at 23:18. Reason: more info
-
Thanks....this saves me a lot of time (scripting retard), as I would have one line in my .bat file that I would edit with the location of the .mkv....and the location of the .mp4 i wanted it to become. (stop laughing). It worked....takes a couple of minutes is all, but tedious.
-
How can I modify the script to scan through sub-folders, converting every .mkv file it finds to a .mp4 and putting the .mp4 file in the same folder as the .mkv it was converted from?
thanks -
Recursive remux MKV to MP4 batch file:
Code:dir/b/s *.mkv >mkvlist.txt for /F "delims=;" %%F in (mkvlist.txt) do ffmpeg.exe -i "%%F" -vcodec copy -acodec copy "%%~dF%%~pF%%~nF.mp4" del mkvlist.txt
[edit]
One note: I cut/pasted this from a few batch files and haven't actually tried it. So beware. Test it on a few folders before trying it on a drive with zillions of files.Last edited by jagabo; 7th Dec 2013 at 20:33.
-
How can I batch convert specific videos in a server file directory with ffmpeg?
Ffmpeg is installed on the Linux Apache webserver and is working great.
I can convert individual videos one at a time, but I'm struggling to write a batch render script.
In the /vidclips directory, there are several thousand folders:
cd /var/www/vhosts/website.com/htdocs/secure/vidclips/20060530 - 20131212
Inside each of these folders are wmv files that I want to convert to an mp4 version of the same name, written to the same folder.
Trying to figure out how to apply this command, " ffmpeg -i 20070125h.wmv -strict -2 -crf 18 -s 640x360 20070125h-360p.mp4",
to several hundred folders from 20070125 through 20080509.
I would really appreciate some advice,
Thanks -
If you can share the folder you can use the method in post #10 in Windows. Just replace the ffmpeg command with yours.
Code:dir/b/s "\\server\share\folder\*.wmv" >filelist.txt for /F "delims=;" %%F in (filelist.txt) do "c:\program files\ffmpeg\bin\ffmpeg.exe" -i "%%F" -strict -2 -crf 18 -s 640x360 "%%~dF%%~pF%%~nF.mp4" del filelist.txt
Last edited by jagabo; 14th Dec 2013 at 08:11.
-
Thanks, but unfortunately it didn't work. The server is Linux.
-bash: syntax error near unexpected token `"delims=;"'
root@ns0000000:~# del filelist.txt
for /F "delims=;" %%F in (mkvlist.txt) do ffmpeg.exe -i "%%F" -vcodec copy -aco dec copy "%%~dF%%~pF%%~nF.mp4"
del mkvlist.txt
No command 'del' found, did you mean:
Command 'mdel' from package 'mtools' (main)
Command 'delp' from package 'fp-utils-2.4.4' (universe)
Command 'el' from package 'oneliner-el' (universe)
Command 'tel' from package 'orville-write' (universe)
Command 'deal' from package 'deal' (universe)
Command 'hdel' from package 'hfsutils' (main)
Command 'bel' from package 'belier' (universe)
Command 'qdel' from package 'slurm-llnl-torque' (universe)
Command 'qdel' from package 'gridengine-client' (universe)
Command 'qdel' from package 'torque-client-x11' (universe)
Command 'qdel' from package 'torque-client' (universe)
del: command not found
root@ns0000000:~#
root@ns0000000:~# for /F "delims=;" %%F in (mkvlist.txt) do ffmpeg.exe -i "%%F" -vcodec copy -acodec copy "%%~dF%%~pF%%~nF.mp4"
-bash: syntax error near unexpected token `"delims=;"'
root@ns4007033:~# del mkvlist.txt
No command 'del' found, did you mean:
Command 'mdel' from package 'mtools' (main)
Command 'delp' from package 'fp-utils-2.4.4' (universe)
Command 'el' from package 'oneliner-el' (universe)
Command 'tel' from package 'orville-write' (universe)
Command 'deal' from package 'deal' (universe)
Command 'hdel' from package 'hfsutils' (main)
Command 'bel' from package 'belier' (universe)
Command 'qdel' from package 'slurm-llnl-torque' (universe)
Command 'qdel' from package 'gridengine-client' (universe)
Command 'qdel' from package 'torque-client-x11' (universe)
Command 'qdel' from package 'torque-client' (universe)
del: command not foundLast edited by Tom Dewey; 14th Dec 2013 at 14:11.
-
del: command not found
http://www.faqs.org/docs/linux_intro/app2.html -
-
as a follow up, this works well....i also added a line to del *.mkv, however to cleanup the leftover .mkv's....however, be careful with this automated deletion of files.
-
-
Hi @baldrick
I have 100s of videos in different containers with varying resolution, aspect ratios, quality and formats that I want to convert to MKV H.264 video and AC3 (Dolby Digital, if possible) audio at the highest quality.
I would like to do it via a batch file using VidCoder or Handbrake as these applications take care of cropping automatically. But, will use FFMPEG or any other you suggest.
I can take care of A/R correction manually for each file using MKVMergeGUI as you had suggested in an earlier question a long time ago. I must confess I'm technically moron.
Please help and in sept-by-step procedure.
Thanks. -
I don't know how to do that. I just do basic conversions with command line software. I use GUIs for more advanced stuff like cropping.
-
Thanks @baldrick.
I hope someone reads my post and can suggest a way out! This forum is very good. Thanks to people like you and others, I have almost always received a solution.
Latest update on my problem:
I got the help in private.Last edited by ConverterCrazy; 27th Mar 2014 at 12:41. Reason: Additional information.
-
@ConverterCrazy
I have made a script that can run on Windows, that will give you some options in batch converting using FFmpeg.
I have not build in cropping, but please let me know if and how you would like that implemented.
You can get the tool here: http://sye.dk/convert/
/Kenny -
ConverterCrazy: And did you get any working method? Any script you can share?
-
I tried this (came here after trying and failing), with the option of taking an .m4a audio file and over-writing the existing one in an .mp4/H.264 video file. I need to do this with dozens of files. The new audio is the old, except de-hiss'd, normalized, and with several fades placed.
However, using map and copy with ffmpeg doesn't seem to work right:
1. The resulting file ends up 8MB larger (this is acceptable)
2. All tools show the audio in the mp4, they all show proper info for all the streams (vid and aud).
3. Quicktime, however, shows the audio track ONLY has a zero length 0:00:00.0
4. The resultant video plays (sort of), but the audio does not, in all players
5. The video loses something, and in some players, pausing or doing any effect (slow, fast play, etc.) causes things similar to keyframe loss or corruption. VLC loses initial keyframes sort-of giving medium gray as the keyframe until about 10 seconds in.
6. All the feedback from ffmpeg is spot on, as expected.
I've tried changing the syntax a little each time, but it always returns the same stream (so -map 1:a:0 = -map 1:a = -map 1, etc.).
cl string: "ffmpeg -i video-01.mp4 -i audio-01.m4a -map 0:v -vcodec copy -map 1:a -acodec copy newvideo-01.mp4"
Am I missing or overlooking something in the ffmpeg help? or doing something blatantly stupid?
All of the audio was recorded at different distances (and therefore, levels), so the normalization is absolutely necessary.
I can't even find a frontend that will do this (just re-muxing in the audio over the old audio in the mp4). I can do this for avi in seconds, but not mp4.
To avoid long strings (and unicode issues) everything is in the same directory, and this is under unix. -
The reason is you can't - at least you can't without knowing some details about the file. That's true for both audio & video. It can't do a generic demux of everything of any file, because you would have to script contingencies for every type of video and audio . For example, what if you have files that have multiple audio & video tracks? What if there were different types of audio? What if that audio is incompatible in a certain container? It has to know the specific raw audio format used in order to get the proper extension - either that or you could use a generic wide compatibility container like mka.
If you have known details about a certain bunch of files with the same characteristics, then it can be done in a batch audio stream copy -
that's strange, since I always assumed lossless requires no transcoding whatsoever.
why would ffmpg need to know what's in the container in order to get it out? that makes no sense, since any old program and it's motherboard can DETECT what's in it. I'd assume ffmpeg can too.
check out this command:
Code:ffmpeg -i video.mp4 -vn -acodec copy audio.m4a
Code:for %%a in ("*.mp4") do ffmpeg -i "%%a" -c:a libvo_aacenc -b:a 128k "newfiles\%%~na.m4a" pause
Code:for /l %%x in ("*.*") do ( echo %%x ffmpeg -i -acodec copy "newfiles\%%~na.m4a" ) pause
The command works on a video of which the name is known. That's nice, but not what's efficient.
all the guis accept a bunch of files, and yes they wanna know the TARGET specs, but the source specs, they don't need user input for that!!!?
Perhaps you meant TARGET specs and not SOURCE specs?
Or are you talking about ripping CDs? cos that's NOT what I meant.
Even so, ffmpeg CAN CAN CAN do that, only not in batch. Which is why I came here:
an ALREADY existing command, but in batch.Last edited by KneeRow; 13th Aug 2014 at 18:20.
Looking for subtitles of: Höök tt0997023, Lime tt0269480, La clé sur la porte tt0077348. tt=iMDb.com Found Desideria tt0081724 subtitle! :-) -
Lossless can involve transcoding: for example, demuxing is lossless (stream copy) . But uncompressed audio is also lossess, but will be much larger in filesize if original audio was compressed. Flac is also lossless (losslessly compressed) . The term "lossless" just implies no quality loss
That is my point. There are 100's of different combinations, and it's impossible to script them all
This works on a video of which the name is known. That's nice, but not what's efficient.
all the gui accept a bunch of files, and yes they wanna know the TARGET specs, but the source specs, they don't need user input for that!!!?
Perhaps you meant TARGET specs and not SOURCE specs?
Even so, ffmpeg CAN CAN CAN do that, only not in batch. Which is why I came here:
an ALREADY existing command, but in batch.
If you have mp4's with aac audio as the only audio track
Code:for %a in ("*.mp4") do ffmpeg -i "%a" -c:a copy "%~na.aac"
Or if you want to remove adts header
Code:for %a in ("*.mp4") do ffmpeg -i "%a" -c:a copy -absf aac_adtstoasc "%~na.m4a"
But you see that doesn't work if some of the mp4's have mp3 audio, or pcm, or maybe something other audio, because the output file extension "aac" or "m4a" is hardcoded into the commandline . And if they have multiple audio, only the 1st is copied. That' s what I mean by at least some known characteristics
If that's what you were asking for, only MP4's with 1 AAC track, then that's your answer. But earlier you asked for ANY file - which implies all file types , under every situation - which isn't possibleLast edited by poisondeathray; 13th Aug 2014 at 17:53.
Similar Threads
-
Best Way To Batch Convert DVR-MS and WTV Files
By dj4monie in forum Video ConversionReplies: 39Last Post: 25th Jun 2012, 19:17 -
Best way to batch convert xvid/avi files to mkv/x264 files?
By gaikokujinkyofusho in forum Video ConversionReplies: 1Last Post: 13th Jan 2012, 07:31 -
batch convert .mpg (MPEG2) files?
By shun in forum Video ConversionReplies: 2Last Post: 8th Jan 2009, 09:44 -
Hi, need a program to batch multiplex.
By mmdmmd in forum AudioReplies: 2Last Post: 18th Oct 2008, 14:50 -
Hi all, I need program to batch de-multiplex mpg files with 2 audio tracks
By mmdmmd in forum AudioReplies: 4Last Post: 14th Oct 2008, 16:57