ffmpeg:如何将h264原始数据保存为mp4文件 [英] ffmpeg: how to save h264 raw data as mp4 file

查看:2706
本文介绍了ffmpeg:如何将h264原始数据保存为mp4文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过libavcodec编码h264数据。
ex。

  while(1){
...
avcodec_encode_video(pEnc- > pCtx,OutBuf,ENC_OUTSIZE,pEnc-> pYUVFrame);
...
}

如果我直接将OutBuf数据保存为。 264文件,它不能播放播放器。现在我想保存OutBuf



作为mp4文件。任何人都知道如何通过ffmpeg lib这样做?谢谢。

解决方案

您使用 avformat_write_header av_interleaved_write_frame avformat_write_trailer 和朋友。



他们的用法显示在复制示例的FFmpeg。



查看类似的主题:原始H264框架mpegts容器使用libavcodec 也写入一个文件(不同的容器,相同的API)



另请参阅这里的链接:将MPEG图像编码为H264的图像


I encode h264 data by libavcodec. ex.

while (1) {
  ...
  avcodec_encode_video(pEnc->pCtx, OutBuf, ENC_OUTSIZE, pEnc->pYUVFrame);
  ...
}

If I directly save OutBuf data as a .264 file, it can`t be play by player. Now I want to save OutBuf

as a mp4 file. Anyone know how to do this by ffmpeg lib? thanks.

解决方案

You use avformat_write_header, av_interleaved_write_frame, avformat_write_trailer and friends.

Their usage is shown in the muxing example of FFmpeg.

See a similar topic: Raw H264 frames in mpegts container using libavcodec with also writing to a file (different container, same API)

See also links from answer here: FFMpeg encoding RGB images to H264

这篇关于ffmpeg:如何将h264原始数据保存为mp4文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆