首页 > 解决方案 > 播放没有文件头的 mp4 视频

问题描述

我正在为摄像机构建一些硬件和软件。硬件在将数据写入 SD 卡时捕获数据,并将数据传输到显示视频的 PC。

我需要帮助来解码和显示没有 mp4 文件标题的视频。对应于视频开始后捕获和显示视频。

我可以用 Gstreamer 播放我的示例视频

gst-launch-1.0 filesrc location=full.mp4 ! qtdemux name=demux demux.video_0 ! queue ! decodebin ! videoconvert ! videoscale ! autovideosink

如果我拿文件的中间部分

tail -c $(( 10*1024*1024 )) full.mp4 | head -c $(( 5*1024*1024 )) > middle.mp4

-我不确定如何播放文件了。

我的问题是: 如何播放缺少 mp4 文件头的文件?

有关示例视频的额外信息 (full.mp4)

gst-discoverer-1.0 file:///home/username/Videos/full.mp4 -v
Analyzing file:///home/quist/Videos/full.mp4
Done discovering file:///home/quist/Videos/full.mp4

Topology:
  container: video/quicktime
    audio: audio/mpeg, mpegversion=(int)4, framed=(boolean)true, stream-format=(string)raw, level=(string)2, base-profile=(string)lc, profile=(string)lc, codec_data=(buffer)1210, rate=(int)44100, channels=(int)2
      Tags:
        audio codec: MPEG-4 AAC audio
        maximum bitrate: 256000
        bitrate: 3108
        language code: en
        encoder: Lavf55.33.100
        container format: Quicktime
      
      Codec:
        audio/mpeg, mpegversion=(int)4, framed=(boolean)true, stream-format=(string)raw, level=(string)2, base-profile=(string)lc, profile=(string)lc, codec_data=(buffer)1210, rate=(int)44100, channels=(int)2
      Additional info:
        None
      Stream ID: ac6b090d044d63146735090a310b819cd64304c2ee05c9ee590009622318d12b/002
      Language: en
      Channels: 2 (front-left, front-right)
      Sample rate: 44100
      Depth: 32
      Bitrate: 3108
      Max bitrate: 256000
    video: video/x-h264, stream-format=(string)avc, alignment=(string)au, level=(string)4.1, profile=(string)high, codec_data=(buffer)01640029ffe1001967640029acd9405005bb0110000003001000000780f183196001000468efbcb0, width=(int)1280, height=(int)720, framerate=(fraction)60/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true
      Tags:
        video codec: H.264 / AVC
        language code: en
        bitrate: 8082504
        encoder: Lavf55.33.100
        container format: Quicktime
      
      Codec:
        video/x-h264, stream-format=(string)avc, alignment=(string)au, level=(string)4.1, profile=(string)high, codec_data=(buffer)01640029ffe1001967640029acd9405005bb0110000003001000000780f183196001000468efbcb0, width=(int)1280, height=(int)720, framerate=(fraction)60/1, pixel-aspect-ratio=(fraction)1/1, interlace-mode=(string)progressive, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, parsed=(boolean)true
      Additional info:
        None
      Stream ID: ac6b090d044d63146735090a310b819cd64304c2ee05c9ee590009622318d12b/001
      Width: 1280
      Height: 720
      Depth: 24
      Frame rate: 60/1
      Pixel aspect ratio: 1/1
      Interlaced: false
      Bitrate: 8082504
      Max bitrate: 0

Properties:
  Duration: 0:00:18.167000000
  Seekable: yes
  Live: no
  Tags: 
      video codec: H.264 / AVC
      language code: en
      bitrate: 8082504
      encoder: Lavf55.33.100
      container format: Quicktime
      audio codec: MPEG-4 AAC audio
      maximum bitrate: 256000

标签: videogstreamermp4h.264quicktime

解决方案


你不能用头/尾截断 MP4 - 你可以用 MPEG-2 传输流来做到这一点,可能并非完全没有问题。

但是你可以使用 ffmpeg 代替 head/tail:

ffmpeg -i full.mp4 -vcodec copy -acodec copy -ss 00:10:00 -to 00:20:00 middle.mp4

推荐阅读