VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors.
Please consider supporting us by disabling your ad blocker or buy a VSO converter software :)
+ Reply to Thread
Page 1 of 5
1 2 3 ... LastLast
Results 1 to 30 of 144
Thread
  1. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    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 http://ffmpeg.zeranoe.com/builds/ and choose latest 32bit Static version.



    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.
    Click image for larger version

Name:	batch0.png
Views:	5025
Size:	63.5 KB
ID:	18041



    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.
    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
    Now save it, File->Save as, change to All files under Save as type and save it as batch.bat.
    Click image for larger version

Name:	batch1b.png
Views:	4243
Size:	73.6 KB
ID:	18071



    Just double click on the batch.bat to start converting. You will see any errors in the command line box.
    Click image for larger version

Name:	batch3.png
Views:	90846
Size:	50.4 KB
ID:	18040



    When it's done just press enter in the command line window.
    Click image for larger version

Name:	batch2b.png
Views:	90018
Size:	45.0 KB
ID:	18070



    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 libvo_aacenc -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 libvo_aacenc -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
    Last edited by Baldrick; 29th May 2013 at 02:54.
    Quote Quote  
  2. Member
    Join Date
    Feb 2009
    Location
    India
    Search Comp PM
    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.
    Quote Quote  
  3. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    This is a batch ffmpeg tutorial...not how to batch convert in general.
    Quote Quote  
  4. 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... )
    Quote Quote  
  5. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    Scanning what it contains would be very complex from just a batch file.
    Last edited by Baldrick; 16th Sep 2013 at 07:28.
    Quote Quote  
  6. Originally Posted by Baldrick View Post
    Scanning what it contains would be very complex from just a batch file.
    I agree with you....the only thing I can actually think of, right now, is some kind of BAT toolchain...
    I will think on it some more and report here if I can find a decent solution, if that's ok with you...
    Quote Quote  
  7. 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 22:18. Reason: more info
    Quote Quote  
  8. Member
    Join Date
    Nov 2013
    Location
    United States
    Search PM
    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.
    Quote Quote  
  9. Member
    Join Date
    Nov 2013
    Location
    United States
    Search PM
    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
    Quote Quote  
  10. Originally Posted by mahjohn View Post
    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?
    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
    But it won't work if the codecs aren't MP4 compatible.

    [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 19:33.
    Quote Quote  
  11. Member
    Join Date
    Nov 2013
    Location
    United States
    Search PM
    Thanks for the help....worked a treat.
    Quote Quote  
  12. Member
    Join Date
    Dec 2013
    Location
    Los Angeles, Ca
    Search Comp PM
    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
    Quote Quote  
  13. 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
    That will convert all WMV files in indicated folder (\\server\share\folder\) and all sub folders down from there. You must have read and write access to the share, of course.
    Last edited by jagabo; 14th Dec 2013 at 07:11.
    Quote Quote  
  14. Member
    Join Date
    Dec 2013
    Location
    Los Angeles, Ca
    Search Comp PM
    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 found
    Last edited by Tom Dewey; 14th Dec 2013 at 13:11.
    Quote Quote  
  15. del: command not found
    The equivalent of "del" (delete) in dos is "rm" (remove) in linux
    http://www.faqs.org/docs/linux_intro/app2.html
    Quote Quote  
  16. Originally Posted by Tom Dewey View Post
    Thanks, but unfortunately it didn't work. The server is Linux.
    And I said you have to run the batch file on Windows, accessing the folders/files via an SMB share.
    Quote Quote  
  17. Member
    Join Date
    Dec 2013
    Location
    Los Angeles, Ca
    Search Comp PM
    Thanks, I'll try again
    Quote Quote  
  18. I'm pretty sure the whole "for" syntax isn't going to work in Linux.
    Quote Quote  
  19. Member
    Join Date
    Nov 2013
    Location
    United States
    Search PM
    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.
    Quote Quote  
  20. Originally Posted by mahjohn View Post
    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.
    I would never do that until I'd verified the conversions worked. Otherwise you'll completely lose the video.
    Quote Quote  
  21. 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.
    Quote Quote  
  22. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    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.
    Quote Quote  
  23. 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 11:41. Reason: Additional information.
    Quote Quote  
  24. Member
    Join Date
    Apr 2014
    Location
    Denmark
    Search PM
    @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
    Quote Quote  
  25. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    ConverterCrazy: And did you get any working method? Any script you can share?
    Quote Quote  
  26. Member
    Join Date
    Dec 2006
    Location
    United States
    Search Comp PM
    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.
    Quote Quote  
  27. Member KneeGrow's Avatar
    Join Date
    Aug 2007
    Location
    "Not Taw City, but T...!"
    Search Comp PM
    HOW can I batch extract the audio LOSSLESS out of any files with ffmpeg

    no-one seems to have presets for THAT one, oddly enough.

    thanks.
    Looking for the subtitles of: Hk tt0997023 - Lime tt0269480 - Desideria tt0081724 - La cl sur la porte tt0077348 (tt=iMDb.com)
    Quote Quote  
  28. Originally Posted by KneeGrow View Post
    HOW can I batch extract the audio LOSSLESS out of any files with ffmpeg

    no-one seems to have presets for THAT one, oddly enough.

    thanks.
    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
    Quote Quote  
  29. Member KneeGrow's Avatar
    Join Date
    Aug 2007
    Location
    "Not Taw City, but T...!"
    Search Comp PM
    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
    and this batchfile
    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
    my problem is that I can't seem to combine the 3 properly

    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 KneeGrow; 13th Aug 2014 at 17:20.
    Looking for the subtitles of: Hk tt0997023 - Lime tt0269480 - Desideria tt0081724 - La cl sur la porte tt0077348 (tt=iMDb.com)
    Quote Quote  
  30. Originally Posted by KneeGrow View Post
    that's strange, since I always assumed lossless requires no transcoding whatsoever.
    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




    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:

    ffmpeg -i video.mp4 -vn -acodec copy audio.m4a
    Right, how did you know that input was mp4 and that the audio was AAC ? What if the desired audio was stream #4 ? What if file was a TS or MKV ? or RMVB ? What if it's cook audio? the m4a extension would be incorrect, you'd get an error

    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.
    Yes you can, but at least some information about both source and target is required

    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 possible
    Last edited by poisondeathray; 13th Aug 2014 at 16:53.
    Quote Quote  



Similar Threads