Skip to content

Commit db6e19c

Browse files
committed
Set default pix_fmt & sample_fmt
1 parent e1f273e commit db6e19c

6 files changed

Lines changed: 37 additions & 22 deletions

File tree

src/ffmpegio/audio.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""Audio Read/Write Module
22
"""
33

4-
from . import ffmpegprocess, utils, configure, FFmpegError, probe, plugins
4+
from . import ffmpegprocess, utils, configure, FFmpegError, probe, plugins, caps
55
from .utils import filter as filter_utils, log as log_utils
6+
import logging
67

78
__all__ = ["create", "read", "write", "filter"]
89

@@ -187,11 +188,14 @@ def read(url, progress=None, show_log=None, **options):
187188
sample_fmt = options.get("sample_fmt", None)
188189
ac_in = ar_in = None
189190
if sample_fmt is None:
190-
# use the same format as the input
191-
info = probe.audio_streams_basic(url, 0)[0]
192-
sample_fmt = info["sample_fmt"]
193-
ac_in = info.get("ac", None)
194-
ar_in = info.get("ar", None)
191+
try:
192+
# use the same format as the input
193+
info = probe.audio_streams_basic(url, 0)[0]
194+
sample_fmt = info["sample_fmt"]
195+
ac_in = info.get("ac", None)
196+
ar_in = info.get("ar", None)
197+
except:
198+
sample_fmt = 's16'
195199

196200
input_options = utils.pop_extra_options(options, "_in")
197201
url, stdin, input = configure.check_url(

src/ffmpegio/image.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from . import ffmpegprocess, utils, configure, FFmpegError, probe, plugins
22
from .utils import filter as filter_utils, log as log_utils
3+
import logging
34

45
__all__ = ["create", "read", "write", "filter"]
56

@@ -143,9 +144,12 @@ def read(url, show_log=None, **options):
143144

144145
# get pix_fmt of the input file only if needed
145146
if "pix_fmt" not in options and "pix_fmt_in" not in options:
146-
info = probe.video_streams_basic(url, 0)[0]
147-
pix_fmt_in = info["pix_fmt"]
148-
s_in = (info["width"], info["height"])
147+
try:
148+
info = probe.video_streams_basic(url, 0)[0]
149+
pix_fmt_in = info["pix_fmt"]
150+
s_in = (info["width"], info["height"])
151+
except:
152+
pix_fmt_in = 'rgb24'
149153
else:
150154
pix_fmt_in = s_in = None
151155

src/ffmpegio/media.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def read(*urls, progress=None, show_log=None, **options):
3434
Unlike :py:mod:`video` and :py:mod:`image`, video pixel formats are not autodetected. If output
3535
'pix_fmt' option is not explicitly set, 'rgb24' is used.
3636
37-
For audio streams, if 'sample_fmt' output option is not specified, 's16le'.
37+
For audio streams, if 'sample_fmt' output option is not specified, 's16'.
3838
3939
4040
streams = ['0:v:0','1:a:3'] # pick 1st file's 1st video stream and 2nd file's 4th audio stream

src/ffmpegio/streams/AviStreams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AviMediaReader:
3232
Unlike :py:mod:`video` and :py:mod:`image`, video pixel formats are not autodetected. If output
3333
'pix_fmt' option is not explicitly set, 'rgb24' is used.
3434
35-
For audio streams, if 'sample_fmt' output option is not specified, 's16le'.
35+
For audio streams, if 'sample_fmt' output option is not specified, 's16'.
3636
3737
3838
streams = ['0:v:0','1:a:3'] # pick 1st file's 1st video stream and 2nd file's 4th audio stream

src/ffmpegio/streams/SimpleStreams.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,14 @@ def _finalize(self, ffmpeg_args):
226226
and inurl not in ("-", "pipe:", "pipe:0")
227227
and not inopts.get("pix_fmt", None)
228228
):
229-
# must assign output rgb/grayscale pixel format
230-
info = probe.video_streams_basic(inurl, 0)[0]
231-
pix_fmt_in = info["pix_fmt"]
232-
s_in = (info["width"], info["height"])
233-
r_in = info["frame_rate"]
229+
try:
230+
# must assign output rgb/grayscale pixel format
231+
info = probe.video_streams_basic(inurl, 0)[0]
232+
pix_fmt_in = info["pix_fmt"]
233+
s_in = (info["width"], info["height"])
234+
r_in = info["frame_rate"]
235+
except:
236+
pix_fmt_in = 'rgb24'
234237
else:
235238
pix_fmt_in = s_in = r_in = None
236239

@@ -290,7 +293,7 @@ def _finalize(self, ffmpeg_args):
290293
ac_in = info.get("channels", None)
291294
ar_in = info.get("sample_rate", None)
292295
except:
293-
pass
296+
sample_fmt_in = 's16'
294297

295298
(
296299
self.dtype,

src/ffmpegio/video.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from . import ffmpegprocess, utils, configure, FFmpegError, probe, plugins
1+
from . import ffmpegprocess, utils, configure, FFmpegError, probe, plugins, caps
22
from .utils import filter as filter_utils, log as log_utils
3+
import logging
34

45
__all__ = ["create", "read", "write", "filter"]
56

@@ -164,10 +165,13 @@ def read(url, progress=None, show_log=None, **options):
164165

165166
# get pix_fmt of the input file only if needed
166167
if pix_fmt is None and "pix_fmt_in" not in options:
167-
info = probe.video_streams_basic(url, 0)[0]
168-
pix_fmt_in = info["pix_fmt"]
169-
s_in = (info["width"], info["height"])
170-
r_in = info["frame_rate"]
168+
try:
169+
info = probe.video_streams_basic(url, 0)[0]
170+
pix_fmt_in = info["pix_fmt"]
171+
s_in = (info["width"], info["height"])
172+
r_in = info["frame_rate"]
173+
except:
174+
pix_fmt_in = 'rgb24'
171175
else:
172176
pix_fmt_in = s_in = r_in = None
173177

0 commit comments

Comments
 (0)