Add cli flag to set first subtitle as default

This commit is contained in:
RealStickman 2022-12-19 20:46:10 +01:00
parent 3b1a6a8329
commit dd2963c2e9

View File

@ -130,6 +130,14 @@ parser.add_argument(
help="Stream identifier for subtitles", help="Stream identifier for subtitles",
) )
parser.add_argument(
"-sd",
"--set-default-subtitle",
required=False,
action="store_true",
help="If passed, set the first subtitle as default",
)
# Output file # Output file
parser.add_argument("-o", "--output-file", required=True, type=str, help="Output file") parser.add_argument("-o", "--output-file", required=True, type=str, help="Output file")
@ -204,6 +212,11 @@ else:
subtitle = args.subtitle_name subtitle = args.subtitle_name
subtitlestream = args.subtitle_stream subtitlestream = args.subtitle_stream
if args.set_default_subtitle:
defaultsub = "-disposition:s:0 default"
else:
defaultsub = ""
# Flag to actually execute command # Flag to actually execute command
execute = args.execute execute = args.execute
@ -222,7 +235,7 @@ ff = ffmpy.FFmpeg(
" " " "
"{audiometa} -disposition:a:0 default" "{audiometa} -disposition:a:0 default"
" " " "
"-c:s copy -map {substream}? -metadata:s:s:0 title='{subtitle}' -metadata:s:s:0 language=eng -disposition:s:0 default" "-c:s copy -map {substream}? -metadata:s:s:0 title='{subtitle}' -metadata:s:s:0 language=eng {defaultsub}"
" ".format( " ".format(
title=title, title=title,
videocodec=videocodec, videocodec=videocodec,
@ -236,6 +249,7 @@ ff = ffmpy.FFmpeg(
audiometa=audiometa, audiometa=audiometa,
substream=subtitlestream, substream=subtitlestream,
subtitle=subtitle, subtitle=subtitle,
defaultsub=defaultsub,
) )
}, },
) )