FFmpeg 连接 - 打开编码器时出错

FFmpeg 连接 - 打开编码器时出错

我有一个 Android 应用程序,它使用 ffmpeg 将 2 个 mp4 视频文件 (360x640) 连接在一起并将其输出为一个 .mp4。这是我的命令:

ffmpeg -y -i vid_1.mp4 -i vid_2.mp4 -strictexperimental -s 360x640 -ar 44100 -pix_fmt yuv420p -codec:v libx264 -codec:a aac -filter_complex [0:0] setsar=1/1[sarfix];[sarfix] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1 vid_output.mp4

该命令有效,我的一些用户遇到了以下错误(我自己似乎无法重现)

完整日志:

ffmpeg version N-69972-g6c91afe Copyright (c) 2000-2015 the FFmpeg developers
  built with gcc 4.4.3 (GCC)
ffmpeg4android 2.5_23 
  libavutil      54. 19.100 / 54. 19.100
  libavcodec     56. 25.100 / 56. 25.100
  libavformat    56. 23.100 / 56. 23.100
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.100 /  5. 11.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Splitting the commandline.
Reading option '-y' ... matched as option 'y' (overwrite output files) with argument '1'.
Reading option '-i' ... matched as input file with argument 'vid_1.mp4'.
Reading option '-i' ... matched as input file with argument 'vid_2.mp4'.
Reading option '-strict' ...Routing option strict to both codec and muxer layer
 matched as AVOption 'strict' with argument 'experimental'.
Reading option '-s' ... matched as option 's' (set frame size (WxH or abbreviation)) with argument '360x640'.
Reading option '-ar' ... matched as option 'ar' (set audio sampling rate (in Hz)) with argument '44100'.
Reading option '-pix_fmt' ... matched as option 'pix_fmt' (set pixel format) with argument 'yuv420p'.
Reading option '-codec:v' ... matched as option 'codec' (codec name) with argument 'libx264'.
Reading option '-codec:a' ... matched as option 'codec' (codec name) with argument 'aac'.
Reading option '-filter_complex' ... matched as option 'filter_complex' (create a complex filtergraph) with argument '[0:0] setsar=1/1[sarfix];[sarfix] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1'.
Reading option 'vid_output.mp4' ... matched as output file.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option y (overwrite output files) with argument 1.
Applying option filter_complex (create a complex filtergraph) with argument [0:0] setsar=1/1[sarfix];[sarfix] [0:1] [1:0] [1:1] concat=n=2:v=1:a=1.
Successfully parsed a group of options.
Parsing a group of options: input file vid_1.mp4.
Successfully parsed a group of options.
Opening an input file: vid_1.mp4.
Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
ISO: File Type Major Brand: isom
Before avformat_find_stream_info() pos: 3143489 bytes read:39076 seeks:1
All info found
After avformat_find_stream_info() pos: 64041 bytes read:104612 seeks:2 frames:2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vid_1.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.23.100
  Duration: 00:00:05.90, start: 0.023220, bitrate: 4262 kb/s
    Stream #0:0(eng), 1, 1/15360: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 360x640 [SAR 1:1 DAR 9:16], 4125 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Successfully opened the file.
Parsing a group of options: input file vid_2.mp4.
Successfully parsed a group of options.
Opening an input file: vid_2.mp4.
Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
ISO: File Type Major Brand: isom
Before avformat_find_stream_info() pos: 939642 bytes read:41527 seeks:1
All info found
After avformat_find_stream_info() pos: 32674 bytes read:74295 seeks:2 frames:2
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'vid_2.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.23.100
  Duration: 00:00:08.90, start: 0.000000, bitrate: 844 kb/s
    Stream #1:0(und), 1, 1/15360: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 360x640, 708 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #1:1(und), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
Successfully opened the file.
Parsing a group of options: output file vid_output.mp4.
Applying option s (set frame size (WxH or abbreviation)) with argument 360x640.
Applying option ar (set audio sampling rate (in Hz)) with argument 44100.
Applying option pix_fmt (set pixel format) with argument yuv420p.
Applying option codec:v (codec name) with argument libx264.
Applying option codec:a (codec name) with argument aac.
Successfully parsed a group of options.
Opening an output file: vid_output.mp4.
detected 4 logical cores
Setting 'sar' to value '1/1'
Setting 'n' to value '2'
Setting 'v' to value '1'
Setting 'a' to value '1'
Setting 'video_size' to value '360x640'
Setting 'pix_fmt' to value '0'
Setting 'time_base' to value '1/15360'
Setting 'pixel_aspect' to value '1/1'
Setting 'sws_param' to value 'flags=2'
Setting 'frame_rate' to value '30/1'
w:360 h:640 pixfmt:yuv420p tb:1/15360 fr:30/1 sar:1/1 sws_param:flags=2
Setting 'time_base' to value '1/44100'
Setting 'sample_rate' to value '44100'
Setting 'sample_fmt' to value 'fltp'
Setting 'channel_layout' to value '0x4'
tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x4
Setting 'video_size' to value '360x640'
Setting 'pix_fmt' to value '0'
Setting 'time_base' to value '1/15360'
Setting 'pixel_aspect' to value '0/1'
Setting 'sws_param' to value 'flags=2'
Setting 'frame_rate' to value '30/1'
w:360 h:640 pixfmt:yuv420p tb:1/15360 fr:30/1 sar:0/1 sws_param:flags=2
Setting 'time_base' to value '1/44100'
Setting 'sample_rate' to value '44100'
Setting 'sample_fmt' to value 'fltp'
Setting 'channel_layout' to value '0x3'
tb:1/44100 samplefmt:fltp samplerate:44100 chlayout:0x3
Setting 'w' to value '360'
Setting 'h' to value '640'
Setting 'flags' to value '0x4'
w:360 h:640 flags:'0x4' interl:0
compat: called with args=[yuv420p]
Setting 'pix_fmts' to value 'yuv420p'
Setting 'sample_fmts' to value 'fltp'
Setting 'sample_rates' to value '44100'
Successfully opened the file.
auto-inserting filter 'auto-inserted resampler 0' between the filter 'graph 0 input from stream 1:1' and the filter 'Parsed_concat_1'
query_formats: 11 queried, 16 merged, 3 already done, 0 delayed
w:360 h:640 sar:1/1 dar:9/16 -> sar:1/1 dar:9/16
0.707107 0.707107 
ch:2 chl:stereo fmt:fltp r:44100Hz -> ch:1 chl:mono fmt:fltp r:44100Hz
w:360 h:640 fmt:yuv420p sar:1/1 -> w:360 h:640 fmt:yuv420p sar:1/1 flags:0x4
using mv_range_thread = 56
using SAR=1/1
using cpu capabilities: ARMv6 NEON
Output #0, mp4, to 'vid_output.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf56.23.100
    Stream #0:0, 0, 0/0: Video: h264, none, q=2-31, 128 kb/s, SAR 1:1 DAR 0:0, 30 fps (default)
    Metadata:
      encoder         : Lavc56.25.100 libx264
    Stream #0:1, 0, 0/0: Audio: aac, 0 channels, 128 kb/s (default)
    Metadata:
      encoder         : Lavc56.25.100 aac
Stream mapping:
  Stream #0:0 (h264) -> setsar
  Stream #0:1 (aac) -> concat:in0:a0
  Stream #1:0 (h264) -> concat:in1:v0
  Stream #1:1 (aac) -> concat:in1:a0
  concat:out:v0 -> Stream #0:0 (libx264)
  concat:out:a0 -> Stream #0:1 (aac)
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
exit_program: 1 
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

知道为什么有些人会遇到这个错误吗?有人能解释一下发生了什么吗?谢谢!

答案1

满足您的核心需求,这个命令就可以做到

ffmpeg -ss 2 -t 8 -i original_vid.mp4 \
       -filter_complex "[0:v]split[v]f]; \
                        [f]loop=150:1:30,trim=start_frame=30:end_frame=180[fr]; \
                        [v][fr]concat=n=2,scale=640x360,setsar=1[vid]; \
                        [0:a]apad[aud]" \
-map "[vid]" -map "[aud]" \
-r 30 -c:a aac -ar 44100 -strict experimental -t 13 -y vid_output.mp4

ss提供t您需要的修剪段。

环路滤波器将第 30 帧(即 30 fps 视频中 1 秒的帧)循环播放 150 帧,即 30 fps 的 5 秒。

然后应用修剪来提取循环部分,起始帧是 1 秒处的帧索引,结束帧是 5 秒后,因此对于 30 fps 的视频,+150。然后将其与原始修剪片段连接起来,最后缩放。

这里不需要填充音频,只需保持流长度相同即可。

最后,由于有一个 apad 过滤器可以无限延长音频,因此-t 13在编码了 8 秒修剪 + 5 秒图像循环后,该过程就会停止。

相关内容