ffprobe 报告一些错误的元数据,但仅当输入通过管道输入时

ffprobe reports some wrong meta data but only when input is piped in

我有一个视频文件,我正在使用 ffprobe 从中提取元数据。如果我将文件保存到磁盘并且 运行ffprobe 一切正常。但是,如果我将输入通过管道传输到 ffprobe,大多数元数据都是正确的,但是某些字段,例如 widthheightdisplay_aspect_ratio 是不正确的。 ffprobe 在输入为流时报告这些错误(请参阅下面的完整输出):

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x563c3de3c000] stream 1, offset 0x2c: partial file [mov,mp4,m4a,3gp,3g2,mj2 @ 0x563c3de3c000] Could not find codec parameters for stream 0 (Video: mpeg4 (mp4v / 0x7634706D), none, 1567 kb/s): unspecified size Consider increasing the value for the 'analyzeduration' and 'probesize' options

我尝试了 analyzedurationprobesize 的各种设置,结果没有任何变化。我尝试将其他更大的 MP4 文件通过管道传输到 ffprobe 中,并且正确报告了高度和宽度,但我没有收到 "stream 1, offset 0x2c: partial file" 输出警告。我认为这个特定文件可能存在一些问题,但如果是这样,为什么它只在文件流式传输时才引起问题?

知道问题是什么以及如何让 ffprobe 与文件输入一样使用管道吗?

带文件:

> ffprobe -show_streams camera-test.mp4 
ffprobe version 4.1.6-1~deb10u1 Copyright (c) 2007-2020 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'camera-test.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.35.101
  Duration: 00:00:05.74, start: 0.000000, bitrate: 1650 kb/s
    Stream #0:0(eng): Video: mpeg4 (Simple Profile) (mp4v / 0x7634706D), yuv420p, 720x1280 [SAR 1:1 DAR 9:16], 1567 kb/s, 30 fps, 30 tbr, 15360 tbn, 30 tbc (default)
    Metadata:
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 121 kb/s (default)
    Metadata:
      handler_name    : SoundHandle
[STREAM]
index=0
codec_name=mpeg4
codec_long_name=MPEG-4 part 2
profile=Simple Profile
codec_type=video
codec_time_base=1/30
codec_tag_string=mp4v
codec_tag=0x7634706d
width=720
height=1280
coded_width=720
coded_height=1280
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=9:16
pix_fmt=yuv420p
level=1
...

有烟斗:

> ffprobe -show_streams "pipe:0"  <camera-test.mp4 
ffprobe version 4.1.6-1~deb10u1 Copyright (c) 2007-2020 the FFmpeg developers
  built with gcc 8 (Debian 8.3.0-6)
  configuration: --prefix=/usr --extra-version='1~deb10u1' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x563c3de3c000] stream 1, offset 0x2c: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x563c3de3c000] Could not find codec parameters for stream 0 (Video: mpeg4 (mp4v / 0x7634706D), none, 1567 kb/s): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'pipe:0':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2mp41
    encoder         : Lavf58.35.101
  Duration: 00:00:05.74, start: 0.000000, bitrate: N/A
    Stream #0:0(eng): Video: mpeg4 (mp4v / 0x7634706D), none, 1567 kb/s, SAR 1:1 DAR 0:0, 30 fps, 30 tbr, 15360 tbn, 15360 tbc (default)
    Metadata:
      handler_name    : VideoHandle
    Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 121 kb/s (default)
    Metadata:
      handler_name    : SoundHandle
[STREAM]
index=0
codec_name=mpeg4
codec_long_name=MPEG-4 part 2
profile=unknown
codec_type=video
codec_time_base=1/30
codec_tag_string=mp4v
codec_tag=0x7634706d
width=0
height=0
coded_width=0
coded_height=0
has_b_frames=0
sample_aspect_ratio=1:1
display_aspect_ratio=0:0
pix_fmt=unknown
level=-99
...

两个输出之间的完全差异:

< profile=unknown
---
> profile=Simple Profile
10,13c10,13
< width=0
< height=0
< coded_width=0
< coded_height=0
---
> width=720
> height=1280
> coded_width=720
> coded_height=1280
16,18c16,18
< display_aspect_ratio=0:0
< pix_fmt=unknown
< level=-99
---
> display_aspect_ratio=9:16
> pix_fmt=yuv420p
> level=1
62c62
< profile=unknown
---
> profile=LC

Mp4 将此信息编码在 moov 框中。 moov 框可以在文件的开头或结尾。对于 moov 开头的文件,管道将起作用。对于它位于末尾的文件,您将需要探测文件的每个字节。

或者你可以用faststart重新打包文件,强制把moov放到最前面