ffmpeg解码器似乎丢帧

时间:2017-08-08 08:21:40

标签: c++ ffmpeg libavcodec virtualdub

我使用avcodec(c ++)api解码视频文件帧并处理它们。我注意到解码的帧数小于预期的\实际帧数。差异是16帧。 虽然x帧是用ffmpeg解码的,但VirtualDub说同一个文件有x + 16帧。 使用ffprobe,我看到该文件包含x帧:

$ ffprobe -v error -count_frames -select_streams v:0   -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 inputFile.avi
10875

此外,当我尝试使用ffmpeg实用程序提取x + 1帧时,我遇到了失败:

$  ffmpeg -i inputFile.avi -vf "select=eq(n\,10875)" -vframes 1 outPic.jpg
ffmpeg version N-80801-gc0cb53c Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 27.100 / 55. 27.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 40.101 / 57. 40.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 46.102 /  6. 46.102
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, avi, from 'inputFile.avi':
  Metadata:
    comment         : Recorder-v2
    encoder         : Lavf57.40.101
  Duration: 00:18:09.10, start: 0.000000, bitrate: 3421 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 1280x960 [SAR 1:1 DAR 4:3], 3420 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc
[swscaler @ 00000000021100a0] deprecated pixel format used, make sure you did set range correctly
[image2 @ 0000000001f10540] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, image2, to 'outPic.jpg':
  Metadata:
    comment         : Recorder-v2
    encoder         : Lavf57.40.101
    Stream #0:0: Video: mjpeg, yuvj420p(pc), 1280x960 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 10 fps, 10 tbn, 10 tbc
    Metadata:
      encoder         : Lavc57.48.101 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame=    0 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.00 bitrate=N/A speed=   0x
video:0kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)

有趣和奇怪的部分是按照序列生成x + 16个文件(相同的帧编号VirutalDub声称)保存这部电影的所有帧:

$ ffmpeg -i inputFile.avi "frames/out-%03d.jpg"
ffmpeg version N-80801-gc0cb53c Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 27.100 / 55. 27.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 40.101 / 57. 40.101
  libavdevice    57.  0.102 / 57.  0.102
  libavfilter     6. 46.102 /  6. 46.102
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
  libpostproc    54.  0.100 / 54.  0.100
Input #0, avi, from 'inputFile.avi':
  Metadata:
    comment         : Recorder-v2
    encoder         : Lavf57.40.101
  Duration: 00:18:09.10, start: 0.000000, bitrate: 3421 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (xvid / 0x64697678), yuv420p, 1280x960 [SAR 1:1 DAR 4:3], 3420 kb/s, 10 fps, 10 tbr, 10 tbn, 10 tbc
[swscaler @ 00000000020600a0] deprecated pixel format used, make sure you did set range correctly
[image2 @ 0000000001d20540] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, image2, to 'frames/out-%03d.jpg':
  Metadata:
    comment         : Recorder-v2
    encoder         : Lavf57.40.101
    Stream #0:0: Video: mjpeg, yuvj420p(pc), 1280x960 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 10 fps, 10 tbn, 10 tbc
    Metadata:
      encoder         : Lavc57.48.101 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame=10891 fps=120 q=24.8 Lsize=N/A time=00:18:09.10 bitrate=N/A dup=16 drop=0 speed=  12x
video:384325kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

计算的文件数/帧数:

$ ls -l frames/* | wc -l
    10891

我在这里很丢失。任何线索为什么avcodec解码x帧而不是x + 16? ffmpeg错过了帧吗? VirtualDub可能重复(16)帧吗?

由于

2 个答案:

答案 0 :(得分:0)

可能的原因是"丢帧",您可以使用VirtualDub热键" Go - >进行检查。下一帧下架"。 FFmpeg不会将它们视为独立帧,但您可以注意到时间码中的跳跃。

答案 1 :(得分:0)

  1. 发送完最后一帧后,您可能会忘记刷新编码器。
  2. 或者您可能会忘记在编写框架之前重新调整时间戳记:

    av_packet_rescale_ts(&pkt, codec_context->time_base, stream->time_base);