我有两个命名管道,分别为audio_conv
和video
,用于s16le
和h264
流。我想将它们webm
即时转换为格式。这些管道的数据来自我的应用程序,该应用程序解析专有格式并转换音频。但有时传入流中没有音频,我无法在初始化阶段轻松确定它。当我同时传递音频和视频时,这是可以的,但是当没有音频时,相应的管道为空,据我所知,ffmpeg 停止转换视频并等待一些音频数据。
我使用的命令:
ffmpeg -v debug -probesize 10000 -r 12 -analyzeduration 0 -vsync 0 -async 0 -i video -f s16le -ar 8000 -analyzeduration 0 -channel_layout mono -i audio_conv -f webm - | ffplay -
来自 ffmpeg 日志:
Successfully parsed a group of options.
Opening an input file: video.
[h264 @ 0x23bf460] Format h264 probed with size=2048 and score=51
[h264 @ 0x23bf460] Before avformat_find_stream_info() pos: 0 bytes read:2910 seeks:0
[h264 @ 0x23bf460] Probe buffer size limit of 10000 bytes reached
[h264 @ 0x23bf460] Stream #0: not enough frames to estimate rate; consider increasing probesize
[h264 @ 0x23bf460] decoding for stream 0 failed
[h264 @ 0x23bf460] After avformat_find_stream_info() pos: 15805 bytes read:17153 seeks:0 frames:1
Input #0, h264, from 'video':
Duration: N/A, bitrate: N/A
Stream #0:0, 1, 1/1200000: Video: h264 (Baseline), 1 reference frame, yuv420p(left), 704x576, 1/50, 25 tbr, 1200k tbn, 50 tbc
Successfully opened the file.
Parsing a group of options: input file audio_conv.
Applying option f (force format) with argument s16le.
Applying option ar (set audio sampling rate (in Hz)) with argument 8000.
Applying option channel_layout (set channel layout) with argument mono.
Successfully parsed a group of options.
Opening an input file: audio_conv.
之后我可以看到视频流被传递到 ffmpeg,但一段时间后它意外停止。然后,在kill
ffmpeg 处理之后,它输出:
[s16le @ 0x16a8060] Before avformat_find_stream_info() pos: 0 bytes read:0 seeks:0
[s16le @ 0x16a8060] After avformat_find_stream_info() pos: 0 bytes read:0 seeks:0 frames:0
Input #1, s16le, from 'audio_conv':
Duration: N/A, bitrate: 128 kb/s
Stream #1:0, 0, 1/8000: Audio: pcm_s16le, 8000 Hz, mono, s16, 128 kb/s
Successfully opened the file.
Parsing a group of options: output file -.
Applying option f (force format) with argument webm.
Successfully parsed a group of options.
Opening an output file: -.
Successfully opened the file.
detected 4 logical cores 0 aq= 0KB vq= 0KB sq= 0B f=0/0
[graph 0 input from stream 0:0 @ 0x16cf220] Setting 'video_size' to value '704x576'
[graph 0 input from stream 0:0 @ 0x16cf220] Setting 'pix_fmt' to value '0'
[graph 0 input from stream 0:0 @ 0x16cf220] Setting 'time_base' to value '1/12'
[graph 0 input from stream 0:0 @ 0x16cf220] Setting 'pixel_aspect' to value '0/1'
[graph 0 input from stream 0:0 @ 0x16cf220] Setting 'sws_param' to value 'flags=2'
[graph 0 input from stream 0:0 @ 0x16cf220] Setting 'frame_rate' to value '12/1'
[graph 0 input from stream 0:0 @ 0x16cf220] w:704 h:576 pixfmt:yuv420p tb:1/12 fr:12/1 sar:0/1 sws_param:flags=2
[force CFR for input from stream 0:0 @ 0x16a95a0] Setting 'expr' to value 'N'
[format @ 0x16a6160] compat: called with args=[yuv420p|yuv422p|yuv440p|yuv444p]
[format @ 0x16a6160] Setting 'pix_fmts' to value 'yuv420p|yuv422p|yuv440p|yuv444p'
[AVFilterGraph @ 0x16cc400] query_formats: 5 queried, 4 merged, 0 already done, 0 delayed
[graph 0 input from stream 0:0 @ 0x16cf220] TB:0.083333 FRAME_RATE:12.000000 SAMPLE_RATE:nan
[graph 1 input from stream 1:0 @ 0x16aa8c0] Setting 'time_base' to value '1/8000'
[graph 1 input from stream 1:0 @ 0x16aa8c0] Setting 'sample_rate' to value '8000'
[graph 1 input from stream 1:0 @ 0x16aa8c0] Setting 'sample_fmt' to value 's16'
[graph 1 input from stream 1:0 @ 0x16aa8c0] Setting 'channel_layout' to value '0x4'
[graph 1 input from stream 1:0 @ 0x16aa8c0] tb:1/8000 samplefmt:s16 samplerate:8000 chlayout:0x4
[audio format for output stream 0:1 @ 0x16aa760] Setting 'sample_fmts' to value 's16|flt'
[audio format for output stream 0:1 @ 0x16aa760] Setting 'sample_rates' to value '48000|24000|16000|12000|8000'
[audio format for output stream 0:1 @ 0x16aa760] Setting 'channel_layouts' to value '0x4|0x3|0x7|0x33|0x37|0x3f|0x70f|0x63f'
[AVFilterGraph @ 0x16ab920] query_formats: 4 queried, 9 merged, 0 already done, 0 delayed
[libvpx-vp9 @ 0x16ce760] v1.5.0
[libvpx-vp9 @ 0x16ce760] --prefix=/usr --enable-pic --enable-shared --disable-install-bins --disable-install-srcs --size-limit=16384x16384 --enable-postproc --enable-multi-res-encoding --enable-temporal-denoising --enable-vp9-temporal-denoising --enable-vp9-postproc --target=x86_64-linux-gcc
[libvpx-vp9 @ 0x16ce760] vpx_codec_enc_cfg
[libvpx-vp9 @ 0x16ce760] generic settings
g_usage: 0
g_threads: 8
g_profile: 0
g_w: 320
g_h: 240
g_bit_depth: 8
g_input_bit_depth: 8
g_timebase: {1/30}
g_error_resilient: 0
g_pass: 0
g_lag_in_frames: 25
[libvpx-vp9 @ 0x16ce760] rate control settings
rc_dropframe_thresh: 0
rc_resize_allowed: 0
rc_resize_up_thresh: 60
rc_resize_down_thresh: 30
rc_end_usage: 0
rc_twopass_stats_in: (nil)(0)
rc_target_bitrate: 256
[libvpx-vp9 @ 0x16ce760] quantizer settings
rc_min_quantizer: 0
rc_max_quantizer: 63
[libvpx-vp9 @ 0x16ce760] bitrate tolerance
rc_undershoot_pct: 25
rc_overshoot_pct: 25
[libvpx-vp9 @ 0x16ce760] decoder buffer model
rc_buf_sz: 6000
rc_buf_initial_sz: 4000
rc_buf_optimal_sz: 5000
[libvpx-vp9 @ 0x16ce760] 2 pass rate control settings
rc_2pass_vbr_bias_pct: 50
rc_2pass_vbr_minsection_pct: 0
rc_2pass_vbr_maxsection_pct: 2000
[libvpx-vp9 @ 0x16ce760] keyframing settings
kf_mode: 1
kf_min_dist: 0
kf_max_dist: 9999
[libvpx-vp9 @ 0x16ce760]
[libvpx-vp9 @ 0x16ce760] vpx_codec_enc_cfg
[libvpx-vp9 @ 0x16ce760] generic settings
g_usage: 0
g_threads: 0
g_profile: 0
g_w: 704
g_h: 576
g_bit_depth: 8
g_input_bit_depth: 8
g_timebase: {1/12}
g_error_resilient: 0
g_pass: 0
g_lag_in_frames: 25
[libvpx-vp9 @ 0x16ce760] rate control settings
rc_dropframe_thresh: 0
rc_resize_allowed: 0
rc_resize_up_thresh: 60
rc_resize_down_thresh: 30
rc_end_usage: 0
rc_twopass_stats_in: (nil)(0)
rc_target_bitrate: 200
[libvpx-vp9 @ 0x16ce760] quantizer settings
rc_min_quantizer: 0
rc_max_quantizer: 63
[libvpx-vp9 @ 0x16ce760] bitrate tolerance
rc_undershoot_pct: 25
rc_overshoot_pct: 25
[libvpx-vp9 @ 0x16ce760] decoder buffer model
rc_buf_sz: 6000
rc_buf_initial_sz: 4000
rc_buf_optimal_sz: 5000
[libvpx-vp9 @ 0x16ce760] 2 pass rate control settings
rc_2pass_vbr_bias_pct: 50
rc_2pass_vbr_minsection_pct: 0
rc_2pass_vbr_maxsection_pct: 2000
[libvpx-vp9 @ 0x16ce760] keyframing settings
kf_mode: 1
kf_min_dist: 0
kf_max_dist: 9999
[libvpx-vp9 @ 0x16ce760]
[libvpx-vp9 @ 0x16ce760] vpx_codec_control
[libvpx-vp9 @ 0x16ce760] VP8E_SET_CPUUSED: 1
[libvpx-vp9 @ 0x16ce760] VP8E_SET_ARNR_MAXFRAMES: 0
[libvpx-vp9 @ 0x16ce760] VP8E_SET_ARNR_STRENGTH: 3
[libvpx-vp9 @ 0x16ce760] VP8E_SET_ARNR_TYPE: 3
[libvpx-vp9 @ 0x16ce760] VP8E_SET_STATIC_THRESHOLD: 0
[libvpx-vp9 @ 0x16ce760] VP9E_SET_COLOR_SPACE: 0
[libvpx-vp9 @ 0x16ce760] Using deadline: 1000000
[libopus @ 0x16cfda0] No bit rate set. Defaulting to 64000 bps.
如果没有输入数据,有没有办法告诉 ffmpeg 跳过音频?
答案1
使用-analyzeduration 3000000
之前的选项-i
以及以微秒为单位的适当值,其中 3 秒为 3,000,000
https://ffmpeg.org/ffprobe-all.html#Format-Options
analyzeduration integer (input)
Specify how many microseconds are analyzed to probe the input. A higher value will enable detecting more accurate information, but will increase latency. It defaults to 5,000,000 microseconds = 5 seconds.