cutvid: allow to select subtitle to hardcode

This commit is contained in:
tastytea 2023-04-23 20:32:09 +02:00
parent 775b081bd6
commit 8a7a3d4035
Signed by: tastytea
SSH Key Fingerprint: SHA256:FBkvrOlhq5use1XEttyUGT4bUTDVA1ar9SgIc9P03cM
2 changed files with 7 additions and 5 deletions

View File

@ -33,7 +33,7 @@ _arguments '-h[short help text]' \
'--to[timestamp]:timestamp:' \
'--vencoder[video encoder]:encoder:_cutvid_vencoders' \
'--aencoder[audio encoder]:encoder:_cutvid_aencoders' \
'--hardcode-subs[hardcode ASS subtitles]' \
'--hardcode-subs[hardcode ASS subtitles]:number:' \
'1:input file:_files' \
'2:output file:_files' \
'*:ffmpeg options:'

View File

@ -12,13 +12,13 @@ local -a o_aencoder=()
local -a o_hardcode_subs=()
zparseopts -D -K -- h=o_help -help=o_help -from:=o_from -to:=o_to \
-vencoder:=o_vencoder -aencoder:=o_aencoder \
-hardcode-subs=o_hardcode_subs
-hardcode-subs:=o_hardcode_subs
if [[ ${#o_help} -ne 0 || ! -v 2 || ${#o_from} -ne 2 || ${#o_to} -ne 2 ]]; then
local ret=$(( ${#o_help} ^ 1 ))
print -u $(( 1 + ${ret} )) "usage: ${0} [-h|--help]" \
"--from <HH:MM:SS.MMM> --to <HH:MM:SS.MMM>" \
"[--vencoder <ENCODER>] [--aencoder <ENCODER>] [--hardcode-subs]" \
"<INPUT FILE> <OUTPUT FILE> [FFMPEG OPTIONS]"
"[--vencoder <ENCODER>] [--aencoder <ENCODER>]" \
"[--hardcode-subs <NUM>] <INPUT FILE> <OUTPUT FILE> [FFMPEG OPTIONS]"
print "\e[3mYou can set bitrates with -b:v and -b:a in FFMPEG OPTIONS." \
"The -vn / -an / -sn / -dn options can be used to skip inclusion of" \
"video, audio, subtitle and data streams respectively." \
@ -38,12 +38,14 @@ local vencoder="copy"
local aencoder="copy"
[[ ${#o_vencoder} -eq 2 ]] && vencoder=${o_vencoder[2]}
[[ ${#o_aencoder} -eq 2 ]] && aencoder=${o_aencoder[2]}
local subnumber=0
[[ ${#o_hardcode_subs} -eq 2 ]] && subnumber=${o_hardcode_subs[2]}
local subtitle_options=(-codec:s copy)
local compat_options=(-pix_fmt yuv420p) # Android doesn't like yuv420p10le
if [[ ${#o_hardcode_subs} -ne 0 ]]; then
local tmpass=$(mktemp --suffix='.cutvid.ass')
ffmpeg -i ${input} -y ${tmpass}
ffmpeg -i ${input} -map 0:s:${subnumber} -y ${tmpass}
subtitle_options=(-sn -vf ass=${tmpass} )
fi