I have a directory of .mxf files that I'm batch transcoding to .mp4. Some of the mxf's already have mp4 versions within the directory.
I want to check in bash that the mp4 version does not exist so the batch process will skip files that already have an mp4 version.
Psuedo code example:
for file.mxf in folder: do
if file.mp4 != exist
$ffmpeg_command
fi
done
CodePudding user response:
Would you please try the following:
#!/bin/bash
for fin in folder/*.mxf; do # loop over mxf files in "folder"
fout=${fin%.mxf}.mp4 # filename of the paired mp4
if [[ ! -f $fout ]]; then # if the mp4 file doesn't exist
echo ffmeg -i "$fin" [options] "$fout" # then transcode
fi
done
- Put appropriate options such as codec and bitrate as
[option]
. - If the printed commands look okay, drop
echo
and run.
CodePudding user response:
#!/bin/bash
while IFS= read -r filename; do
# if ${filename}.mp4 not exist
if [ ! -f "${filename}.mp4" ]; then
# do some with ${filename}.xmf
echo "ffmpeg_command for ${filename}.mxf"
fi
done < <(find . -iname "*.mxf"|sed 's/\.mxf$//')
find . -iname "*.mxf"
find *.mxf filessed 's/\.mxf$//'
remove extension from file