Compare commits
No commits in common. "c45861d7663da8800486624303d5ffc09836a28d" and "0d71296f48015810aacddbaa004c61dee0f78cab" have entirely different histories.
c45861d766
...
0d71296f48
129
main.py
129
main.py
@ -2,96 +2,52 @@
|
||||
|
||||
# ffmpeg wrapper
|
||||
import ffmpy
|
||||
|
||||
# argument parsing
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(description="")
|
||||
parser = argparse.ArgumentParser(description='')
|
||||
|
||||
# Input file
|
||||
parser.add_argument("-i", "--input-file", required=True, type=str, help="Input file")
|
||||
parser.add_argument("-i", "--input-file", required=True, type=str,
|
||||
help="Input file")
|
||||
|
||||
# Media title
|
||||
parser.add_argument("-t", "--title", required=True, type=str, help="Media title")
|
||||
parser.add_argument("-t", "--title", required=True, type=str,
|
||||
help="Media title")
|
||||
|
||||
# Video stuff
|
||||
parser.add_argument(
|
||||
"-vc",
|
||||
"--video-codec",
|
||||
required=False,
|
||||
type=str,
|
||||
help="Output video codec. Defaults to 'copy'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-crf",
|
||||
"--crf",
|
||||
required=False,
|
||||
type=int,
|
||||
help="Codec crf. No effect if video codec is 'copy'. Defaults to 20",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-vt", "--video-tune", required=False, type=str, help="Video codec tune"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-vp",
|
||||
"--video-preset",
|
||||
required=False,
|
||||
type=str,
|
||||
help="Video compression preset. Defaults to 'medium'",
|
||||
)
|
||||
parser.add_argument("-vc", "--video-codec", required=False, type=str,
|
||||
help="Output video codec. Defaults to 'copy'")
|
||||
parser.add_argument("-crf", "--crf", required=False, type=int,
|
||||
help="Codec crf. No effect if video codec is 'copy'. Defaults to 20")
|
||||
parser.add_argument("-vt", "--video-tune", required=False, type=str,
|
||||
help="Video codec tune")
|
||||
parser.add_argument("-vp", "--video-preset", required=False, type=str,
|
||||
help="Video compression preset. Defaults to 'medium'")
|
||||
|
||||
# Audio stuff
|
||||
parser.add_argument(
|
||||
"-ac",
|
||||
"--audio-codec",
|
||||
required=False,
|
||||
type=str,
|
||||
help="Output audio codec. Defaults to 'copy'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-ab",
|
||||
"--audio-bitrate",
|
||||
required=False,
|
||||
type=str,
|
||||
help="Output audio bitrate. No effect if audio codec is 'copy'. Defaults to '192k'",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-aj",
|
||||
"--audio-japanese",
|
||||
required=True,
|
||||
type=str,
|
||||
help="Stream identifier for japanese audio",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-ae",
|
||||
"--audio-english",
|
||||
required=False,
|
||||
type=str,
|
||||
help="Stream identifier for english audio",
|
||||
)
|
||||
parser.add_argument("-ac", "--audio-codec", required=False, type=str,
|
||||
help="Output audio codec. Defaults to 'copy'")
|
||||
parser.add_argument("-ab", "--audio-bitrate", required=False, type=str,
|
||||
help="Output audio bitrate. No effect if audio codec is 'copy'. Defaults to '192k'")
|
||||
parser.add_argument("-aj", "--audio-japanese", required=True, type=str,
|
||||
help="Stream identifier for japanese audio")
|
||||
parser.add_argument("-ae", "--audio-english", required=False, type=str,
|
||||
help="Stream identifier for english audio")
|
||||
|
||||
# Subtitle stuff
|
||||
parser.add_argument(
|
||||
"-sn", "--subtitle-name", required=True, type=str, help="Name for subtitles"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-si",
|
||||
"--subtitle-stream",
|
||||
required=True,
|
||||
type=str,
|
||||
help="Stream identifier for subtitles",
|
||||
)
|
||||
parser.add_argument("-sn", "--subtitle-name", required=True, type=str,
|
||||
help="Name for subtitles")
|
||||
parser.add_argument("-si", "--subtitle-stream", required=True, type=str,
|
||||
help="Stream identifier for subtitles")
|
||||
|
||||
# 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")
|
||||
|
||||
# Execute or print commands
|
||||
parser.add_argument(
|
||||
"-e",
|
||||
"--execute",
|
||||
action="store_true",
|
||||
help="Execute script. If not set, shows the commands that would be run.",
|
||||
)
|
||||
parser.add_argument("-e", "--execute", action="store_true",
|
||||
help="Execute script. If not set, shows the commands that would be run.")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@ -149,21 +105,13 @@ subtitlestream = args.subtitle_stream
|
||||
# Flag to actually execute command
|
||||
execute = args.execute
|
||||
|
||||
# NOTE Breaks if filename contains quotes: '
|
||||
ff = ffmpy.FFmpeg(
|
||||
inputs={inputfile: None},
|
||||
outputs={
|
||||
outputfile: "-metadata title='{title}' -disposition 0"
|
||||
" "
|
||||
"-c:v {videocodec} -crf {crf} {tune} -preset {preset} -map 0:v:0 -metadata:s:v:0 title='Video' -disposition:v:0 default"
|
||||
" "
|
||||
"-c:a {audiocodec} -b:a {audiobitrate} -map {jpnaudiostream}? {engaudiomap}"
|
||||
" "
|
||||
"-metadata:s:a:0 title='Japanese' -metadata:s:a:0 language=jpn -metadata:s:a:1 title='English' -metadata:s:a:1 language=eng -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"
|
||||
" ".format(
|
||||
title=title,
|
||||
ff = ffmpy.FFmpeg(inputs={inputfile:None},
|
||||
outputs={outputfile: "-metadata title='{title}' -disposition 0"" "
|
||||
"-c:v {videocodec} -crf {crf} {tune} -preset {preset} -map 0:v:0 -metadata:s:v:0 title='Video' -disposition:v:0 default"" "
|
||||
"-c:a {audiocodec} -b:a {audiobitrate} -map {jpnaudiostream}? {engaudiomap}"" "
|
||||
"-metadata:s:a:0 title='Japanese' -metadata:s:a:0 language=jpn -metadata:s:a:1 title='English' -metadata:s:a:1 language=eng -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"" "
|
||||
.format(title=title,
|
||||
videocodec=videocodec,
|
||||
crf=crf,
|
||||
tune=tune,
|
||||
@ -173,9 +121,8 @@ ff = ffmpy.FFmpeg(
|
||||
jpnaudiostream=japaneseaudio,
|
||||
engaudiomap=englishaudio,
|
||||
substream=subtitlestream,
|
||||
subtitle=subtitle,
|
||||
)
|
||||
},
|
||||
subtitle=subtitle)
|
||||
}
|
||||
)
|
||||
|
||||
if execute:
|
||||
|
Reference in New Issue
Block a user