How do you convert an entire directory with ffmpeg?











up vote
90
down vote

favorite
42












How do you convert an entire directory/folder with ffmpeg via command line or with a batch script?










share|improve this question




























    up vote
    90
    down vote

    favorite
    42












    How do you convert an entire directory/folder with ffmpeg via command line or with a batch script?










    share|improve this question


























      up vote
      90
      down vote

      favorite
      42









      up vote
      90
      down vote

      favorite
      42






      42





      How do you convert an entire directory/folder with ffmpeg via command line or with a batch script?










      share|improve this question















      How do you convert an entire directory/folder with ffmpeg via command line or with a batch script?







      ffmpeg batch-processing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 11 '16 at 0:23

























      asked Apr 26 '11 at 0:19









      Eugene

      4,215154772




      4,215154772
























          12 Answers
          12






          active

          oldest

          votes

















          up vote
          103
          down vote



          accepted










          Previous answer will only create 1 output file called out.mov. To make a separate output file for each old movie, try this.



          for i in *.avi;
          do name=`echo $i | cut -d'.' -f1`;
          echo $name;
          ffmpeg -i "$i" "${name}.mov";
          done





          share|improve this answer



















          • 19




            If you're like me and have lots of spaces (and a few other problematic characters) in your file names, I'd suggest addding double quotes : ffmpeg -i "$i" "$name.mov";
            – Pif
            Dec 17 '12 at 22:36






          • 4




            I'm getting the error i was unexpected at this time.
            – Keavon
            May 17 '14 at 1:09






          • 4




            do name=`echo "${i%.*}"`; will work on file names with dots (and spaces) in them.
            – Nepoxx
            Jun 30 '15 at 14:50








          • 4




            Wow, this answer is incredibly overcomplicated. See one of the one-line answers.
            – foobarbecue
            Jun 11 '16 at 18:49










          • is this support for .bat in windows?
            – Jazuly
            Jun 30 at 6:12


















          up vote
          113
          down vote













          For Linux and macOS this can be done in one line, using parameter expansion to change the filename extension of the output file:



          for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done





          share|improve this answer























          • This is perfect, thank you! Here's full command that ended up working great for me: for i in *.avi; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 20 "${i%.avi}.mp4"; done
            – Phil Kulak
            Apr 28 '17 at 3:29










          • I am getting i was unexpected at this time. error in cmd, windows 10. I used following line: for i in *.mp3; do ffmpeg -i "$i" -map_metadata -1 -c:v copy -c:a copy "${i%.mp3}.mp3"; done
            – Junaid
            May 17 '17 at 7:13






          • 1




            @Junaid 1) Make sure to use a different name for the output file than the input, or output to another directory, because ffmpeg can't input and output to the same file. 2) I'm not sure if Bash commands work on Windows 10 natively. Maybe I should add to the answer that it is targeted towards systems that can natively use Bash such as Linux and macOS. lxs provided an Windows answer for this question.
            – LordNeckbeard
            May 17 '17 at 17:25












          • I suggest this is marked as the correct answer.
            – Alexandr Kurilin
            Apr 25 at 0:30


















          up vote
          46
          down vote













          And on Windows:



          FOR /F "tokens=*" %G IN ('dir /b *.flac') DO ffmpeg -i "%G" -acodec mp3 "%~nG.mp3"





          share|improve this answer

















          • 12




            if you run this command in a batch (.bat) file you need to double the % signs => %%
            – hB0
            May 17 '15 at 14:24










          • Any idea how to run this command but copy to a new file that includes the original file's metadata?
            – Barryman9000
            Feb 26 '16 at 17:53










          • @Barryman9000 this was a long time ago but I think there's an output file option you could pass
            – lxs
            Mar 21 '16 at 15:00










          • @lxs thanks for the follow up. I ended up doing it with Powershell by changing the new file's name to be the original file's date created stackoverflow.com/a/35671099/197472
            – Barryman9000
            Mar 21 '16 at 23:08










          • Used it for removing metadata. But it is giving me Access denied error. So I changed output file name with an extra space to make it new file. FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -i "%G" -map_metadata -1 -c:v copy -c:a copy "%~nG .mp3"
            – Junaid
            May 17 '17 at 7:27




















          up vote
          22
          down vote













          A one-line bash script would be easy to do - replace *.avi with your filetype:



          for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov  ; done





          share|improve this answer



















          • 4




            There should not be quotes around "*.avi", that makes bash think it's a string not a list of files
            – JZL003
            Jun 18 '15 at 1:57










          • whops. Thanks @JZL003!
            – yolk
            Nov 17 '15 at 19:49










          • The default encoder for .mov is libx264 (if available), but this encoder ignores -qscale. Remove it and use the default settings, or use -crf instead (default is -crf 23).
            – LordNeckbeard
            Aug 14 '16 at 19:29






          • 4




            This answer is better than the marked one.
            – Hal
            Aug 28 '17 at 8:57






          • 1




            If there are any spaces in the file name the command will fail because the backticked basename subshell isn't quoted. This is exactly why bash has shell expansion instead: for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov ; done
            – Calimo
            Feb 16 at 12:28


















          up vote
          12
          down vote













          To convert with subdirectories use e.g.



          find . -exec ffmpeg -i {} {}.mp3 ;





          share|improve this answer





















          • I used this, combined with this answer to convert VTT to SRT, to great effect. find -name "*.vtt" -exec ffmpeg -i {} {}.srt ;
            – grooveplex
            Jun 7 at 19:40










          • I this command, with slight modif to convert all mp4 to mp3: find *.mp4 -exec ffmpeg -i {} {}.mp3 ;
            – swdev
            Jun 15 at 23:28










          • Or, if you want to convert multiple file types: find . -name *.ogg -or -name *.wma -exec ffmpeg -i {} {}.mp3 ;
            – bonh
            Sep 26 at 18:36


















          up vote
          4
          down vote













          For anyone who wants to batch convert anything with ffmpeg but would like to have a convenient Windows interface, I developed this front-end:



          https://sourceforge.net/projects/ffmpeg-batch



          It adds to ffmpeg a window fashion interface, progress bars and time remaining info, features I always missed when using ffmpeg.






          share|improve this answer




























            up vote
            3
            down vote













            If you want a graphical interface to batch process with ffmpegX, try Quick Batcher. It's free and will take your last ffmpegX settings to convert files you drop into it.



            Note that you can't drag-drop folders onto Quick Batcher. So select files and then put them through Quick Batcher.






            share|improve this answer





















            • The "Quick Batcher" software is ONLY for MAC OS
              – Mohammad ElNesr
              Nov 1 '17 at 14:20


















            up vote
            3
            down vote













            for i in *.flac;
            do name=`echo "${i%.*}"`;
            echo $name;
            ffmpeg -i "${i}" -ab 320k -map_metadata 0 -id3v2_version 3 "${name}".mp3;
            done


            Batch process flac files into mp3 (safe for file names with spaces) using [1] [2]






            share|improve this answer






























              up vote
              3
              down vote













              If you have GNU parallel you could convert all .avi files below vid_dir to mp4 in parallel, using all except one of your CPU cores with



              find vid_dir -type f -name '*.avi' -not -empty -print0 |
              parallel -0 -j -1 ffmpeg -loglevel fatal -i {} {.}.mp4


              To convert from/to different formats, change '*.avi' or .mp4 as needed. GNU parallel is listed in most Linux distributions' repositories in a package which is usually called parallel.






              share|improve this answer




























                up vote
                3
                down vote













                I know this might be redundant but I use this script to batch convert files.



                old_extension=$1
                new_extension=$2

                for i in *."$old_extension";
                do ffmpeg -i "$i" "${i%.*}.$new_extension";
                done


                It takes 2 arguments to make it more flexible :




                1. the extension you want to convert from

                2. the new extension you want to convert to


                I create an alias for it but you can also use it manually like this:



                sh batch_convert.sh mkv mp4


                This would convert all the mkv files into mp4 files.



                As you can see it slightly more versatile. As long as ffmpeg can convert it you can specify any two extensions.






                share|improve this answer























                • Thats the best 👍
                  – Andreas Prang
                  Sep 29 at 10:29


















                up vote
                0
                down vote













                Another simple solution that hasn't been suggested yet would be to use xargs:



                ls *.avi | xargs -i -n1 ffmpeg -i {} "{}.mp4"



                One minor pitfall is the awkward naming of output files (e.g. input.avi.mp4). A possible workaround for this might be:



                ls *.avi | xargs -i -n1 bash -c "i={}; ffmpeg -i {} "${i%.*}.mp4""






                share|improve this answer





















                • shellcheck.net has a few suggestions regarding your examples.
                  – LordNeckbeard
                  Nov 27 at 18:59


















                up vote
                -2
                down vote













                little php script to do it:



                #!/usr/bin/env php
                <?php
                declare(strict_types = 1);
                if ($argc !== 2) {
                fprintf ( STDERR, "usage: %s dirn", $argv [0] );
                die ( 1 );
                }
                $dir = rtrim ( $argv [1], DIRECTORY_SEPARATOR );
                if (! is_readable ( $dir )) {
                fprintf ( STDERR, "supplied path is not readable! (try running as an administrator?)" );
                die(1);
                }
                if (! is_dir ( $dir )) {
                fprintf ( STDERR, "supplied path is not a directory!" );
                die(1);
                }
                $files = glob ( $dir . DIRECTORY_SEPARATOR . '*.avi' );
                foreach ( $files as $file ) {
                system ( "ffmpeg -i " . escapeshellarg ( $file ) . ' ' . escapeshellarg ( $file . '.mp4' ) );
                }





                share|improve this answer

















                • 1




                  A very limited scope answer as a user has to have PHP installed on their machine. The command line and batch file answers are much easier, and much less complex.
                  – ProfK
                  Nov 10 '17 at 9:06






                • 2




                  @ProfK PHP is 1 of the most popular languages on SO - second, Isaac's answer for sh is somewhat unreliable, in that it might rename your files to something else than the original, for example, it doesn't preserve newlines in the filename. lyx's bat script is even worse, it COMPLETELY IGNORES any file with newlines in the name. not sure why, not even a syntax error or anything, but it does (tested on win10). my php script has neither problems, thanks to escapeshellarg(), and works both on windows and linux. i agree its a edge-case though.
                  – hanshenrik
                  Nov 12 '17 at 12:43











                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5784661%2fhow-do-you-convert-an-entire-directory-with-ffmpeg%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                12 Answers
                12






                active

                oldest

                votes








                12 Answers
                12






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                103
                down vote



                accepted










                Previous answer will only create 1 output file called out.mov. To make a separate output file for each old movie, try this.



                for i in *.avi;
                do name=`echo $i | cut -d'.' -f1`;
                echo $name;
                ffmpeg -i "$i" "${name}.mov";
                done





                share|improve this answer



















                • 19




                  If you're like me and have lots of spaces (and a few other problematic characters) in your file names, I'd suggest addding double quotes : ffmpeg -i "$i" "$name.mov";
                  – Pif
                  Dec 17 '12 at 22:36






                • 4




                  I'm getting the error i was unexpected at this time.
                  – Keavon
                  May 17 '14 at 1:09






                • 4




                  do name=`echo "${i%.*}"`; will work on file names with dots (and spaces) in them.
                  – Nepoxx
                  Jun 30 '15 at 14:50








                • 4




                  Wow, this answer is incredibly overcomplicated. See one of the one-line answers.
                  – foobarbecue
                  Jun 11 '16 at 18:49










                • is this support for .bat in windows?
                  – Jazuly
                  Jun 30 at 6:12















                up vote
                103
                down vote



                accepted










                Previous answer will only create 1 output file called out.mov. To make a separate output file for each old movie, try this.



                for i in *.avi;
                do name=`echo $i | cut -d'.' -f1`;
                echo $name;
                ffmpeg -i "$i" "${name}.mov";
                done





                share|improve this answer



















                • 19




                  If you're like me and have lots of spaces (and a few other problematic characters) in your file names, I'd suggest addding double quotes : ffmpeg -i "$i" "$name.mov";
                  – Pif
                  Dec 17 '12 at 22:36






                • 4




                  I'm getting the error i was unexpected at this time.
                  – Keavon
                  May 17 '14 at 1:09






                • 4




                  do name=`echo "${i%.*}"`; will work on file names with dots (and spaces) in them.
                  – Nepoxx
                  Jun 30 '15 at 14:50








                • 4




                  Wow, this answer is incredibly overcomplicated. See one of the one-line answers.
                  – foobarbecue
                  Jun 11 '16 at 18:49










                • is this support for .bat in windows?
                  – Jazuly
                  Jun 30 at 6:12













                up vote
                103
                down vote



                accepted







                up vote
                103
                down vote



                accepted






                Previous answer will only create 1 output file called out.mov. To make a separate output file for each old movie, try this.



                for i in *.avi;
                do name=`echo $i | cut -d'.' -f1`;
                echo $name;
                ffmpeg -i "$i" "${name}.mov";
                done





                share|improve this answer














                Previous answer will only create 1 output file called out.mov. To make a separate output file for each old movie, try this.



                for i in *.avi;
                do name=`echo $i | cut -d'.' -f1`;
                echo $name;
                ffmpeg -i "$i" "${name}.mov";
                done






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 6 '17 at 16:06









                Jason Cemra

                351312




                351312










                answered Nov 20 '11 at 8:35









                Isaac

                1,090187




                1,090187








                • 19




                  If you're like me and have lots of spaces (and a few other problematic characters) in your file names, I'd suggest addding double quotes : ffmpeg -i "$i" "$name.mov";
                  – Pif
                  Dec 17 '12 at 22:36






                • 4




                  I'm getting the error i was unexpected at this time.
                  – Keavon
                  May 17 '14 at 1:09






                • 4




                  do name=`echo "${i%.*}"`; will work on file names with dots (and spaces) in them.
                  – Nepoxx
                  Jun 30 '15 at 14:50








                • 4




                  Wow, this answer is incredibly overcomplicated. See one of the one-line answers.
                  – foobarbecue
                  Jun 11 '16 at 18:49










                • is this support for .bat in windows?
                  – Jazuly
                  Jun 30 at 6:12














                • 19




                  If you're like me and have lots of spaces (and a few other problematic characters) in your file names, I'd suggest addding double quotes : ffmpeg -i "$i" "$name.mov";
                  – Pif
                  Dec 17 '12 at 22:36






                • 4




                  I'm getting the error i was unexpected at this time.
                  – Keavon
                  May 17 '14 at 1:09






                • 4




                  do name=`echo "${i%.*}"`; will work on file names with dots (and spaces) in them.
                  – Nepoxx
                  Jun 30 '15 at 14:50








                • 4




                  Wow, this answer is incredibly overcomplicated. See one of the one-line answers.
                  – foobarbecue
                  Jun 11 '16 at 18:49










                • is this support for .bat in windows?
                  – Jazuly
                  Jun 30 at 6:12








                19




                19




                If you're like me and have lots of spaces (and a few other problematic characters) in your file names, I'd suggest addding double quotes : ffmpeg -i "$i" "$name.mov";
                – Pif
                Dec 17 '12 at 22:36




                If you're like me and have lots of spaces (and a few other problematic characters) in your file names, I'd suggest addding double quotes : ffmpeg -i "$i" "$name.mov";
                – Pif
                Dec 17 '12 at 22:36




                4




                4




                I'm getting the error i was unexpected at this time.
                – Keavon
                May 17 '14 at 1:09




                I'm getting the error i was unexpected at this time.
                – Keavon
                May 17 '14 at 1:09




                4




                4




                do name=`echo "${i%.*}"`; will work on file names with dots (and spaces) in them.
                – Nepoxx
                Jun 30 '15 at 14:50






                do name=`echo "${i%.*}"`; will work on file names with dots (and spaces) in them.
                – Nepoxx
                Jun 30 '15 at 14:50






                4




                4




                Wow, this answer is incredibly overcomplicated. See one of the one-line answers.
                – foobarbecue
                Jun 11 '16 at 18:49




                Wow, this answer is incredibly overcomplicated. See one of the one-line answers.
                – foobarbecue
                Jun 11 '16 at 18:49












                is this support for .bat in windows?
                – Jazuly
                Jun 30 at 6:12




                is this support for .bat in windows?
                – Jazuly
                Jun 30 at 6:12












                up vote
                113
                down vote













                For Linux and macOS this can be done in one line, using parameter expansion to change the filename extension of the output file:



                for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done





                share|improve this answer























                • This is perfect, thank you! Here's full command that ended up working great for me: for i in *.avi; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 20 "${i%.avi}.mp4"; done
                  – Phil Kulak
                  Apr 28 '17 at 3:29










                • I am getting i was unexpected at this time. error in cmd, windows 10. I used following line: for i in *.mp3; do ffmpeg -i "$i" -map_metadata -1 -c:v copy -c:a copy "${i%.mp3}.mp3"; done
                  – Junaid
                  May 17 '17 at 7:13






                • 1




                  @Junaid 1) Make sure to use a different name for the output file than the input, or output to another directory, because ffmpeg can't input and output to the same file. 2) I'm not sure if Bash commands work on Windows 10 natively. Maybe I should add to the answer that it is targeted towards systems that can natively use Bash such as Linux and macOS. lxs provided an Windows answer for this question.
                  – LordNeckbeard
                  May 17 '17 at 17:25












                • I suggest this is marked as the correct answer.
                  – Alexandr Kurilin
                  Apr 25 at 0:30















                up vote
                113
                down vote













                For Linux and macOS this can be done in one line, using parameter expansion to change the filename extension of the output file:



                for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done





                share|improve this answer























                • This is perfect, thank you! Here's full command that ended up working great for me: for i in *.avi; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 20 "${i%.avi}.mp4"; done
                  – Phil Kulak
                  Apr 28 '17 at 3:29










                • I am getting i was unexpected at this time. error in cmd, windows 10. I used following line: for i in *.mp3; do ffmpeg -i "$i" -map_metadata -1 -c:v copy -c:a copy "${i%.mp3}.mp3"; done
                  – Junaid
                  May 17 '17 at 7:13






                • 1




                  @Junaid 1) Make sure to use a different name for the output file than the input, or output to another directory, because ffmpeg can't input and output to the same file. 2) I'm not sure if Bash commands work on Windows 10 natively. Maybe I should add to the answer that it is targeted towards systems that can natively use Bash such as Linux and macOS. lxs provided an Windows answer for this question.
                  – LordNeckbeard
                  May 17 '17 at 17:25












                • I suggest this is marked as the correct answer.
                  – Alexandr Kurilin
                  Apr 25 at 0:30













                up vote
                113
                down vote










                up vote
                113
                down vote









                For Linux and macOS this can be done in one line, using parameter expansion to change the filename extension of the output file:



                for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done





                share|improve this answer














                For Linux and macOS this can be done in one line, using parameter expansion to change the filename extension of the output file:



                for i in *.avi; do ffmpeg -i "$i" "${i%.*}.mp4"; done






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 5 at 4:38









                Boris

                1,0731326




                1,0731326










                answered Nov 17 '15 at 20:15









                LordNeckbeard

                43.1k13101133




                43.1k13101133












                • This is perfect, thank you! Here's full command that ended up working great for me: for i in *.avi; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 20 "${i%.avi}.mp4"; done
                  – Phil Kulak
                  Apr 28 '17 at 3:29










                • I am getting i was unexpected at this time. error in cmd, windows 10. I used following line: for i in *.mp3; do ffmpeg -i "$i" -map_metadata -1 -c:v copy -c:a copy "${i%.mp3}.mp3"; done
                  – Junaid
                  May 17 '17 at 7:13






                • 1




                  @Junaid 1) Make sure to use a different name for the output file than the input, or output to another directory, because ffmpeg can't input and output to the same file. 2) I'm not sure if Bash commands work on Windows 10 natively. Maybe I should add to the answer that it is targeted towards systems that can natively use Bash such as Linux and macOS. lxs provided an Windows answer for this question.
                  – LordNeckbeard
                  May 17 '17 at 17:25












                • I suggest this is marked as the correct answer.
                  – Alexandr Kurilin
                  Apr 25 at 0:30


















                • This is perfect, thank you! Here's full command that ended up working great for me: for i in *.avi; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 20 "${i%.avi}.mp4"; done
                  – Phil Kulak
                  Apr 28 '17 at 3:29










                • I am getting i was unexpected at this time. error in cmd, windows 10. I used following line: for i in *.mp3; do ffmpeg -i "$i" -map_metadata -1 -c:v copy -c:a copy "${i%.mp3}.mp3"; done
                  – Junaid
                  May 17 '17 at 7:13






                • 1




                  @Junaid 1) Make sure to use a different name for the output file than the input, or output to another directory, because ffmpeg can't input and output to the same file. 2) I'm not sure if Bash commands work on Windows 10 natively. Maybe I should add to the answer that it is targeted towards systems that can natively use Bash such as Linux and macOS. lxs provided an Windows answer for this question.
                  – LordNeckbeard
                  May 17 '17 at 17:25












                • I suggest this is marked as the correct answer.
                  – Alexandr Kurilin
                  Apr 25 at 0:30
















                This is perfect, thank you! Here's full command that ended up working great for me: for i in *.avi; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 20 "${i%.avi}.mp4"; done
                – Phil Kulak
                Apr 28 '17 at 3:29




                This is perfect, thank you! Here's full command that ended up working great for me: for i in *.avi; do ffmpeg -i "$i" -c:a aac -b:a 128k -c:v libx264 -crf 20 "${i%.avi}.mp4"; done
                – Phil Kulak
                Apr 28 '17 at 3:29












                I am getting i was unexpected at this time. error in cmd, windows 10. I used following line: for i in *.mp3; do ffmpeg -i "$i" -map_metadata -1 -c:v copy -c:a copy "${i%.mp3}.mp3"; done
                – Junaid
                May 17 '17 at 7:13




                I am getting i was unexpected at this time. error in cmd, windows 10. I used following line: for i in *.mp3; do ffmpeg -i "$i" -map_metadata -1 -c:v copy -c:a copy "${i%.mp3}.mp3"; done
                – Junaid
                May 17 '17 at 7:13




                1




                1




                @Junaid 1) Make sure to use a different name for the output file than the input, or output to another directory, because ffmpeg can't input and output to the same file. 2) I'm not sure if Bash commands work on Windows 10 natively. Maybe I should add to the answer that it is targeted towards systems that can natively use Bash such as Linux and macOS. lxs provided an Windows answer for this question.
                – LordNeckbeard
                May 17 '17 at 17:25






                @Junaid 1) Make sure to use a different name for the output file than the input, or output to another directory, because ffmpeg can't input and output to the same file. 2) I'm not sure if Bash commands work on Windows 10 natively. Maybe I should add to the answer that it is targeted towards systems that can natively use Bash such as Linux and macOS. lxs provided an Windows answer for this question.
                – LordNeckbeard
                May 17 '17 at 17:25














                I suggest this is marked as the correct answer.
                – Alexandr Kurilin
                Apr 25 at 0:30




                I suggest this is marked as the correct answer.
                – Alexandr Kurilin
                Apr 25 at 0:30










                up vote
                46
                down vote













                And on Windows:



                FOR /F "tokens=*" %G IN ('dir /b *.flac') DO ffmpeg -i "%G" -acodec mp3 "%~nG.mp3"





                share|improve this answer

















                • 12




                  if you run this command in a batch (.bat) file you need to double the % signs => %%
                  – hB0
                  May 17 '15 at 14:24










                • Any idea how to run this command but copy to a new file that includes the original file's metadata?
                  – Barryman9000
                  Feb 26 '16 at 17:53










                • @Barryman9000 this was a long time ago but I think there's an output file option you could pass
                  – lxs
                  Mar 21 '16 at 15:00










                • @lxs thanks for the follow up. I ended up doing it with Powershell by changing the new file's name to be the original file's date created stackoverflow.com/a/35671099/197472
                  – Barryman9000
                  Mar 21 '16 at 23:08










                • Used it for removing metadata. But it is giving me Access denied error. So I changed output file name with an extra space to make it new file. FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -i "%G" -map_metadata -1 -c:v copy -c:a copy "%~nG .mp3"
                  – Junaid
                  May 17 '17 at 7:27

















                up vote
                46
                down vote













                And on Windows:



                FOR /F "tokens=*" %G IN ('dir /b *.flac') DO ffmpeg -i "%G" -acodec mp3 "%~nG.mp3"





                share|improve this answer

















                • 12




                  if you run this command in a batch (.bat) file you need to double the % signs => %%
                  – hB0
                  May 17 '15 at 14:24










                • Any idea how to run this command but copy to a new file that includes the original file's metadata?
                  – Barryman9000
                  Feb 26 '16 at 17:53










                • @Barryman9000 this was a long time ago but I think there's an output file option you could pass
                  – lxs
                  Mar 21 '16 at 15:00










                • @lxs thanks for the follow up. I ended up doing it with Powershell by changing the new file's name to be the original file's date created stackoverflow.com/a/35671099/197472
                  – Barryman9000
                  Mar 21 '16 at 23:08










                • Used it for removing metadata. But it is giving me Access denied error. So I changed output file name with an extra space to make it new file. FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -i "%G" -map_metadata -1 -c:v copy -c:a copy "%~nG .mp3"
                  – Junaid
                  May 17 '17 at 7:27















                up vote
                46
                down vote










                up vote
                46
                down vote









                And on Windows:



                FOR /F "tokens=*" %G IN ('dir /b *.flac') DO ffmpeg -i "%G" -acodec mp3 "%~nG.mp3"





                share|improve this answer












                And on Windows:



                FOR /F "tokens=*" %G IN ('dir /b *.flac') DO ffmpeg -i "%G" -acodec mp3 "%~nG.mp3"






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jun 17 '14 at 21:34









                lxs

                2,80711217




                2,80711217








                • 12




                  if you run this command in a batch (.bat) file you need to double the % signs => %%
                  – hB0
                  May 17 '15 at 14:24










                • Any idea how to run this command but copy to a new file that includes the original file's metadata?
                  – Barryman9000
                  Feb 26 '16 at 17:53










                • @Barryman9000 this was a long time ago but I think there's an output file option you could pass
                  – lxs
                  Mar 21 '16 at 15:00










                • @lxs thanks for the follow up. I ended up doing it with Powershell by changing the new file's name to be the original file's date created stackoverflow.com/a/35671099/197472
                  – Barryman9000
                  Mar 21 '16 at 23:08










                • Used it for removing metadata. But it is giving me Access denied error. So I changed output file name with an extra space to make it new file. FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -i "%G" -map_metadata -1 -c:v copy -c:a copy "%~nG .mp3"
                  – Junaid
                  May 17 '17 at 7:27
















                • 12




                  if you run this command in a batch (.bat) file you need to double the % signs => %%
                  – hB0
                  May 17 '15 at 14:24










                • Any idea how to run this command but copy to a new file that includes the original file's metadata?
                  – Barryman9000
                  Feb 26 '16 at 17:53










                • @Barryman9000 this was a long time ago but I think there's an output file option you could pass
                  – lxs
                  Mar 21 '16 at 15:00










                • @lxs thanks for the follow up. I ended up doing it with Powershell by changing the new file's name to be the original file's date created stackoverflow.com/a/35671099/197472
                  – Barryman9000
                  Mar 21 '16 at 23:08










                • Used it for removing metadata. But it is giving me Access denied error. So I changed output file name with an extra space to make it new file. FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -i "%G" -map_metadata -1 -c:v copy -c:a copy "%~nG .mp3"
                  – Junaid
                  May 17 '17 at 7:27










                12




                12




                if you run this command in a batch (.bat) file you need to double the % signs => %%
                – hB0
                May 17 '15 at 14:24




                if you run this command in a batch (.bat) file you need to double the % signs => %%
                – hB0
                May 17 '15 at 14:24












                Any idea how to run this command but copy to a new file that includes the original file's metadata?
                – Barryman9000
                Feb 26 '16 at 17:53




                Any idea how to run this command but copy to a new file that includes the original file's metadata?
                – Barryman9000
                Feb 26 '16 at 17:53












                @Barryman9000 this was a long time ago but I think there's an output file option you could pass
                – lxs
                Mar 21 '16 at 15:00




                @Barryman9000 this was a long time ago but I think there's an output file option you could pass
                – lxs
                Mar 21 '16 at 15:00












                @lxs thanks for the follow up. I ended up doing it with Powershell by changing the new file's name to be the original file's date created stackoverflow.com/a/35671099/197472
                – Barryman9000
                Mar 21 '16 at 23:08




                @lxs thanks for the follow up. I ended up doing it with Powershell by changing the new file's name to be the original file's date created stackoverflow.com/a/35671099/197472
                – Barryman9000
                Mar 21 '16 at 23:08












                Used it for removing metadata. But it is giving me Access denied error. So I changed output file name with an extra space to make it new file. FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -i "%G" -map_metadata -1 -c:v copy -c:a copy "%~nG .mp3"
                – Junaid
                May 17 '17 at 7:27






                Used it for removing metadata. But it is giving me Access denied error. So I changed output file name with an extra space to make it new file. FOR /F "tokens=*" %G IN ('dir /b *.mp3') DO ffmpeg -i "%G" -map_metadata -1 -c:v copy -c:a copy "%~nG .mp3"
                – Junaid
                May 17 '17 at 7:27












                up vote
                22
                down vote













                A one-line bash script would be easy to do - replace *.avi with your filetype:



                for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov  ; done





                share|improve this answer



















                • 4




                  There should not be quotes around "*.avi", that makes bash think it's a string not a list of files
                  – JZL003
                  Jun 18 '15 at 1:57










                • whops. Thanks @JZL003!
                  – yolk
                  Nov 17 '15 at 19:49










                • The default encoder for .mov is libx264 (if available), but this encoder ignores -qscale. Remove it and use the default settings, or use -crf instead (default is -crf 23).
                  – LordNeckbeard
                  Aug 14 '16 at 19:29






                • 4




                  This answer is better than the marked one.
                  – Hal
                  Aug 28 '17 at 8:57






                • 1




                  If there are any spaces in the file name the command will fail because the backticked basename subshell isn't quoted. This is exactly why bash has shell expansion instead: for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov ; done
                  – Calimo
                  Feb 16 at 12:28















                up vote
                22
                down vote













                A one-line bash script would be easy to do - replace *.avi with your filetype:



                for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov  ; done





                share|improve this answer



















                • 4




                  There should not be quotes around "*.avi", that makes bash think it's a string not a list of files
                  – JZL003
                  Jun 18 '15 at 1:57










                • whops. Thanks @JZL003!
                  – yolk
                  Nov 17 '15 at 19:49










                • The default encoder for .mov is libx264 (if available), but this encoder ignores -qscale. Remove it and use the default settings, or use -crf instead (default is -crf 23).
                  – LordNeckbeard
                  Aug 14 '16 at 19:29






                • 4




                  This answer is better than the marked one.
                  – Hal
                  Aug 28 '17 at 8:57






                • 1




                  If there are any spaces in the file name the command will fail because the backticked basename subshell isn't quoted. This is exactly why bash has shell expansion instead: for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov ; done
                  – Calimo
                  Feb 16 at 12:28













                up vote
                22
                down vote










                up vote
                22
                down vote









                A one-line bash script would be easy to do - replace *.avi with your filetype:



                for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov  ; done





                share|improve this answer














                A one-line bash script would be easy to do - replace *.avi with your filetype:



                for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov  ; done






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited May 8 at 22:59

























                answered Jul 2 '11 at 22:29









                yolk

                474410




                474410








                • 4




                  There should not be quotes around "*.avi", that makes bash think it's a string not a list of files
                  – JZL003
                  Jun 18 '15 at 1:57










                • whops. Thanks @JZL003!
                  – yolk
                  Nov 17 '15 at 19:49










                • The default encoder for .mov is libx264 (if available), but this encoder ignores -qscale. Remove it and use the default settings, or use -crf instead (default is -crf 23).
                  – LordNeckbeard
                  Aug 14 '16 at 19:29






                • 4




                  This answer is better than the marked one.
                  – Hal
                  Aug 28 '17 at 8:57






                • 1




                  If there are any spaces in the file name the command will fail because the backticked basename subshell isn't quoted. This is exactly why bash has shell expansion instead: for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov ; done
                  – Calimo
                  Feb 16 at 12:28














                • 4




                  There should not be quotes around "*.avi", that makes bash think it's a string not a list of files
                  – JZL003
                  Jun 18 '15 at 1:57










                • whops. Thanks @JZL003!
                  – yolk
                  Nov 17 '15 at 19:49










                • The default encoder for .mov is libx264 (if available), but this encoder ignores -qscale. Remove it and use the default settings, or use -crf instead (default is -crf 23).
                  – LordNeckbeard
                  Aug 14 '16 at 19:29






                • 4




                  This answer is better than the marked one.
                  – Hal
                  Aug 28 '17 at 8:57






                • 1




                  If there are any spaces in the file name the command will fail because the backticked basename subshell isn't quoted. This is exactly why bash has shell expansion instead: for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov ; done
                  – Calimo
                  Feb 16 at 12:28








                4




                4




                There should not be quotes around "*.avi", that makes bash think it's a string not a list of files
                – JZL003
                Jun 18 '15 at 1:57




                There should not be quotes around "*.avi", that makes bash think it's a string not a list of files
                – JZL003
                Jun 18 '15 at 1:57












                whops. Thanks @JZL003!
                – yolk
                Nov 17 '15 at 19:49




                whops. Thanks @JZL003!
                – yolk
                Nov 17 '15 at 19:49












                The default encoder for .mov is libx264 (if available), but this encoder ignores -qscale. Remove it and use the default settings, or use -crf instead (default is -crf 23).
                – LordNeckbeard
                Aug 14 '16 at 19:29




                The default encoder for .mov is libx264 (if available), but this encoder ignores -qscale. Remove it and use the default settings, or use -crf instead (default is -crf 23).
                – LordNeckbeard
                Aug 14 '16 at 19:29




                4




                4




                This answer is better than the marked one.
                – Hal
                Aug 28 '17 at 8:57




                This answer is better than the marked one.
                – Hal
                Aug 28 '17 at 8:57




                1




                1




                If there are any spaces in the file name the command will fail because the backticked basename subshell isn't quoted. This is exactly why bash has shell expansion instead: for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov ; done
                – Calimo
                Feb 16 at 12:28




                If there are any spaces in the file name the command will fail because the backticked basename subshell isn't quoted. This is exactly why bash has shell expansion instead: for i in *.avi; do ffmpeg -i "$i" -qscale 0 "$(basename "$i" .avi)".mov ; done
                – Calimo
                Feb 16 at 12:28










                up vote
                12
                down vote













                To convert with subdirectories use e.g.



                find . -exec ffmpeg -i {} {}.mp3 ;





                share|improve this answer





















                • I used this, combined with this answer to convert VTT to SRT, to great effect. find -name "*.vtt" -exec ffmpeg -i {} {}.srt ;
                  – grooveplex
                  Jun 7 at 19:40










                • I this command, with slight modif to convert all mp4 to mp3: find *.mp4 -exec ffmpeg -i {} {}.mp3 ;
                  – swdev
                  Jun 15 at 23:28










                • Or, if you want to convert multiple file types: find . -name *.ogg -or -name *.wma -exec ffmpeg -i {} {}.mp3 ;
                  – bonh
                  Sep 26 at 18:36















                up vote
                12
                down vote













                To convert with subdirectories use e.g.



                find . -exec ffmpeg -i {} {}.mp3 ;





                share|improve this answer





















                • I used this, combined with this answer to convert VTT to SRT, to great effect. find -name "*.vtt" -exec ffmpeg -i {} {}.srt ;
                  – grooveplex
                  Jun 7 at 19:40










                • I this command, with slight modif to convert all mp4 to mp3: find *.mp4 -exec ffmpeg -i {} {}.mp3 ;
                  – swdev
                  Jun 15 at 23:28










                • Or, if you want to convert multiple file types: find . -name *.ogg -or -name *.wma -exec ffmpeg -i {} {}.mp3 ;
                  – bonh
                  Sep 26 at 18:36













                up vote
                12
                down vote










                up vote
                12
                down vote









                To convert with subdirectories use e.g.



                find . -exec ffmpeg -i {} {}.mp3 ;





                share|improve this answer












                To convert with subdirectories use e.g.



                find . -exec ffmpeg -i {} {}.mp3 ;






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 12 '16 at 16:59









                user2707001

                643712




                643712












                • I used this, combined with this answer to convert VTT to SRT, to great effect. find -name "*.vtt" -exec ffmpeg -i {} {}.srt ;
                  – grooveplex
                  Jun 7 at 19:40










                • I this command, with slight modif to convert all mp4 to mp3: find *.mp4 -exec ffmpeg -i {} {}.mp3 ;
                  – swdev
                  Jun 15 at 23:28










                • Or, if you want to convert multiple file types: find . -name *.ogg -or -name *.wma -exec ffmpeg -i {} {}.mp3 ;
                  – bonh
                  Sep 26 at 18:36


















                • I used this, combined with this answer to convert VTT to SRT, to great effect. find -name "*.vtt" -exec ffmpeg -i {} {}.srt ;
                  – grooveplex
                  Jun 7 at 19:40










                • I this command, with slight modif to convert all mp4 to mp3: find *.mp4 -exec ffmpeg -i {} {}.mp3 ;
                  – swdev
                  Jun 15 at 23:28










                • Or, if you want to convert multiple file types: find . -name *.ogg -or -name *.wma -exec ffmpeg -i {} {}.mp3 ;
                  – bonh
                  Sep 26 at 18:36
















                I used this, combined with this answer to convert VTT to SRT, to great effect. find -name "*.vtt" -exec ffmpeg -i {} {}.srt ;
                – grooveplex
                Jun 7 at 19:40




                I used this, combined with this answer to convert VTT to SRT, to great effect. find -name "*.vtt" -exec ffmpeg -i {} {}.srt ;
                – grooveplex
                Jun 7 at 19:40












                I this command, with slight modif to convert all mp4 to mp3: find *.mp4 -exec ffmpeg -i {} {}.mp3 ;
                – swdev
                Jun 15 at 23:28




                I this command, with slight modif to convert all mp4 to mp3: find *.mp4 -exec ffmpeg -i {} {}.mp3 ;
                – swdev
                Jun 15 at 23:28












                Or, if you want to convert multiple file types: find . -name *.ogg -or -name *.wma -exec ffmpeg -i {} {}.mp3 ;
                – bonh
                Sep 26 at 18:36




                Or, if you want to convert multiple file types: find . -name *.ogg -or -name *.wma -exec ffmpeg -i {} {}.mp3 ;
                – bonh
                Sep 26 at 18:36










                up vote
                4
                down vote













                For anyone who wants to batch convert anything with ffmpeg but would like to have a convenient Windows interface, I developed this front-end:



                https://sourceforge.net/projects/ffmpeg-batch



                It adds to ffmpeg a window fashion interface, progress bars and time remaining info, features I always missed when using ffmpeg.






                share|improve this answer

























                  up vote
                  4
                  down vote













                  For anyone who wants to batch convert anything with ffmpeg but would like to have a convenient Windows interface, I developed this front-end:



                  https://sourceforge.net/projects/ffmpeg-batch



                  It adds to ffmpeg a window fashion interface, progress bars and time remaining info, features I always missed when using ffmpeg.






                  share|improve this answer























                    up vote
                    4
                    down vote










                    up vote
                    4
                    down vote









                    For anyone who wants to batch convert anything with ffmpeg but would like to have a convenient Windows interface, I developed this front-end:



                    https://sourceforge.net/projects/ffmpeg-batch



                    It adds to ffmpeg a window fashion interface, progress bars and time remaining info, features I always missed when using ffmpeg.






                    share|improve this answer












                    For anyone who wants to batch convert anything with ffmpeg but would like to have a convenient Windows interface, I developed this front-end:



                    https://sourceforge.net/projects/ffmpeg-batch



                    It adds to ffmpeg a window fashion interface, progress bars and time remaining info, features I always missed when using ffmpeg.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 25 at 9:34









                    Eibel

                    411




                    411






















                        up vote
                        3
                        down vote













                        If you want a graphical interface to batch process with ffmpegX, try Quick Batcher. It's free and will take your last ffmpegX settings to convert files you drop into it.



                        Note that you can't drag-drop folders onto Quick Batcher. So select files and then put them through Quick Batcher.






                        share|improve this answer





















                        • The "Quick Batcher" software is ONLY for MAC OS
                          – Mohammad ElNesr
                          Nov 1 '17 at 14:20















                        up vote
                        3
                        down vote













                        If you want a graphical interface to batch process with ffmpegX, try Quick Batcher. It's free and will take your last ffmpegX settings to convert files you drop into it.



                        Note that you can't drag-drop folders onto Quick Batcher. So select files and then put them through Quick Batcher.






                        share|improve this answer





















                        • The "Quick Batcher" software is ONLY for MAC OS
                          – Mohammad ElNesr
                          Nov 1 '17 at 14:20













                        up vote
                        3
                        down vote










                        up vote
                        3
                        down vote









                        If you want a graphical interface to batch process with ffmpegX, try Quick Batcher. It's free and will take your last ffmpegX settings to convert files you drop into it.



                        Note that you can't drag-drop folders onto Quick Batcher. So select files and then put them through Quick Batcher.






                        share|improve this answer












                        If you want a graphical interface to batch process with ffmpegX, try Quick Batcher. It's free and will take your last ffmpegX settings to convert files you drop into it.



                        Note that you can't drag-drop folders onto Quick Batcher. So select files and then put them through Quick Batcher.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Apr 5 '14 at 8:58









                        Nirav Mehta

                        16913




                        16913












                        • The "Quick Batcher" software is ONLY for MAC OS
                          – Mohammad ElNesr
                          Nov 1 '17 at 14:20


















                        • The "Quick Batcher" software is ONLY for MAC OS
                          – Mohammad ElNesr
                          Nov 1 '17 at 14:20
















                        The "Quick Batcher" software is ONLY for MAC OS
                        – Mohammad ElNesr
                        Nov 1 '17 at 14:20




                        The "Quick Batcher" software is ONLY for MAC OS
                        – Mohammad ElNesr
                        Nov 1 '17 at 14:20










                        up vote
                        3
                        down vote













                        for i in *.flac;
                        do name=`echo "${i%.*}"`;
                        echo $name;
                        ffmpeg -i "${i}" -ab 320k -map_metadata 0 -id3v2_version 3 "${name}".mp3;
                        done


                        Batch process flac files into mp3 (safe for file names with spaces) using [1] [2]






                        share|improve this answer



























                          up vote
                          3
                          down vote













                          for i in *.flac;
                          do name=`echo "${i%.*}"`;
                          echo $name;
                          ffmpeg -i "${i}" -ab 320k -map_metadata 0 -id3v2_version 3 "${name}".mp3;
                          done


                          Batch process flac files into mp3 (safe for file names with spaces) using [1] [2]






                          share|improve this answer

























                            up vote
                            3
                            down vote










                            up vote
                            3
                            down vote









                            for i in *.flac;
                            do name=`echo "${i%.*}"`;
                            echo $name;
                            ffmpeg -i "${i}" -ab 320k -map_metadata 0 -id3v2_version 3 "${name}".mp3;
                            done


                            Batch process flac files into mp3 (safe for file names with spaces) using [1] [2]






                            share|improve this answer














                            for i in *.flac;
                            do name=`echo "${i%.*}"`;
                            echo $name;
                            ffmpeg -i "${i}" -ab 320k -map_metadata 0 -id3v2_version 3 "${name}".mp3;
                            done


                            Batch process flac files into mp3 (safe for file names with spaces) using [1] [2]







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited May 23 '17 at 12:10









                            Community

                            11




                            11










                            answered May 13 '16 at 2:15









                            César

                            93666




                            93666






















                                up vote
                                3
                                down vote













                                If you have GNU parallel you could convert all .avi files below vid_dir to mp4 in parallel, using all except one of your CPU cores with



                                find vid_dir -type f -name '*.avi' -not -empty -print0 |
                                parallel -0 -j -1 ffmpeg -loglevel fatal -i {} {.}.mp4


                                To convert from/to different formats, change '*.avi' or .mp4 as needed. GNU parallel is listed in most Linux distributions' repositories in a package which is usually called parallel.






                                share|improve this answer

























                                  up vote
                                  3
                                  down vote













                                  If you have GNU parallel you could convert all .avi files below vid_dir to mp4 in parallel, using all except one of your CPU cores with



                                  find vid_dir -type f -name '*.avi' -not -empty -print0 |
                                  parallel -0 -j -1 ffmpeg -loglevel fatal -i {} {.}.mp4


                                  To convert from/to different formats, change '*.avi' or .mp4 as needed. GNU parallel is listed in most Linux distributions' repositories in a package which is usually called parallel.






                                  share|improve this answer























                                    up vote
                                    3
                                    down vote










                                    up vote
                                    3
                                    down vote









                                    If you have GNU parallel you could convert all .avi files below vid_dir to mp4 in parallel, using all except one of your CPU cores with



                                    find vid_dir -type f -name '*.avi' -not -empty -print0 |
                                    parallel -0 -j -1 ffmpeg -loglevel fatal -i {} {.}.mp4


                                    To convert from/to different formats, change '*.avi' or .mp4 as needed. GNU parallel is listed in most Linux distributions' repositories in a package which is usually called parallel.






                                    share|improve this answer












                                    If you have GNU parallel you could convert all .avi files below vid_dir to mp4 in parallel, using all except one of your CPU cores with



                                    find vid_dir -type f -name '*.avi' -not -empty -print0 |
                                    parallel -0 -j -1 ffmpeg -loglevel fatal -i {} {.}.mp4


                                    To convert from/to different formats, change '*.avi' or .mp4 as needed. GNU parallel is listed in most Linux distributions' repositories in a package which is usually called parallel.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered May 10 at 9:37









                                    Sebastian Scheurer

                                    312




                                    312






















                                        up vote
                                        3
                                        down vote













                                        I know this might be redundant but I use this script to batch convert files.



                                        old_extension=$1
                                        new_extension=$2

                                        for i in *."$old_extension";
                                        do ffmpeg -i "$i" "${i%.*}.$new_extension";
                                        done


                                        It takes 2 arguments to make it more flexible :




                                        1. the extension you want to convert from

                                        2. the new extension you want to convert to


                                        I create an alias for it but you can also use it manually like this:



                                        sh batch_convert.sh mkv mp4


                                        This would convert all the mkv files into mp4 files.



                                        As you can see it slightly more versatile. As long as ffmpeg can convert it you can specify any two extensions.






                                        share|improve this answer























                                        • Thats the best 👍
                                          – Andreas Prang
                                          Sep 29 at 10:29















                                        up vote
                                        3
                                        down vote













                                        I know this might be redundant but I use this script to batch convert files.



                                        old_extension=$1
                                        new_extension=$2

                                        for i in *."$old_extension";
                                        do ffmpeg -i "$i" "${i%.*}.$new_extension";
                                        done


                                        It takes 2 arguments to make it more flexible :




                                        1. the extension you want to convert from

                                        2. the new extension you want to convert to


                                        I create an alias for it but you can also use it manually like this:



                                        sh batch_convert.sh mkv mp4


                                        This would convert all the mkv files into mp4 files.



                                        As you can see it slightly more versatile. As long as ffmpeg can convert it you can specify any two extensions.






                                        share|improve this answer























                                        • Thats the best 👍
                                          – Andreas Prang
                                          Sep 29 at 10:29













                                        up vote
                                        3
                                        down vote










                                        up vote
                                        3
                                        down vote









                                        I know this might be redundant but I use this script to batch convert files.



                                        old_extension=$1
                                        new_extension=$2

                                        for i in *."$old_extension";
                                        do ffmpeg -i "$i" "${i%.*}.$new_extension";
                                        done


                                        It takes 2 arguments to make it more flexible :




                                        1. the extension you want to convert from

                                        2. the new extension you want to convert to


                                        I create an alias for it but you can also use it manually like this:



                                        sh batch_convert.sh mkv mp4


                                        This would convert all the mkv files into mp4 files.



                                        As you can see it slightly more versatile. As long as ffmpeg can convert it you can specify any two extensions.






                                        share|improve this answer














                                        I know this might be redundant but I use this script to batch convert files.



                                        old_extension=$1
                                        new_extension=$2

                                        for i in *."$old_extension";
                                        do ffmpeg -i "$i" "${i%.*}.$new_extension";
                                        done


                                        It takes 2 arguments to make it more flexible :




                                        1. the extension you want to convert from

                                        2. the new extension you want to convert to


                                        I create an alias for it but you can also use it manually like this:



                                        sh batch_convert.sh mkv mp4


                                        This would convert all the mkv files into mp4 files.



                                        As you can see it slightly more versatile. As long as ffmpeg can convert it you can specify any two extensions.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Sep 15 at 20:55

























                                        answered Sep 14 at 20:17









                                        Alexander Luna

                                        2,27521430




                                        2,27521430












                                        • Thats the best 👍
                                          – Andreas Prang
                                          Sep 29 at 10:29


















                                        • Thats the best 👍
                                          – Andreas Prang
                                          Sep 29 at 10:29
















                                        Thats the best 👍
                                        – Andreas Prang
                                        Sep 29 at 10:29




                                        Thats the best 👍
                                        – Andreas Prang
                                        Sep 29 at 10:29










                                        up vote
                                        0
                                        down vote













                                        Another simple solution that hasn't been suggested yet would be to use xargs:



                                        ls *.avi | xargs -i -n1 ffmpeg -i {} "{}.mp4"



                                        One minor pitfall is the awkward naming of output files (e.g. input.avi.mp4). A possible workaround for this might be:



                                        ls *.avi | xargs -i -n1 bash -c "i={}; ffmpeg -i {} "${i%.*}.mp4""






                                        share|improve this answer





















                                        • shellcheck.net has a few suggestions regarding your examples.
                                          – LordNeckbeard
                                          Nov 27 at 18:59















                                        up vote
                                        0
                                        down vote













                                        Another simple solution that hasn't been suggested yet would be to use xargs:



                                        ls *.avi | xargs -i -n1 ffmpeg -i {} "{}.mp4"



                                        One minor pitfall is the awkward naming of output files (e.g. input.avi.mp4). A possible workaround for this might be:



                                        ls *.avi | xargs -i -n1 bash -c "i={}; ffmpeg -i {} "${i%.*}.mp4""






                                        share|improve this answer





















                                        • shellcheck.net has a few suggestions regarding your examples.
                                          – LordNeckbeard
                                          Nov 27 at 18:59













                                        up vote
                                        0
                                        down vote










                                        up vote
                                        0
                                        down vote









                                        Another simple solution that hasn't been suggested yet would be to use xargs:



                                        ls *.avi | xargs -i -n1 ffmpeg -i {} "{}.mp4"



                                        One minor pitfall is the awkward naming of output files (e.g. input.avi.mp4). A possible workaround for this might be:



                                        ls *.avi | xargs -i -n1 bash -c "i={}; ffmpeg -i {} "${i%.*}.mp4""






                                        share|improve this answer












                                        Another simple solution that hasn't been suggested yet would be to use xargs:



                                        ls *.avi | xargs -i -n1 ffmpeg -i {} "{}.mp4"



                                        One minor pitfall is the awkward naming of output files (e.g. input.avi.mp4). A possible workaround for this might be:



                                        ls *.avi | xargs -i -n1 bash -c "i={}; ffmpeg -i {} "${i%.*}.mp4""







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 27 at 17:01









                                        telenachos

                                        708316




                                        708316












                                        • shellcheck.net has a few suggestions regarding your examples.
                                          – LordNeckbeard
                                          Nov 27 at 18:59


















                                        • shellcheck.net has a few suggestions regarding your examples.
                                          – LordNeckbeard
                                          Nov 27 at 18:59
















                                        shellcheck.net has a few suggestions regarding your examples.
                                        – LordNeckbeard
                                        Nov 27 at 18:59




                                        shellcheck.net has a few suggestions regarding your examples.
                                        – LordNeckbeard
                                        Nov 27 at 18:59










                                        up vote
                                        -2
                                        down vote













                                        little php script to do it:



                                        #!/usr/bin/env php
                                        <?php
                                        declare(strict_types = 1);
                                        if ($argc !== 2) {
                                        fprintf ( STDERR, "usage: %s dirn", $argv [0] );
                                        die ( 1 );
                                        }
                                        $dir = rtrim ( $argv [1], DIRECTORY_SEPARATOR );
                                        if (! is_readable ( $dir )) {
                                        fprintf ( STDERR, "supplied path is not readable! (try running as an administrator?)" );
                                        die(1);
                                        }
                                        if (! is_dir ( $dir )) {
                                        fprintf ( STDERR, "supplied path is not a directory!" );
                                        die(1);
                                        }
                                        $files = glob ( $dir . DIRECTORY_SEPARATOR . '*.avi' );
                                        foreach ( $files as $file ) {
                                        system ( "ffmpeg -i " . escapeshellarg ( $file ) . ' ' . escapeshellarg ( $file . '.mp4' ) );
                                        }





                                        share|improve this answer

















                                        • 1




                                          A very limited scope answer as a user has to have PHP installed on their machine. The command line and batch file answers are much easier, and much less complex.
                                          – ProfK
                                          Nov 10 '17 at 9:06






                                        • 2




                                          @ProfK PHP is 1 of the most popular languages on SO - second, Isaac's answer for sh is somewhat unreliable, in that it might rename your files to something else than the original, for example, it doesn't preserve newlines in the filename. lyx's bat script is even worse, it COMPLETELY IGNORES any file with newlines in the name. not sure why, not even a syntax error or anything, but it does (tested on win10). my php script has neither problems, thanks to escapeshellarg(), and works both on windows and linux. i agree its a edge-case though.
                                          – hanshenrik
                                          Nov 12 '17 at 12:43















                                        up vote
                                        -2
                                        down vote













                                        little php script to do it:



                                        #!/usr/bin/env php
                                        <?php
                                        declare(strict_types = 1);
                                        if ($argc !== 2) {
                                        fprintf ( STDERR, "usage: %s dirn", $argv [0] );
                                        die ( 1 );
                                        }
                                        $dir = rtrim ( $argv [1], DIRECTORY_SEPARATOR );
                                        if (! is_readable ( $dir )) {
                                        fprintf ( STDERR, "supplied path is not readable! (try running as an administrator?)" );
                                        die(1);
                                        }
                                        if (! is_dir ( $dir )) {
                                        fprintf ( STDERR, "supplied path is not a directory!" );
                                        die(1);
                                        }
                                        $files = glob ( $dir . DIRECTORY_SEPARATOR . '*.avi' );
                                        foreach ( $files as $file ) {
                                        system ( "ffmpeg -i " . escapeshellarg ( $file ) . ' ' . escapeshellarg ( $file . '.mp4' ) );
                                        }





                                        share|improve this answer

















                                        • 1




                                          A very limited scope answer as a user has to have PHP installed on their machine. The command line and batch file answers are much easier, and much less complex.
                                          – ProfK
                                          Nov 10 '17 at 9:06






                                        • 2




                                          @ProfK PHP is 1 of the most popular languages on SO - second, Isaac's answer for sh is somewhat unreliable, in that it might rename your files to something else than the original, for example, it doesn't preserve newlines in the filename. lyx's bat script is even worse, it COMPLETELY IGNORES any file with newlines in the name. not sure why, not even a syntax error or anything, but it does (tested on win10). my php script has neither problems, thanks to escapeshellarg(), and works both on windows and linux. i agree its a edge-case though.
                                          – hanshenrik
                                          Nov 12 '17 at 12:43













                                        up vote
                                        -2
                                        down vote










                                        up vote
                                        -2
                                        down vote









                                        little php script to do it:



                                        #!/usr/bin/env php
                                        <?php
                                        declare(strict_types = 1);
                                        if ($argc !== 2) {
                                        fprintf ( STDERR, "usage: %s dirn", $argv [0] );
                                        die ( 1 );
                                        }
                                        $dir = rtrim ( $argv [1], DIRECTORY_SEPARATOR );
                                        if (! is_readable ( $dir )) {
                                        fprintf ( STDERR, "supplied path is not readable! (try running as an administrator?)" );
                                        die(1);
                                        }
                                        if (! is_dir ( $dir )) {
                                        fprintf ( STDERR, "supplied path is not a directory!" );
                                        die(1);
                                        }
                                        $files = glob ( $dir . DIRECTORY_SEPARATOR . '*.avi' );
                                        foreach ( $files as $file ) {
                                        system ( "ffmpeg -i " . escapeshellarg ( $file ) . ' ' . escapeshellarg ( $file . '.mp4' ) );
                                        }





                                        share|improve this answer












                                        little php script to do it:



                                        #!/usr/bin/env php
                                        <?php
                                        declare(strict_types = 1);
                                        if ($argc !== 2) {
                                        fprintf ( STDERR, "usage: %s dirn", $argv [0] );
                                        die ( 1 );
                                        }
                                        $dir = rtrim ( $argv [1], DIRECTORY_SEPARATOR );
                                        if (! is_readable ( $dir )) {
                                        fprintf ( STDERR, "supplied path is not readable! (try running as an administrator?)" );
                                        die(1);
                                        }
                                        if (! is_dir ( $dir )) {
                                        fprintf ( STDERR, "supplied path is not a directory!" );
                                        die(1);
                                        }
                                        $files = glob ( $dir . DIRECTORY_SEPARATOR . '*.avi' );
                                        foreach ( $files as $file ) {
                                        system ( "ffmpeg -i " . escapeshellarg ( $file ) . ' ' . escapeshellarg ( $file . '.mp4' ) );
                                        }






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 7 '17 at 13:47









                                        hanshenrik

                                        9,18921537




                                        9,18921537








                                        • 1




                                          A very limited scope answer as a user has to have PHP installed on their machine. The command line and batch file answers are much easier, and much less complex.
                                          – ProfK
                                          Nov 10 '17 at 9:06






                                        • 2




                                          @ProfK PHP is 1 of the most popular languages on SO - second, Isaac's answer for sh is somewhat unreliable, in that it might rename your files to something else than the original, for example, it doesn't preserve newlines in the filename. lyx's bat script is even worse, it COMPLETELY IGNORES any file with newlines in the name. not sure why, not even a syntax error or anything, but it does (tested on win10). my php script has neither problems, thanks to escapeshellarg(), and works both on windows and linux. i agree its a edge-case though.
                                          – hanshenrik
                                          Nov 12 '17 at 12:43














                                        • 1




                                          A very limited scope answer as a user has to have PHP installed on their machine. The command line and batch file answers are much easier, and much less complex.
                                          – ProfK
                                          Nov 10 '17 at 9:06






                                        • 2




                                          @ProfK PHP is 1 of the most popular languages on SO - second, Isaac's answer for sh is somewhat unreliable, in that it might rename your files to something else than the original, for example, it doesn't preserve newlines in the filename. lyx's bat script is even worse, it COMPLETELY IGNORES any file with newlines in the name. not sure why, not even a syntax error or anything, but it does (tested on win10). my php script has neither problems, thanks to escapeshellarg(), and works both on windows and linux. i agree its a edge-case though.
                                          – hanshenrik
                                          Nov 12 '17 at 12:43








                                        1




                                        1




                                        A very limited scope answer as a user has to have PHP installed on their machine. The command line and batch file answers are much easier, and much less complex.
                                        – ProfK
                                        Nov 10 '17 at 9:06




                                        A very limited scope answer as a user has to have PHP installed on their machine. The command line and batch file answers are much easier, and much less complex.
                                        – ProfK
                                        Nov 10 '17 at 9:06




                                        2




                                        2




                                        @ProfK PHP is 1 of the most popular languages on SO - second, Isaac's answer for sh is somewhat unreliable, in that it might rename your files to something else than the original, for example, it doesn't preserve newlines in the filename. lyx's bat script is even worse, it COMPLETELY IGNORES any file with newlines in the name. not sure why, not even a syntax error or anything, but it does (tested on win10). my php script has neither problems, thanks to escapeshellarg(), and works both on windows and linux. i agree its a edge-case though.
                                        – hanshenrik
                                        Nov 12 '17 at 12:43




                                        @ProfK PHP is 1 of the most popular languages on SO - second, Isaac's answer for sh is somewhat unreliable, in that it might rename your files to something else than the original, for example, it doesn't preserve newlines in the filename. lyx's bat script is even worse, it COMPLETELY IGNORES any file with newlines in the name. not sure why, not even a syntax error or anything, but it does (tested on win10). my php script has neither problems, thanks to escapeshellarg(), and works both on windows and linux. i agree its a edge-case though.
                                        – hanshenrik
                                        Nov 12 '17 at 12:43


















                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.





                                        Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                        Please pay close attention to the following guidance:


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5784661%2fhow-do-you-convert-an-entire-directory-with-ffmpeg%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                        Alcedinidae

                                        RAC Tourist Trophy