Merge branch 'master' of https://github.com/nstanger/process_podcast
commit 896025181de57365b8231794289aef464f0897e5
2 parents 3b8ff99 + 1ef51f2
Nigel Stanger authored on 23 Jul 2018
Showing 2 changed files
View
56
process_podcast.py
"See config_help.md details on the file "
"format.".format(p=globals.PROGRAM))
parser.add_argument(
"--copy-audio", dest="process_audio", action="store_false",
default=True,
help="Disable additional processing of the source audio. The audio "
"will still be re-encoded using the specified audio codec "
"because the concatenation filter requires it, but extra "
"processing such as reduction of channels or normalisation "
"will not be carried out. (Implies --no-normalise.)")
parser.add_argument(
"--copy-video", dest="process_video", action="store_false",
default=True,
help="Disable additional processing of the source video. The video "
"will still be re-encoded using the specified video codec "
"because the concatenation filter requires it, but extra "
"processing such as remapping of colours will not be "
"carried out.")
parser.add_argument(
"--no-normalise", dest="normalise", action="store_false",
default=True,
help="Disable normalisation of the source audio level (implied by "
"--copy-audio).")
parser.add_argument(
"--audio-codec", dest="audio_codec", metavar="CODEC",
default="pcm_s16le",
help="Specify ffmpeg audio codec for output (default pcm_s16le). "
"See the output of ffmpeg -codecs for possible codecs.")
parser.add_argument(
"--video-codec", dest="video_codec", metavar="CODEC", default="h264",
help="Specify ffmpeg video codec for output (default h264). "
"See the output of ffmpeg -codecs for possible codecs.")
parser.add_argument(
"--input-prefix", "-i", dest="prefix", metavar="PATH", default=".",
help="Path to be prefixed to all INPUT files. This includes the "
"configuration file, if applicable, and any files specified "
"within the configuration file. Input files that already "
prefix_path, [args.prefix] * 3, [args.audio, args.video, args.config])
 
if args.quiet:
globals.log.setLevel(logging.WARNING)
# --copy-audio implies --no-normalise.
if not args.process_audio:
args.normalise = False
# --debug overrides --quiet.
if args.debug:
globals.log.setLevel(logging.DEBUG)
# Odd number of timestamps: punch in at last timestamp,
# out at stream duration.
if (len(time_list) % 2 != 0):
globals.log.debug("{fn}(): odd number of timestamps".format(fn=fn))
punch_in, _ = process_timestamp_pair(args, [time_list[-1], None])
punch_out = stream_duration - punch_in
punch_out = stream_duration
segments.append(make_new_segment(type, filename, punch_in,
punch_out, num))
return segments
 
globals.log.info("Rendering final podcast...")
command = FFmpegConcatCommand(has_audio=len(audio_segments) > 0,
has_video=len(video_segments) > 0,
max_progress=duration,
quiet=args.quiet and not args.debug)
quiet=args.quiet and not args.debug,
process_audio=args.process_audio,
process_video=args.process_video,
audio_codec=args.audio_codec,
video_codec=args.video_codec)
input_files = Segment.input_files()
for f in input_files:
if (input_files[f]):
command.append_input_options(input_files[f])
command.append_input_options(["-i", f])
for s in (audio_segments + video_segments):
command.append_filter(s.trim_filter())
command.append_concat_filter("a", [s for s in audio_segments])
command.append_normalisation_filter()
if (args.normalise):
command.append_normalisation_filter()
command.append_concat_filter("v", [s for s in video_segments])
if args.preview:
globals.log.info("PREVIEW MODE: {fps} fps".format(fps=args.preview))
command.append_output_options(["-r", args.preview])
View
30
shell_command.py
"""An ffmpeg shell command with a complex concat filter."""
_expect_patterns = [r"time=(\d\d):(\d\d):(\d\d\.\d\d)"]
def __init__(self, input_options=[], output_options=[], quiet=False,
max_progress=100, has_audio=False, has_video=False):
max_progress=100, has_audio=False, has_video=False,
process_audio=True, process_video=True,
audio_codec="pcm_s16le", video_codec="h264"):
super(FFmpegConcatCommand, self).__init__(
input_options, output_options)
self.progress = ProgressBar(max_value=max_progress, quiet=quiet)
self.has_video = has_video
self.process_video = process_video
self.video_codec = video_codec
if (self.has_video):
self.prepend_output_options(["-codec:v", "h264",
"-pix_fmt", "yuv420p",
"-map", "[vconc]"])
self.prepend_output_options(["-map", "[vconc]"])
if (self.process_video):
self.prepend_output_options(["-pix_fmt", "yuv420p"])
self.prepend_output_options(["-codec:v", self.video_codec])
self.has_audio = has_audio
self.process_audio = process_audio
self.audio_codec = audio_codec
if (self.has_audio):
self.prepend_output_options(["-codec:a", "pcm_s16le",
"-ac", "1",
"-map", "[anorm]"])
if (self.process_audio):
self.prepend_output_options(["-ac", "1",
"-map", "[anorm]"])
else:
self.prepend_output_options(["-map", "[aconc]"])
self.prepend_output_options(["-codec:a", self.audio_codec])
self.filters = []
def append_filter(self, filter):
"""Append a filter to the filters list."""