最近学习了h265封装mp4,使用ffmpeg实现,因此记录一下。。参考了雷神和其他人的代码,只包含视频文件。
1.由于ffmpeg使用c实现,头文件需要带上extern "c"和 __STDC_CONSTANT_MACROS。
2.原本需要 av_register_all 和 avcodec_copy_context,但由于新版ffmpeg已经不使用AVStream->codec,需要其他方法设置 codec,av_register_all已经删除不使用。
AVStream *out_stream = avformat_new_stream((*pFormatCtx), NULL);
//Copy the settings of AVCodecContext
AVCodecContext *codecCtx = avcodec_alloc_context3(NULL);
avcodec_parameters_to_context(codecCtx, in_stream->codecpar);
codecCtx->codec_tag = 0;
if ((*pFormatCtx)->oformat->flags & AVFMT_GLOBALHEADER)
codecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
avcodec_parameters_from_context(out_stream->codecpar, codecCtx);
3. 调用的静态库和动态库需要区分x86和x64,否则很可能一直编译不过。。
4. h264/h265没有解码时间戳,填入pkt之前需要设置pts,dts和duration。
//Write PTS
AVRational time_base1 = in_stream->time_base;
//Duration between 2 frames (us)
int64_t calc_

本文记录了使用ffmpeg将h265视频封装为mp4文件的过程,包括设置环境、处理时间戳和文件操作等关键步骤。在实践中,需要注意ffmpeg API的更新,以及不同平台的库兼容性问题。

9239

被折叠的 条评论
为什么被折叠?



