Apply command on all files in a folder











up vote
-1
down vote

favorite












I have a folder full of videos which all have 2 audio tracks and I want to remove the first one from each of them.



So I need to run:



ffmpeg -i [filename] -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4
mv temp.mp4 [filename]


on every file in that folder.










share|improve this question
























  • What have you tried so far? The thing you are looking for is called for loop in bash.
    – Fiximan
    Oct 26 '16 at 12:12















up vote
-1
down vote

favorite












I have a folder full of videos which all have 2 audio tracks and I want to remove the first one from each of them.



So I need to run:



ffmpeg -i [filename] -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4
mv temp.mp4 [filename]


on every file in that folder.










share|improve this question
























  • What have you tried so far? The thing you are looking for is called for loop in bash.
    – Fiximan
    Oct 26 '16 at 12:12













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I have a folder full of videos which all have 2 audio tracks and I want to remove the first one from each of them.



So I need to run:



ffmpeg -i [filename] -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4
mv temp.mp4 [filename]


on every file in that folder.










share|improve this question















I have a folder full of videos which all have 2 audio tracks and I want to remove the first one from each of them.



So I need to run:



ffmpeg -i [filename] -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4
mv temp.mp4 [filename]


on every file in that folder.







shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Rui F Ribeiro

38.2k1475125




38.2k1475125










asked Oct 26 '16 at 11:36









Ginso

1




1












  • What have you tried so far? The thing you are looking for is called for loop in bash.
    – Fiximan
    Oct 26 '16 at 12:12


















  • What have you tried so far? The thing you are looking for is called for loop in bash.
    – Fiximan
    Oct 26 '16 at 12:12
















What have you tried so far? The thing you are looking for is called for loop in bash.
– Fiximan
Oct 26 '16 at 12:12




What have you tried so far? The thing you are looking for is called for loop in bash.
– Fiximan
Oct 26 '16 at 12:12










3 Answers
3






active

oldest

votes

















up vote
3
down vote













find . -type f 
-exec ffmpeg -i '{}' -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4 ;
-exec mv temp.mp4 '{}' ;`





share|improve this answer



















  • 1




    The mv is not going to work as you have it.
    – Patrick
    Oct 26 '16 at 12:21










  • Corrected. It should work now.
    – mtahmed
    Oct 26 '16 at 13:05


















up vote
1
down vote













I would use find with -exec:



find . -type f -name "*.mp4" -exec ffmpeg -i {} -map 0:0 -map 0:2 -acodec copy -vcodec copy {} ;


But a ls -1 *.mp4 | ffmpeg also works fine.






share|improve this answer






























    up vote
    0
    down vote













    for file in $(ls)
    do
    #whatever you want to do with "${file}"
    done





    share|improve this answer



















    • 2




      Careful with that -- touch "a b"
      – Jeff Schaller
      Oct 27 '16 at 12:30










    • Oh... Quotation mark added (if that's what you mean).
      – corsel
      Oct 27 '16 at 12:34











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    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: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f319047%2fapply-command-on-all-files-in-a-folder%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    find . -type f 
    -exec ffmpeg -i '{}' -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4 ;
    -exec mv temp.mp4 '{}' ;`





    share|improve this answer



















    • 1




      The mv is not going to work as you have it.
      – Patrick
      Oct 26 '16 at 12:21










    • Corrected. It should work now.
      – mtahmed
      Oct 26 '16 at 13:05















    up vote
    3
    down vote













    find . -type f 
    -exec ffmpeg -i '{}' -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4 ;
    -exec mv temp.mp4 '{}' ;`





    share|improve this answer



















    • 1




      The mv is not going to work as you have it.
      – Patrick
      Oct 26 '16 at 12:21










    • Corrected. It should work now.
      – mtahmed
      Oct 26 '16 at 13:05













    up vote
    3
    down vote










    up vote
    3
    down vote









    find . -type f 
    -exec ffmpeg -i '{}' -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4 ;
    -exec mv temp.mp4 '{}' ;`





    share|improve this answer














    find . -type f 
    -exec ffmpeg -i '{}' -map 0:0 -map 0:2 -acodec copy -vcodec copy temp.mp4 ;
    -exec mv temp.mp4 '{}' ;`






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Oct 26 '16 at 13:16









    Stéphane Chazelas

    294k54554897




    294k54554897










    answered Oct 26 '16 at 11:42









    mtahmed

    1,301108




    1,301108








    • 1




      The mv is not going to work as you have it.
      – Patrick
      Oct 26 '16 at 12:21










    • Corrected. It should work now.
      – mtahmed
      Oct 26 '16 at 13:05














    • 1




      The mv is not going to work as you have it.
      – Patrick
      Oct 26 '16 at 12:21










    • Corrected. It should work now.
      – mtahmed
      Oct 26 '16 at 13:05








    1




    1




    The mv is not going to work as you have it.
    – Patrick
    Oct 26 '16 at 12:21




    The mv is not going to work as you have it.
    – Patrick
    Oct 26 '16 at 12:21












    Corrected. It should work now.
    – mtahmed
    Oct 26 '16 at 13:05




    Corrected. It should work now.
    – mtahmed
    Oct 26 '16 at 13:05












    up vote
    1
    down vote













    I would use find with -exec:



    find . -type f -name "*.mp4" -exec ffmpeg -i {} -map 0:0 -map 0:2 -acodec copy -vcodec copy {} ;


    But a ls -1 *.mp4 | ffmpeg also works fine.






    share|improve this answer



























      up vote
      1
      down vote













      I would use find with -exec:



      find . -type f -name "*.mp4" -exec ffmpeg -i {} -map 0:0 -map 0:2 -acodec copy -vcodec copy {} ;


      But a ls -1 *.mp4 | ffmpeg also works fine.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        I would use find with -exec:



        find . -type f -name "*.mp4" -exec ffmpeg -i {} -map 0:0 -map 0:2 -acodec copy -vcodec copy {} ;


        But a ls -1 *.mp4 | ffmpeg also works fine.






        share|improve this answer














        I would use find with -exec:



        find . -type f -name "*.mp4" -exec ffmpeg -i {} -map 0:0 -map 0:2 -acodec copy -vcodec copy {} ;


        But a ls -1 *.mp4 | ffmpeg also works fine.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 26 '16 at 12:16

























        answered Oct 26 '16 at 11:41









        Willian Paixao

        1,48211029




        1,48211029






















            up vote
            0
            down vote













            for file in $(ls)
            do
            #whatever you want to do with "${file}"
            done





            share|improve this answer



















            • 2




              Careful with that -- touch "a b"
              – Jeff Schaller
              Oct 27 '16 at 12:30










            • Oh... Quotation mark added (if that's what you mean).
              – corsel
              Oct 27 '16 at 12:34















            up vote
            0
            down vote













            for file in $(ls)
            do
            #whatever you want to do with "${file}"
            done





            share|improve this answer



















            • 2




              Careful with that -- touch "a b"
              – Jeff Schaller
              Oct 27 '16 at 12:30










            • Oh... Quotation mark added (if that's what you mean).
              – corsel
              Oct 27 '16 at 12:34













            up vote
            0
            down vote










            up vote
            0
            down vote









            for file in $(ls)
            do
            #whatever you want to do with "${file}"
            done





            share|improve this answer














            for file in $(ls)
            do
            #whatever you want to do with "${file}"
            done






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Oct 27 '16 at 12:33

























            answered Oct 27 '16 at 11:18









            corsel

            787




            787








            • 2




              Careful with that -- touch "a b"
              – Jeff Schaller
              Oct 27 '16 at 12:30










            • Oh... Quotation mark added (if that's what you mean).
              – corsel
              Oct 27 '16 at 12:34














            • 2




              Careful with that -- touch "a b"
              – Jeff Schaller
              Oct 27 '16 at 12:30










            • Oh... Quotation mark added (if that's what you mean).
              – corsel
              Oct 27 '16 at 12:34








            2




            2




            Careful with that -- touch "a b"
            – Jeff Schaller
            Oct 27 '16 at 12:30




            Careful with that -- touch "a b"
            – Jeff Schaller
            Oct 27 '16 at 12:30












            Oh... Quotation mark added (if that's what you mean).
            – corsel
            Oct 27 '16 at 12:34




            Oh... Quotation mark added (if that's what you mean).
            – corsel
            Oct 27 '16 at 12:34


















             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f319047%2fapply-command-on-all-files-in-a-folder%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

            Accessing regular linux commands in Huawei's Dopra Linux

            Can't connect RFCOMM socket: Host is down

            Kernel panic - not syncing: Fatal Exception in Interrupt