@@ -53,8 +53,8 @@ def __getitem__(self, index):
5353 Process the audio and video portions of a stream independently::
5454
5555 input = ffmpeg.input('in.mp4')
56- audio = input[: 'a'].filter("aecho", 0.8, 0.9, 1000, 0.3)
57- video = input[: 'v'].hflip()
56+ audio = input['a'].filter("aecho", 0.8, 0.9, 1000, 0.3)
57+ video = input['v'].hflip()
5858 out = ffmpeg.output(audio, video, 'out.mp4')
5959 """
6060 if self .selector is not None :
@@ -63,6 +63,56 @@ def __getitem__(self, index):
6363 raise TypeError ("Expected string index (e.g. 'a'); got {!r}" .format (index ))
6464 return self .node .stream (label = self .label , selector = index )
6565
66+ @property
67+ def audio (self ):
68+ """Select the audio-portion of a stream.
69+
70+ Some ffmpeg filters drop audio streams, and care must be taken
71+ to preserve the audio in the final output. The ``.audio`` and
72+ ``.video`` operators can be used to reference the audio/video
73+ portions of a stream so that they can be processed separately
74+ and then re-combined later in the pipeline. This dilemma is
75+ intrinsic to ffmpeg, and ffmpeg-python tries to stay out of the
76+ way while users may refer to the official ffmpeg documentation
77+ as to why certain filters drop audio.
78+
79+ ``stream.audio`` is a shorthand for ``stream['a']``.
80+
81+ Example:
82+ Process the audio and video portions of a stream independently::
83+
84+ input = ffmpeg.input('in.mp4')
85+ audio = input.audio.filter("aecho", 0.8, 0.9, 1000, 0.3)
86+ video = input.video.hflip()
87+ out = ffmpeg.output(audio, video, 'out.mp4')
88+ """
89+ return self ['a' ]
90+
91+ @property
92+ def video (self ):
93+ """Select the video-portion of a stream.
94+
95+ Some ffmpeg filters drop audio streams, and care must be taken
96+ to preserve the audio in the final output. The ``.audio`` and
97+ ``.video`` operators can be used to reference the audio/video
98+ portions of a stream so that they can be processed separately
99+ and then re-combined later in the pipeline. This dilemma is
100+ intrinsic to ffmpeg, and ffmpeg-python tries to stay out of the
101+ way while users may refer to the official ffmpeg documentation
102+ as to why certain filters drop audio.
103+
104+ ``stream.video`` is a shorthand for ``stream['v']``.
105+
106+ Example:
107+ Process the audio and video portions of a stream independently::
108+
109+ input = ffmpeg.input('in.mp4')
110+ audio = input.audio.filter("aecho", 0.8, 0.9, 1000, 0.3)
111+ video = input.video.hflip()
112+ out = ffmpeg.output(audio, video, 'out.mp4')
113+ """
114+ return self ['v' ]
115+
66116
67117def get_stream_map (stream_spec ):
68118 if stream_spec is None :
@@ -286,3 +336,8 @@ def filter_operator(name=None):
286336
287337def output_operator (name = None ):
288338 return stream_operator (stream_classes = {OutputStream }, name = name )
339+
340+
341+ __all__ = [
342+ 'Stream' ,
343+ ]
0 commit comments