New ffmpeg scripts

This commit is contained in:
Jeremy Gardais 2022-12-14 13:59:41 +01:00
parent c530cc0ba2
commit 0a91d87456
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
2 changed files with 57 additions and 0 deletions

23
ff.extract.subs.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
#
# From :
# https://gist.github.com/kowalcj0/ae0bdc43018e2718fb75290079b8839a
# Can be improve to call ffmpeg only one time :
# https://gist.github.com/kowalcj0/ae0bdc43018e2718fb75290079b8839a?permalink_comment_id=4187491#gistcomment-4187491
function subs() {
movie="${1}"
filename="${1%.*}"
mappings=`ffprobe -loglevel error -select_streams s -show_entries stream=index:stream_tags=language -of csv=p=0 "${movie}"`
OLDIFS=$IFS
IFS=,
( while read -r idx lang
do
echo "Exctracting ${lang} subtitle #${idx} from ${movie}"
ffmpeg -nostdin -hide_banner -loglevel quiet -i "${movie}" -map 0:"$idx" "${filename}_${lang}_${idx}.srt"
done <<< "${mappings}" )
IFS=$OLDIFS
}
subs "${1}"

34
ff.to.x265.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
#
# Convert input file to x265 :
# * Keep only the first audio track (-map 0:a:0)
# * Keep all subtitles (-map 0:s)
# * Use fast preset for encoding
# * Simply add "x265" at the end of the file (before the extension)
# * Only print progression
# Colors {{{
readonly RED='\033[0;31m'
readonly RESET='\033[0m'
# }}}
x265_convert() {
orig_file="${1}"
file_name=$(echo "${orig_file}" | sed -e 's/\.[^.]*$//') # without extension
#file_name="${1%.*}" # bash only
file_ext=$(echo "${orig_file}" | sed -e 's/.*\.//') # without extension
dest_file="${file_name}.x265.${file_ext}"
## If subtitles are available
if [ $(ffprobe -loglevel error -select_streams s -show_entries stream=index:stream_tags=language -of csv=p=0 "${orig_file}" | wc --lines) -eq "0" ]; then
printf "%b\n" "Try to convert original file (${orig_file}) with ffmpeg… without subtitles."
ffmpeg -loglevel quiet -stats -i "${orig_file}" -codec:v libx265 -preset fast -crf 28 -codec:a copy -map 0:v -map 0:a:0 "${dest_file}"
else
printf "%b\n" "Try to convert original file (${orig_file}) with ffmpeg… with subtitles."
ffmpeg -loglevel quiet -stats -i "${orig_file}" -codec:v libx265 -preset fast -crf 28 -codec:a copy -codec:s copy -map 0:v -map 0:a:0 -map 0:s "${dest_file}"
fi
printf "%b\n" "New x265 file is available ( ${RED}${dest_file}${RESET} )."
}
x265_convert "${1}"