1

У меня есть видео с 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 кадров в секунду (что не правильно). Таким образом, длительность выходного файла составляет 6 минут вместо 5. Я не очень понимаю, почему такая большая разница, когда мы вводим формат ввода в h264, и кажется, что FFmpeg правильно идентифицирует его в первом случае, но все равно не может кодировать.

0