advancedav: Allow disabling stream reordering

master
Taeyeon Mori 7 years ago
parent cd7a8d42b8
commit 2cab1e3123
  1. 23
      lib/python/advancedav.py

@ -37,7 +37,7 @@ from pathlib import Path, PurePath
__all__ = "AdvancedAVError", "AdvancedAV", "SimpleAV", "MultiAV" __all__ = "AdvancedAVError", "AdvancedAV", "SimpleAV", "MultiAV"
version_info = 2, 99, 6 version_info = 2, 99, 7
# Constants # Constants
DEFAULT_CONTAINER = "matroska" DEFAULT_CONTAINER = "matroska"
@ -198,6 +198,8 @@ class ObjectWithOptions:
""" """
__slots__ = () __slots__ = ()
local_option_names = ()
def __init__(self, *, options=None, **more): def __init__(self, *, options=None, **more):
super().__init__(**more) super().__init__(**more)
self.options = options or {} self.options = options or {}
@ -231,6 +233,13 @@ class ObjectWithOptions:
self.options.update(options) self.options.update(options)
return self return self
@property
def ffmpeg_options(self):
if self.local_option_names:
return {k: v for k, v in self.options.items() if k not in self.local_option_names}
else:
return self.options
class ObjectWithMetadata: class ObjectWithMetadata:
__slots__ = () __slots__ = ()
@ -665,7 +674,7 @@ class InputFile(File):
def generate_args(self) -> Iterator: def generate_args(self) -> Iterator:
# Input options # Input options
yield from FFmpeg.argv_options(self.options) yield from FFmpeg.argv_options(self.ffmpeg_options)
# Add Input # Add Input
yield "-i" yield "-i"
@ -776,6 +785,8 @@ class OutputFile(File, ObjectWithMetadata):
""" """
__slots__ = "task", "container", "_mapped_sources", "metadata" __slots__ = "task", "container", "_mapped_sources", "metadata"
local_option_names = ("reorder_streams",) + File.local_option_names
stream_factory = staticmethod(output_stream_factory) stream_factory = staticmethod(output_stream_factory)
def __init__(self, task: "Task", name: str, container=DEFAULT_CONTAINER, def __init__(self, task: "Task", name: str, container=DEFAULT_CONTAINER,
@ -783,6 +794,7 @@ class OutputFile(File, ObjectWithMetadata):
super().__init__(name, options=options, metadata=metadata) super().__init__(name, options=options, metadata=metadata)
self.options.setdefault("c", "copy") self.options.setdefault("c", "copy")
self.options.setdefault("reorder_streams", True)
self.task = task self.task = task
@ -795,10 +807,11 @@ class OutputFile(File, ObjectWithMetadata):
def generate_args(self) -> Iterator: def generate_args(self) -> Iterator:
# Global Metadata & Additional Options # Global Metadata & Additional Options
yield from FFmpeg.argv_metadata(self.metadata) yield from FFmpeg.argv_metadata(self.metadata)
yield from FFmpeg.argv_options(self.options) yield from FFmpeg.argv_options(self.ffmpeg_options)
# Map Streams, sorted by type # Map Streams, sorted by type
self.reorder_streams() if self.options["reorder_streams"]:
self.reorder_streams()
for stream in self.streams: for stream in self.streams:
yield "-map" yield "-map"
@ -809,7 +822,7 @@ class OutputFile(File, ObjectWithMetadata):
yield stream.codec yield stream.codec
yield from FFmpeg.argv_metadata(stream.metadata, stream.stream_spec) yield from FFmpeg.argv_metadata(stream.metadata, stream.stream_spec)
yield from FFmpeg.argv_options(stream.options, stream.stream_spec) yield from FFmpeg.argv_options(stream.ffmpeg_options, stream.stream_spec)
# Container # Container
if self.container is not None: if self.container is not None:

Loading…
Cancel
Save