1

My folder has some video files with mp3 audio and some video files with aac audio. I want to move all files which have mp3 audio to another folder. When I asked my friend, he gave me this script:

mp3ToAAC.sh

#To convert mp3 audio to AAC
for file in *;
do
    if [ $file == "mp3ToAAC.sh" ]; then
        continue;
    fi
    if [ -f "$file" ]; then
        ffmpeg -i "$file" -acodec aac -vcodec copy ../"$file"
    fi 
done

That will convert all video files with audio mp3 to aac. Before using this, I want to move the files which have mp3 audio to another directory. I want to run this script only on those files. How to do that?

1 Answer 1

1

I think that the question has an error. I shall ask the OP to correct it.

The code to move files is:

#To move mp3 video to parent
for file in *;
do
    if [ "$file" == "moveMp3.sh" ]; then
        continue;
    fi
    if [ -f "$file" ]; then
        audioFormat=$(ffprobe -loglevel error -select_streams a:0 -show_entries stream=codec_name -of default=nw=1:nk=1 "$file")
        if [ -z $audioFormat ]; then
            continue;
        fi
        if [ $audioFormat == "mp3" ]; then
            mv "$file" ../"$file"
        fi
    fi
done

The code to convert mp3 can be:

#To convert mp3 audio to AAC
for file in *;
do
    if [ $file == "mp3ToAAC.sh" ]; then
        continue;
    fi
    if [ -f "$file" ]; then
        ffmpeg -i "$file" -map 0 -c copy -c:a:0 aac ../"$file"
    fi 
done

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.