1
0
Fork 0

cutvid: Fix degraded video quality with hardcoded subtitles

- Extract subtitles first
- Only do 1 encoding pass
This commit is contained in:
tastytea 2022-05-07 19:08:01 +02:00
parent b07ee2ccef
commit 41b83f13a5
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
1 changed files with 9 additions and 11 deletions

View File

@ -35,19 +35,17 @@ local vencoder="copy"
local aencoder="copy"
[[ ${#o_vencoder} -eq 2 ]] && vencoder=${o_vencoder[2]}
[[ ${#o_aencoder} -eq 2 ]] && aencoder=${o_aencoder[2]}
local subtitle_options=(-codec:s copy)
if [[ ${#o_hardcode_subs} -ne 0 ]]; then
local tmpass=$(mktemp --suffix='.cutvid.ass')
ffmpeg -i ${input} -y ${tmpass}
subtitle_options=(-sn -vf ass=${tmpass} )
fi
ffmpeg -i ${input} \
-ss ${from} -to ${to} \
-codec:v ${vencoder} -codec:a ${aencoder} -codec:s copy \
-codec:v ${vencoder} -codec:a ${aencoder} ${subtitle_options} \
${ffmpeg_options} ${output}
# NOTE: only works with ASS at the moment
if [[ ${#o_hardcode_subs} -ne 0 ]]; then
local tmpass=$(mktemp --suffix='.cutvid.ass')
ffmpeg -i ${output} -y ${tmpass}
ffmpeg -sn -i ${output} -vf ass=${tmpass} \
-codec:v ${vencoder} -codec:a copy \
hardcoded_sub_${output}
mv --verbose hardcoded_sub_${output} ${output}
rm --verbose ${tmpass}
fi
[[ ${#o_hardcode_subs} -ne 0 ]] && rm --verbose ${tmpass}