使用管道而不是文件从原始 h264 创建 mp4 文件

Create mp4 file from raw h264 using a pipe instead of files

我有一个可以用 VLC 显示的原始 h264 文件,在 mac:

open -a VLC file.h264

我可以用命令行将其转换为 mp4

ffmpeg -f h264 -i file.h264 -c:v copy file.mp4

但我真正想做的是:

cat file.h264 | ffmpeg > file.mp4

原因是输入来自套接字,我想将其转换并即时发送到 html 文件中的视频标签。

另一种解决方案是在网页中显示原始 h264 而无需先将其转换为 mp4。

输入是逐帧进来的,前四个字节是0,0,0,1。我的理解是这个h264 Annex B格式。

我对视频格式一窍不通,请指点方向看看。

我应该像这个问题一样研究使用 libavcodec 编写代码还是有现成的解决方案?

H.264 muxed to MP4 using libavformat not playing back

谢谢!

下面的命令行将创建一个碎片化的 MP4 (Windows cmd)

type test.h264 | ffmpeg -i - -vcodec copy -f mp4 -movflags frag_keyframe+empty_moov pipe:1 > test_frag.mp4

您应该能够找到很多 JavaScript 代码来播放碎片化的 MP4。

例如:https://github.com/chriswiggins/videojs-fmp4