Skip to content

Instantly share code, notes, and snippets.

@bonnebulle
Created October 16, 2023 07:44
Show Gist options
  • Save bonnebulle/907026a0f96d8497fa63dc15472b07ce to your computer and use it in GitHub Desktop.
Save bonnebulle/907026a0f96d8497fa63dc15472b07ce to your computer and use it in GitHub Desktop.
Convert all vidéos files in all sub-folders (batch) with ffmpeg
#!/bin/bash
# DO Convert all vidéos files in all sub-folders (batch) with ffmpeg
# DEP ffmpeg
# TODO Change quality (-crf) + output file_name.ext
# OPT "ffmpeg_batch_subfolders_each.sh infos" => GIVE ffmpeg files infos only...
# GIST https://gist.github.com/bonnebulle/907026a0f96d8497fa63dc15472b07ce
echo "Carefull, will find all files in sub-folders and move them here ="
pwd
echo ": */**.mkv"
echo
echo "Converting alls with ffmpeg..."
echo "-crf 28 is for quality... 0 is better"
echo
echo "wait 10s"
sleep 10
for file in */**.mkv
do
echo $file
echo "---"
noext=${file%.*} # filename w/out .ext
nopath="$(basename -- $noext)" # just file name, no path
echo $nopath
# TODO Notification on start / end
if [[ $1 == "infos" ]]
then
ffmpeg -i $file -f null ## INFOS
else
ffmpeg -i $file -map 0:s:m:language:fre -c:s mov_text -map 0 -vcodec libx265 -crf 28 -c:a aac $nopath.mp4
## -crf 28 — 0-51: where 0 is lossless, 23 is default, and 51 is worst possible
## -map 0:s:m:language:fre -c:s mov_text — move fre sub on first place !
# ffmpeg -i $file -vcodec libx265 -crf 28 $nopath.mp4 # <- without subs manipulation
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment