Convert all found m4a to mp3

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite
1












I'm trying to covert all m4a to mp3 my code look like this:



find . -name '*.m4a' -print0 | while read -d '' -r file; do
ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3";
done


but it only work for first mp3 file for next it show error:



Parse error, at least 3 arguments were expected, only 1 given in string '<All files in one line>'

Enter command: <target>|all <time>|-1 <command>[ <argument>]


The files contain spaces ampersands and parenthesis.







share|improve this question















  • 2




    You could replace ffmpeg with echo -- and inspect the output to ensure all is right.
    – thecarpy
    Apr 20 at 12:44










  • set IFS to the null string as well ... |while IFS= read -d '' -r file; ... . You could use all with find instead of using a shell while-loop
    – Î±Ò“sнιη
    Apr 20 at 14:47











  • @thecarpy I was testing with echo and I've got each file with its own ffmpeg
    – jcubic
    Apr 20 at 15:33














up vote
3
down vote

favorite
1












I'm trying to covert all m4a to mp3 my code look like this:



find . -name '*.m4a' -print0 | while read -d '' -r file; do
ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3";
done


but it only work for first mp3 file for next it show error:



Parse error, at least 3 arguments were expected, only 1 given in string '<All files in one line>'

Enter command: <target>|all <time>|-1 <command>[ <argument>]


The files contain spaces ampersands and parenthesis.







share|improve this question















  • 2




    You could replace ffmpeg with echo -- and inspect the output to ensure all is right.
    – thecarpy
    Apr 20 at 12:44










  • set IFS to the null string as well ... |while IFS= read -d '' -r file; ... . You could use all with find instead of using a shell while-loop
    – Î±Ò“sнιη
    Apr 20 at 14:47











  • @thecarpy I was testing with echo and I've got each file with its own ffmpeg
    – jcubic
    Apr 20 at 15:33












up vote
3
down vote

favorite
1









up vote
3
down vote

favorite
1






1





I'm trying to covert all m4a to mp3 my code look like this:



find . -name '*.m4a' -print0 | while read -d '' -r file; do
ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3";
done


but it only work for first mp3 file for next it show error:



Parse error, at least 3 arguments were expected, only 1 given in string '<All files in one line>'

Enter command: <target>|all <time>|-1 <command>[ <argument>]


The files contain spaces ampersands and parenthesis.







share|improve this question











I'm trying to covert all m4a to mp3 my code look like this:



find . -name '*.m4a' -print0 | while read -d '' -r file; do
ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3";
done


but it only work for first mp3 file for next it show error:



Parse error, at least 3 arguments were expected, only 1 given in string '<All files in one line>'

Enter command: <target>|all <time>|-1 <command>[ <argument>]


The files contain spaces ampersands and parenthesis.









share|improve this question










share|improve this question




share|improve this question









asked Apr 20 at 12:28









jcubic

2,67342439




2,67342439







  • 2




    You could replace ffmpeg with echo -- and inspect the output to ensure all is right.
    – thecarpy
    Apr 20 at 12:44










  • set IFS to the null string as well ... |while IFS= read -d '' -r file; ... . You could use all with find instead of using a shell while-loop
    – Î±Ò“sнιη
    Apr 20 at 14:47











  • @thecarpy I was testing with echo and I've got each file with its own ffmpeg
    – jcubic
    Apr 20 at 15:33












  • 2




    You could replace ffmpeg with echo -- and inspect the output to ensure all is right.
    – thecarpy
    Apr 20 at 12:44










  • set IFS to the null string as well ... |while IFS= read -d '' -r file; ... . You could use all with find instead of using a shell while-loop
    – Î±Ò“sнιη
    Apr 20 at 14:47











  • @thecarpy I was testing with echo and I've got each file with its own ffmpeg
    – jcubic
    Apr 20 at 15:33







2




2




You could replace ffmpeg with echo -- and inspect the output to ensure all is right.
– thecarpy
Apr 20 at 12:44




You could replace ffmpeg with echo -- and inspect the output to ensure all is right.
– thecarpy
Apr 20 at 12:44












set IFS to the null string as well ... |while IFS= read -d '' -r file; ... . You could use all with find instead of using a shell while-loop
– Î±Ò“sнιη
Apr 20 at 14:47





set IFS to the null string as well ... |while IFS= read -d '' -r file; ... . You could use all with find instead of using a shell while-loop
– Î±Ò“sнιη
Apr 20 at 14:47













@thecarpy I was testing with echo and I've got each file with its own ffmpeg
– jcubic
Apr 20 at 15:33




@thecarpy I was testing with echo and I've got each file with its own ffmpeg
– jcubic
Apr 20 at 15:33










3 Answers
3






active

oldest

votes

















up vote
4
down vote



accepted











When reading a file line by line, if a command inside the loop also reads stdin, it can exhaust the input file.




Continue reading here: Bash FAQ 89



So the code should look like this:



find . -name '*.m4a' -print0 | while read -d '' -r file; do
ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3" < /dev/null
done





share|improve this answer






























    up vote
    0
    down vote













    Your question asked about converting m4a to mp3.



    This is a bash script I have been using for a while.



    Adjust the avconv command to suite your needs.



    #!/bin/bash
    ## jc 2016
    ## convert [m4a mp3 wma] to mp3 128k
    ## [-vn] disable video recording
    ##
    ## avconv with lame mp3 plugin
    ## [-acodec libmp3lame]
    ##
    ## 192 k constant bitrate
    ## [-ab 192k]
    ## [-ab 128k]
    ##
    ## 44.1kHz sampling rate
    ## [-ar 44100]
    ##
    ## 2 channel audio
    ## [-ac 2]
    ##

    ## force the shell to do a case insensitive comparison
    shopt -s nocasematch

    working_directory="./mp3_converted"
    # check if dir exist
    if [ ! -d "$working_directory" ];
    then
    # dir does not exist
    echo "convert directory does not exist $working_directory..."
    `mkdir -p "$working_directory"`
    echo "convert directory created $working_directory..."
    fi

    COUNT=0

    for i in *; do

    case $i in
    *.mp3)
    avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .mp3`.mp3"
    echo $i
    ;;
    *.m4a)
    ##avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .m4a`.mp3"
    # adjusted for ffmpeg to test.
    ffmpeg -i "$i" -n -acodec libmp3lame -ab 128k "$working_directory/`basename "$i" .m4a`.mp3"
    echo $i
    ;;
    *.wma)
    avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .wma`.mp3"
    echo $i
    ;;
    *)
    echo "other"
    ;;
    esac

    done

    ## back to normal comparison
    shopt -u nocasematch
    exit 0





    share|improve this answer






























      up vote
      0
      down vote













      Why not just use the -exec argument of find? So find -iname '*.m4a' -exec ffmpeg -i -n -acodec libmp3lame -ab 128k .mp3 ; and run a rename command afterward?






      share|improve this answer





















        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: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        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%2f438927%2fconvert-all-found-m4a-to-mp3%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        4
        down vote



        accepted











        When reading a file line by line, if a command inside the loop also reads stdin, it can exhaust the input file.




        Continue reading here: Bash FAQ 89



        So the code should look like this:



        find . -name '*.m4a' -print0 | while read -d '' -r file; do
        ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3" < /dev/null
        done





        share|improve this answer



























          up vote
          4
          down vote



          accepted











          When reading a file line by line, if a command inside the loop also reads stdin, it can exhaust the input file.




          Continue reading here: Bash FAQ 89



          So the code should look like this:



          find . -name '*.m4a' -print0 | while read -d '' -r file; do
          ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3" < /dev/null
          done





          share|improve this answer

























            up vote
            4
            down vote



            accepted







            up vote
            4
            down vote



            accepted







            When reading a file line by line, if a command inside the loop also reads stdin, it can exhaust the input file.




            Continue reading here: Bash FAQ 89



            So the code should look like this:



            find . -name '*.m4a' -print0 | while read -d '' -r file; do
            ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3" < /dev/null
            done





            share|improve this answer
















            When reading a file line by line, if a command inside the loop also reads stdin, it can exhaust the input file.




            Continue reading here: Bash FAQ 89



            So the code should look like this:



            find . -name '*.m4a' -print0 | while read -d '' -r file; do
            ffmpeg -i "$file" -n -acodec libmp3lame -ab 128k "$file%.m4a.mp3" < /dev/null
            done






            share|improve this answer















            share|improve this answer



            share|improve this answer








            edited Apr 20 at 15:57









            jcubic

            2,67342439




            2,67342439











            answered Apr 20 at 14:00









            Rany Albeg Wein

            567214




            567214






















                up vote
                0
                down vote













                Your question asked about converting m4a to mp3.



                This is a bash script I have been using for a while.



                Adjust the avconv command to suite your needs.



                #!/bin/bash
                ## jc 2016
                ## convert [m4a mp3 wma] to mp3 128k
                ## [-vn] disable video recording
                ##
                ## avconv with lame mp3 plugin
                ## [-acodec libmp3lame]
                ##
                ## 192 k constant bitrate
                ## [-ab 192k]
                ## [-ab 128k]
                ##
                ## 44.1kHz sampling rate
                ## [-ar 44100]
                ##
                ## 2 channel audio
                ## [-ac 2]
                ##

                ## force the shell to do a case insensitive comparison
                shopt -s nocasematch

                working_directory="./mp3_converted"
                # check if dir exist
                if [ ! -d "$working_directory" ];
                then
                # dir does not exist
                echo "convert directory does not exist $working_directory..."
                `mkdir -p "$working_directory"`
                echo "convert directory created $working_directory..."
                fi

                COUNT=0

                for i in *; do

                case $i in
                *.mp3)
                avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .mp3`.mp3"
                echo $i
                ;;
                *.m4a)
                ##avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .m4a`.mp3"
                # adjusted for ffmpeg to test.
                ffmpeg -i "$i" -n -acodec libmp3lame -ab 128k "$working_directory/`basename "$i" .m4a`.mp3"
                echo $i
                ;;
                *.wma)
                avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .wma`.mp3"
                echo $i
                ;;
                *)
                echo "other"
                ;;
                esac

                done

                ## back to normal comparison
                shopt -u nocasematch
                exit 0





                share|improve this answer



























                  up vote
                  0
                  down vote













                  Your question asked about converting m4a to mp3.



                  This is a bash script I have been using for a while.



                  Adjust the avconv command to suite your needs.



                  #!/bin/bash
                  ## jc 2016
                  ## convert [m4a mp3 wma] to mp3 128k
                  ## [-vn] disable video recording
                  ##
                  ## avconv with lame mp3 plugin
                  ## [-acodec libmp3lame]
                  ##
                  ## 192 k constant bitrate
                  ## [-ab 192k]
                  ## [-ab 128k]
                  ##
                  ## 44.1kHz sampling rate
                  ## [-ar 44100]
                  ##
                  ## 2 channel audio
                  ## [-ac 2]
                  ##

                  ## force the shell to do a case insensitive comparison
                  shopt -s nocasematch

                  working_directory="./mp3_converted"
                  # check if dir exist
                  if [ ! -d "$working_directory" ];
                  then
                  # dir does not exist
                  echo "convert directory does not exist $working_directory..."
                  `mkdir -p "$working_directory"`
                  echo "convert directory created $working_directory..."
                  fi

                  COUNT=0

                  for i in *; do

                  case $i in
                  *.mp3)
                  avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .mp3`.mp3"
                  echo $i
                  ;;
                  *.m4a)
                  ##avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .m4a`.mp3"
                  # adjusted for ffmpeg to test.
                  ffmpeg -i "$i" -n -acodec libmp3lame -ab 128k "$working_directory/`basename "$i" .m4a`.mp3"
                  echo $i
                  ;;
                  *.wma)
                  avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .wma`.mp3"
                  echo $i
                  ;;
                  *)
                  echo "other"
                  ;;
                  esac

                  done

                  ## back to normal comparison
                  shopt -u nocasematch
                  exit 0





                  share|improve this answer

























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Your question asked about converting m4a to mp3.



                    This is a bash script I have been using for a while.



                    Adjust the avconv command to suite your needs.



                    #!/bin/bash
                    ## jc 2016
                    ## convert [m4a mp3 wma] to mp3 128k
                    ## [-vn] disable video recording
                    ##
                    ## avconv with lame mp3 plugin
                    ## [-acodec libmp3lame]
                    ##
                    ## 192 k constant bitrate
                    ## [-ab 192k]
                    ## [-ab 128k]
                    ##
                    ## 44.1kHz sampling rate
                    ## [-ar 44100]
                    ##
                    ## 2 channel audio
                    ## [-ac 2]
                    ##

                    ## force the shell to do a case insensitive comparison
                    shopt -s nocasematch

                    working_directory="./mp3_converted"
                    # check if dir exist
                    if [ ! -d "$working_directory" ];
                    then
                    # dir does not exist
                    echo "convert directory does not exist $working_directory..."
                    `mkdir -p "$working_directory"`
                    echo "convert directory created $working_directory..."
                    fi

                    COUNT=0

                    for i in *; do

                    case $i in
                    *.mp3)
                    avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .mp3`.mp3"
                    echo $i
                    ;;
                    *.m4a)
                    ##avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .m4a`.mp3"
                    # adjusted for ffmpeg to test.
                    ffmpeg -i "$i" -n -acodec libmp3lame -ab 128k "$working_directory/`basename "$i" .m4a`.mp3"
                    echo $i
                    ;;
                    *.wma)
                    avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .wma`.mp3"
                    echo $i
                    ;;
                    *)
                    echo "other"
                    ;;
                    esac

                    done

                    ## back to normal comparison
                    shopt -u nocasematch
                    exit 0





                    share|improve this answer















                    Your question asked about converting m4a to mp3.



                    This is a bash script I have been using for a while.



                    Adjust the avconv command to suite your needs.



                    #!/bin/bash
                    ## jc 2016
                    ## convert [m4a mp3 wma] to mp3 128k
                    ## [-vn] disable video recording
                    ##
                    ## avconv with lame mp3 plugin
                    ## [-acodec libmp3lame]
                    ##
                    ## 192 k constant bitrate
                    ## [-ab 192k]
                    ## [-ab 128k]
                    ##
                    ## 44.1kHz sampling rate
                    ## [-ar 44100]
                    ##
                    ## 2 channel audio
                    ## [-ac 2]
                    ##

                    ## force the shell to do a case insensitive comparison
                    shopt -s nocasematch

                    working_directory="./mp3_converted"
                    # check if dir exist
                    if [ ! -d "$working_directory" ];
                    then
                    # dir does not exist
                    echo "convert directory does not exist $working_directory..."
                    `mkdir -p "$working_directory"`
                    echo "convert directory created $working_directory..."
                    fi

                    COUNT=0

                    for i in *; do

                    case $i in
                    *.mp3)
                    avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .mp3`.mp3"
                    echo $i
                    ;;
                    *.m4a)
                    ##avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .m4a`.mp3"
                    # adjusted for ffmpeg to test.
                    ffmpeg -i "$i" -n -acodec libmp3lame -ab 128k "$working_directory/`basename "$i" .m4a`.mp3"
                    echo $i
                    ;;
                    *.wma)
                    avconv -analyzeduration 999999999 -map_metadata 0 -i "$i" -vn -acodec libmp3lame -ac 2 -ab 128k -ar 44100 "$working_directory/`basename "$i" .wma`.mp3"
                    echo $i
                    ;;
                    *)
                    echo "other"
                    ;;
                    esac

                    done

                    ## back to normal comparison
                    shopt -u nocasematch
                    exit 0






                    share|improve this answer















                    share|improve this answer



                    share|improve this answer








                    edited Apr 20 at 16:18


























                    answered Apr 20 at 16:03









                    jc__

                    1,278215




                    1,278215




















                        up vote
                        0
                        down vote













                        Why not just use the -exec argument of find? So find -iname '*.m4a' -exec ffmpeg -i -n -acodec libmp3lame -ab 128k .mp3 ; and run a rename command afterward?






                        share|improve this answer

























                          up vote
                          0
                          down vote













                          Why not just use the -exec argument of find? So find -iname '*.m4a' -exec ffmpeg -i -n -acodec libmp3lame -ab 128k .mp3 ; and run a rename command afterward?






                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            Why not just use the -exec argument of find? So find -iname '*.m4a' -exec ffmpeg -i -n -acodec libmp3lame -ab 128k .mp3 ; and run a rename command afterward?






                            share|improve this answer













                            Why not just use the -exec argument of find? So find -iname '*.m4a' -exec ffmpeg -i -n -acodec libmp3lame -ab 128k .mp3 ; and run a rename command afterward?







                            share|improve this answer













                            share|improve this answer



                            share|improve this answer











                            answered Apr 21 at 11:16









                            Chiraag

                            1968




                            1968






















                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438927%2fconvert-all-found-m4a-to-mp3%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                Peggy Mitchell

                                Palaiologos

                                The Forum (Inglewood, California)