使用ffmpeg录制视频时,视频时长错误

时间:2018-10-04 15:12:04

标签: ffmpeg h.264 frame-rate

我正在尝试使用ffmpeg录制H264视频。

为此,我要从视频源中抓取帧并将其推入FFmpeg读取并随后写入文件的管道中。

我的问题是,当我录制10秒的视频时,该文件包含加速的完整视频,即最终持续时间3秒...

我相信我遇到的问题可能与帧速率有关,因为我说要以30 FPS进行记录,但是我只能提供10 FPS。

这些是我与FFmpeg一起使用的选项:

  

-thread_queue_size 512 -framerate 30 -f rawvideo -pix_fmt rgb32 -video_size 1920x1080 -i \。\ pipe \ pipe_name -vcodec libx264 -crf 23 -pix_fmt yuv420p -preset ultrafast -r 30“ output.mp4”

这些是FFmpeg日志:

2018-10-04 15:56:11.9342 | INFO  | ffmpeg version N-91715-gd71dfc087b Copyright (c) 2000-2018 the FFmpeg developers 
2018-10-04 15:56:11.9402 | INFO  |   built with gcc 8.2.1 (GCC) 20180813 
2018-10-04 15:56:11.9402 | INFO  |   configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth 
2018-10-04 15:56:11.9402 | INFO  |   libavutil      56. 19.100 / 56. 19.100 
2018-10-04 15:56:11.9542 | INFO  |   libavcodec     58. 27.100 / 58. 27.100 
2018-10-04 15:56:11.9542 | INFO  |   libavformat    58. 17.103 / 58. 17.103 
2018-10-04 15:56:11.9728 | INFO  |   libavdevice    58.  4.101 / 58.  4.101 
2018-10-04 15:56:11.9728 | INFO  |   libavfilter     7. 26.100 /  7. 26.100 
2018-10-04 15:56:11.9999 | INFO  |   libswscale      5.  2.100 /  5.  2.100 
2018-10-04 15:56:12.0239 | INFO  |   libswresample   3.  2.100 /  3.  2.100 
2018-10-04 15:56:12.0239 | INFO  |   libpostproc    55.  2.100 / 55.  2.100 
2018-10-04 15:56:12.0350 | INFO  | Input #0, rawvideo, from '\\.\pipe\pipe_name': 
2018-10-04 15:56:12.0350 | INFO  |   Duration: N/A, start: 0.000000, bitrate: 1990656 kb/s 
2018-10-04 15:56:12.0350 | INFO  |     Stream #0:0: Video: rawvideo (BGRA / 0x41524742), bgra, 1920x1080, 1990656 kb/s, 30 tbr, 30 tbn, 30 tbc 
2018-10-04 15:56:12.0481 | INFO  | Stream mapping: 
2018-10-04 15:56:12.0481 | INFO  |   Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264)) 
2018-10-04 15:56:12.0691 | INFO  | Press [q] to stop, [?] for help 
2018-10-04 15:56:12.0881 | INFO  | [libx264 @ 000001bceea618c0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 
2018-10-04 15:56:12.0881 | INFO  | [libx264 @ 000001bceea618c0] profile Constrained Baseline, level 4.0, 4:2:0, 8-bit 
2018-10-04 15:56:12.0951 | INFO  | [libx264 @ 000001bceea618c0] 264 - core 157 r2932 303c484 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=30.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0 
2018-10-04 15:56:12.0951 | INFO  | Output #0, mp4, to 'output.mp4': 
2018-10-04 15:56:12.0951 | INFO  |   Metadata: 
2018-10-04 15:56:12.0951 | INFO  |     encoder         : Lavf58.17.103 
2018-10-04 15:56:12.0951 | INFO  |     Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1920x1080, q=-1--1, 30 fps, 15360 tbn, 30 tbc 
2018-10-04 15:56:12.1171 | INFO  |     Metadata: 
2018-10-04 15:56:12.1171 | INFO  |       encoder         : Lavc58.27.100 libx264 
2018-10-04 15:56:12.1531 | INFO  |     Side data: 
2018-10-04 15:56:12.1691 | INFO  |       cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 
2018-10-04 15:56:12.8750 | INFO  | frame=    8 fps=0.0 q=31.0 size=       0kB time=00:00:00.00 bitrate=5907.7kbits/s speed=0.000121x     
2018-10-04 15:56:13.3238 | INFO  | frame=   11 fps=9.9 q=31.0 size=       0kB time=00:00:00.10 bitrate=   3.8kbits/s speed=0.0904x     
2018-10-04 15:56:13.7782 | INFO  | frame=   16 fps=9.5 q=31.0 size=       0kB time=00:00:00.26 bitrate=   1.4kbits/s speed=0.159x     
2018-10-04 15:56:14.2346 | INFO  | frame=   21 fps=9.5 q=31.0 size=       0kB time=00:00:00.43 bitrate=   0.9kbits/s speed=0.197x     
2018-10-04 15:56:14.8011 | INFO  | frame=   27 fps=9.7 q=31.0 size=       0kB time=00:00:00.63 bitrate=   0.6kbits/s speed=0.229x     
2018-10-04 15:56:15.4266 | INFO  | frame=   33 fps=9.7 q=32.0 size=       0kB time=00:00:00.83 bitrate=   0.5kbits/s speed=0.246x     
2018-10-04 15:56:16.0827 | INFO  | frame=   39 fps=9.6 q=31.0 size=     256kB time=00:00:01.03 bitrate=2029.7kbits/s speed=0.255x     
2018-10-04 15:56:16.7291 | INFO  | frame=   47 fps= 10 q=31.0 size=     256kB time=00:00:01.30 bitrate=1613.4kbits/s speed=0.277x     
2018-10-04 15:56:17.4279 | INFO  | frame=   54 fps= 10 q=31.0 size=     256kB time=00:00:01.53 bitrate=1367.9kbits/s speed=0.284x     
2018-10-04 15:56:18.0562 | INFO  | frame=   61 fps= 10 q=31.0 size=     512kB time=00:00:01.76 bitrate=2374.3kbits/s speed=0.298x     
2018-10-04 15:56:18.5401 | INFO  | frame=   64 fps=9.9 q=31.0 size=     512kB time=00:00:01.86 bitrate=2247.1kbits/s speed=0.287x     
2018-10-04 15:56:19.2106 | INFO  | frame=   70 fps=9.9 q=32.0 size=     512kB time=00:00:02.06 bitrate=2029.6kbits/s speed=0.293x     
2018-10-04 15:56:19.6653 | INFO  | frame=   75 fps=9.9 q=31.0 size=     512kB time=00:00:02.23 bitrate=1878.2kbits/s speed=0.294x     
2018-10-04 15:56:20.1512 | INFO  | frame=   78 fps=9.6 q=31.0 size=     512kB time=00:00:02.33 bitrate=1797.7kbits/s speed=0.287x     
2018-10-04 15:56:21.0577 | INFO  | frame=   84 fps=9.3 q=31.0 size=     768kB time=00:00:02.53 bitrate=2483.6kbits/s speed=0.281x     
2018-10-04 15:56:21.6416 | INFO  | frame=   91 fps=9.5 q=31.0 size=     768kB time=00:00:02.76 bitrate=2274.1kbits/s speed=0.29x     
2018-10-04 15:56:22.1779 | INFO  | frame=   97 fps=9.6 q=31.0 size=     768kB time=00:00:02.96 bitrate=2120.8kbits/s speed=0.295x     
2018-10-04 15:56:22.6571 | INFO  | frame=  101 fps=9.5 q=-1.0 Lsize=    1015kB time=00:00:03.33 bitrate=2495.6kbits/s speed=0.313x     
2018-10-04 15:56:22.6571 | INFO  | video:1014kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.117556% 
2018-10-04 15:56:22.6571 | INFO  | [libx264 @ 000001bceea618c0] frame I:1     Avg QP:27.00  size: 60682 
2018-10-04 15:56:22.6571 | INFO  | [libx264 @ 000001bceea618c0] frame P:100   Avg QP:31.09  size:  9774 
2018-10-04 15:56:22.6571 | INFO  | [libx264 @ 000001bceea618c0] mb I  I16..4: 100.0%  0.0%  0.0% 
2018-10-04 15:56:22.6736 | INFO  | [libx264 @ 000001bceea618c0] mb P  I16..4: 10.6%  0.0%  0.0%  P16..4: 15.2%  0.0%  0.0%  0.0%  0.0%    skip:74.3% 
2018-10-04 15:56:22.6736 | INFO  | [libx264 @ 000001bceea618c0] coded y,uvDC,uvAC intra: 15.8% 24.4% 1.4% inter: 4.8% 6.8% 0.0% 
2018-10-04 15:56:22.6736 | INFO  | [libx264 @ 000001bceea618c0] i16 v,h,dc,p: 39% 20% 15% 26% 
2018-10-04 15:56:22.6736 | INFO  | [libx264 @ 000001bceea618c0] i8c dc,h,v,p: 54% 19% 20%  7% 
2018-10-04 15:56:22.6896 | INFO  | [libx264 @ 000001bceea618c0] kb/s:2466.66 

因此,通过日志,我可以看到我在10秒内提供了大约100帧,但是FFmpeg在3秒内写了所有这100帧...

我要怎么写才能在10秒钟内散布100帧?

我查看了一个名为-vsync的FFmpeg选项,但没有成功。

1 个答案:

答案 0 :(得分:1)

-use_wallclock_as_timestamps true添加为输入选项,即在-i之前。

原始视频输入没有固有的时间戳,因此多路分解器根据帧率值生成平滑序列