我使用 libavcodec 对 h264 数据进行编码。 例如。
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
和 friend 。
它们的用法显示在 muxing example 中FFmpeg 的。
查看类似主题:Raw H264 frames in mpegts container using libavcodec还写入文件(不同的容器,相同的 API)
另请参阅此处答案的链接:FFMpeg encoding RGB images to H264
关于c++ - ffmpeg:如何将 h264 原始数据保存为 mp4 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14341262/