如何使用 ffmpeg 将 .raw 视频文件转换为 .avi?

如何使用 ffmpeg 将 .raw 视频文件转换为 .avi?

mediainfo文件上给出以下输出 -

General
Complete name                            : 0x5C3C6393.raw
Format                                   : AVC
Format/Info                              : Advanced Video Codec
File size                                : 91.7 MiB

Video
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 1 frame
Format settings, GOP                     : M=1, N=15
Width                                    : 800 pixels
Height                                   : 600 pixels
Display aspect ratio                     : 4:3
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Color range                              : Full
Color primaries                          : BT.709
Transfer characteristics                 : BT.709
Matrix coefficients                      : BT.709

我试过了ffmpeg -f rawvideo -pixel_format yuv420p -video_size 800x600 -framerate 15 -i 0x5C3C6393.raw test.avi,但没用。此命令的输出为 -

ffmpeg version 2.8.15-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[rawvideo @ 0x819e00] Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from '0x5C3C6393.raw':
  Duration: 00:00:08.93, start: 0.000000, bitrate: 86129 kb/s
    Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 800x600, 86400 kb/s, 15 tbr, 15 tbn, 15 tbc
Output #0, avi, to 'test.avi':
  Metadata:
    ISFT            : Lavf56.40.101
    Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 800x600, q=2-31, 200 kb/s, 15 fps, 15 tbn, 15 tbc
    Metadata:
      encoder         : Lavc56.60.100 mpeg4
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
Press [q] to stop, [?] for help
[rawvideo @ 0x8236c0] Invalid buffer size, packet size 417540 < expected frame_size 720000
Error while decoding stream #0:0: Invalid argument
frame=  133 fps=0.0 q=24.8 Lsize=   31118kB time=00:00:08.86 bitrate=28750.0kbits/s
video:31109kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.028070%

输出ffmpeg -i 0x5C3C6393.raw -c copy output.mp4-

ffmpeg version 2.8.15-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
  libavutil      54. 31.100 / 54. 31.100
  libavcodec     56. 60.100 / 56. 60.100
  libavformat    56. 40.101 / 56. 40.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 40.101 /  5. 40.101
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  2.101 /  1.  2.101
  libpostproc    53.  3.100 / 53.  3.100
[image2 @ 0xdf4de0] Format image2 detected only with low score of 5, misdetection possible!
[rawvideo @ 0xdf6200] Invalid pixel format.
[image2 @ 0xdf4de0] Failed to open codec in av_find_stream_info
[rawvideo @ 0xdf6200] Invalid pixel format.
[image2 @ 0xdf4de0] Could not find codec parameters for stream 0 (Video: rawvideo, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
0x5C3C6393.raw: could not find codec parameters
Input #0, image2, from '0x5C3C6393.raw':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: rawvideo, none, 25 tbr, 25 tbn, 25 tbc
[mp4 @ 0xdf6f00] dimensions not set
Output #0, mp4, to 'output.mp4':
    Stream #0:0: Video: rawvideo, none, q=2-31, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument

更新-

按照@slhck 的建议更新 ffmpeg 并尝试 @Gyan 建议的命令(略作修改)后,ffmpeg -f h264 -r 15 -i 0x5C3C3031.raw -c copy output_3031.avi我得到了不错的 avi 视频。但是,输出的持续时间比预期的持续时间要短一点。原始视频应该为 10:54 长,但此处的输出为 9:54 长。我将帧速率指定为 15(我正在将时间与官方提供的工具转换的视频进行比较,这些视频的帧率为 15 fps)。此外,在我尝试的另一个较大的文件上,输出应该为 59:53 长,但实际为 57:41。以下是命令的输出ffmpeg -f h264 -r 15 -i 0x5C3C3031.raw -c copy output_3031.avi-

ffmpeg version N-48102-g7cab5471b2-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gmp --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libdav1d --enable-libxvid --enable-libzvbi --enable-libzimg
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 46.100 / 58. 46.100
  libavformat    58. 26.100 / 58. 26.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 3 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 3 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 3 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 3 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] A non-intra slice in an IDR NAL unit.
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 1 times
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 5, skipping.
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 1 times
[h264 @ 0x5ca2540] Invalid NAL unit 5, skipping.
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] non-existing PPS 0 referenced
[h264 @ 0x5ca2540] decode_slice_header error
[h264 @ 0x5ca2540] no frame!
[AVBSFContext @ 0x5cc0440] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 2 times
[h264 @ 0x5ca2540] Invalid NAL unit 8, skipping.
[h264 @ 0x5ca2540] Invalid NAL unit 5, skipping.
[h264 @ 0x5ca2540] Invalid NAL unit 0, skipping.
    Last message repeated 17 times
Input #0, h264, from '0x5C3C3031.raw':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 800x600, 15 fps, 15 tbr, 1200k tbn, 30 tbc
Output #0, avi, to 'output_3031.avi':
  Metadata:
    ISFT            : Lavf58.26.100
    Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), yuvj420p(pc, bt709, progressive), 800x600, q=2-31, 15 fps, 15 tbr, 15 tbn, 15 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[avi @ 0x5cca640] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
Invalid UE golomb code-1.0 size=  206854kB time=00:22:02.26 bitrate=1281.5kbits/s speed=2.64e+03x
[NULL @ 0x5ca2540] pps_id 3199971767 out of range
[NULL @ 0x5ca2540] illegal POC type 6
[NULL @ 0x5ca2540] SEI type 156 size 488 truncated at 2480.40 bitrate=1281.2kbits/s speed=2.64e+03x
frame=51906 fps=39449 q=-1.0 Lsize=  543722kB time=00:57:41.06 bitrate=1286.9kbits/s speed=2.63e+03x
video:542474kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.229998%

答案1

这不是原始的。它是 AVC,即 H.264 附件 B。看起来像附件 B,因为从这个https://stackoverflow.com/questions/51353973/what-is-different-between-h-265-hevc-in-a-containermp4-mkv-and-h-265-hevc你可以看到它插入了 0x000001,可以被识别为 NAL 单元 0,要将其解码为经典 avc,你需要使用 ffmpeg,因为它只有 h264_mp4toannexb 和h264_annexbtomp4,但这里有一个https://github.com/ireader/media-server/commit/76e62c806aaa5e1f97c626a52df0b03c2b2b47b1附件 B 问题在此处https://trac.ffmpeg.org/ticket/8781

此外,ffmpeg 2.8.15 版本太旧了,这太疯狂了。

相关内容