仅当我指定输入格式 (-f h264) 时,FFmpeg 编码才有效

仅当我指定输入格式 (-f h264) 时,FFmpeg 编码才有效

我从 NVR 中获得了 .avi 容器中的视频。我尝试使用 libx264 对其进行重新编码,但只有当我指定输入格式为 h264 时才有效。以下是两次调用的输出。

没有-f h264

ffmpeg -i original.avi -c libx264 -preset ultrafast output.avi
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7 (GCC)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags='-I/usr/include/nvenc ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, avi, from 'original.avi':
  Duration: 00:05:00.00, start: 0.000000, bitrate: 2003 kb/s
    Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), yuv420p(progressive), 1280x720, 1997 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Error while opening decoder for input stream #0:0 : Invalid data found when processing input

-f h264

ffmpeg -f h264 -i original.avi -c libx264 -preset ultrafast output.avi
ffmpeg version 3.3.4 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 7 (GCC)
  configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ' --extra-cflags='-I/usr/include/nvenc ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-frei0r --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-avfilter --enable-avresample --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
[h264 @ 0x559e613da920] Invalid NAL unit 0, skipping.
[h264 @ 0x559e613da920] Invalid NAL unit 7, skipping.
    Last message repeated 3 times
Input #0, h264, from 'original.avi':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuv420p(progressive), 1280x720, 25 fps, 25 tbr, 1200k tbn, 50 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[h264 @ 0x559e6146f120] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6146d240] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6148f0e0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e61469e00] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6147f080] Invalid NAL unit 0, skipping.
[libx264 @ 0x559e613f39a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x559e613f39a0] profile Constrained Baseline, level 3.1
Output #0, avi, to 'output.avi':
  Metadata:
    ISFT            : Lavf57.71.100
    Stream #0:0: Video: h264 (libx264) (H264 / 0x34363248), yuv420p, 1280x720, q=-1--1, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc57.89.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
[h264 @ 0x559e616074c0] Invalid NAL unit 0, skipping.:04.52 bitrate=1292.7kbits/s speed=22.5x    
[h264 @ 0x559e61623060] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6163ec00] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6165a7a0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6146f120] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6146d240] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6148f0e0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e61469e00] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6147f080] Invalid NAL unit 0, skipping.
[h264 @ 0x559e616074c0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e61623060] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6163ec00] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6165a7a0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6146f120] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6146d240] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6148f0e0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e61469e00] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6147f080] Invalid NAL unit 0, skipping.
[h264 @ 0x559e616074c0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e61623060] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6163ec00] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6165a7a0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6146f120] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6146d240] Invalid NAL unit 0, skipping.
[h264 @ 0x559e61469e00] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6147f080] Invalid NAL unit 0, skipping.
[h264 @ 0x559e616074c0] Invalid NAL unit 0, skipping.
[h264 @ 0x559e61623060] Invalid NAL unit 8, skipping.
[h264 @ 0x559e6163ec00] Invalid NAL unit 0, skipping.
[h264 @ 0x559e6165a7a0] Invalid NAL unit 0, skipping.:48.84 bitrate=1291.1kbits/s speed=22.5x    
frame= 9000 fps=563 q=-1.0 Lsize=   56897kB time=00:06:00.00 bitrate=1294.7kbits/s speed=22.5x    
video:56677kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.389630%
[libx264 @ 0x559e613f39a0] frame I:36    Avg QP:12.22  size:118969
[libx264 @ 0x559e613f39a0] frame P:8964  Avg QP:15.00  size:  5997
[libx264 @ 0x559e613f39a0] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x559e613f39a0] mb P  I16..4:  1.2%  0.0%  0.0%  P16..4: 22.6%  0.0%  0.0%  0.0%  0.0%    skip:76.3%
[libx264 @ 0x559e613f39a0] coded y,uvDC,uvAC intra: 95.0% 0.0% 0.0% inter: 7.6% 0.0% 0.0%
[libx264 @ 0x559e613f39a0] i16 v,h,dc,p:  5%  6% 68% 21%
[libx264 @ 0x559e613f39a0] i8c dc,h,v,p: 100%  0%  0%  0%
[libx264 @ 0x559e613f39a0] kb/s:1289.71

我想指出的是,当我不指定时-f h264,它会正确获取流的持续时间(00:05:00)和 fps:30,但无法对文件进行编码。而当我指定输入格式时,它会检测到 25 fps(这是不正确的)。因此输出文件持续时间为 6 分钟而不是 5 分钟。我不明白为什么当我们强制输入格式为 h264 时会有如此大的差异,而且似乎 FFmpeg 在第一种情况下正确识别了它,但无论如何都无法编码​​。

相关内容