mardi 16 juin 2020

Need help combining commands in to a script to run in Ubuntu

I have a bunch of video files with DTS audio that I need to convert to AC3. I have found commands that can do different parts of the task but I'm not sure how to put it all together to make a script that works. I have found the following script that will convert the audio from all my files to AC3 however I would prefer for it to only convert the DTS audio files to AC3. The script is as follows.

shopt -s globstar
for f in **/*.mkv; 
do 
    fname="${f##*/}"
    ffmpeg -i "$f" -c:v copy -c:s copy -c:a ac3 "/some/directory/$fname" &&
    mv "/some/directory/$fname" "$f"
done

I have also found this command that will return what sort of audio codec the mkv file is using.

`ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 input.mkv`

So I'm wondering how I can combine the two to create a script that will do what I want it to do. I'm guessing I can add an if function using ffprobe at the beginning of the script? Something like this...

shopt -s globstar
for f in **/*.mkv; 
do 
    fname="${f##*/}"
    if ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of 
       default=nokey=1:noprint_wrappers=1 "$f" | egrep "DTS"; then
       ffmpeg -i "$f" -c:v copy -c:s copy -c:a ac3 "/some/directory/$fname" &&
       mv "/some/directory/$fname" "$f"
    fi
done

Are there any problems with that? I haven't written scripts since I was in high school playing around with my graphics calculator because I was bored so any help would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire