视频压缩的流程
来源:互联网 发布:网络信息化建设需求 编辑:程序博客网 时间:2024/06/09 03:42
初始化:
av_register_all
avformat_alloc_output_context2
avcodec_find_encoder
avcodec_alloc_context3
av_dict_set
//打开编码器
avcodec_open2
//Add a new stream to output,should be called by the user before avformat_write_header() for muxing
avformat_new_stream
//Open output URL,set before avformat_write_header() for muxing
avio_open
//Write File Header
avformat_write_header(ofmt_ctx, NULL);
循环编码: 编码时需写入PTS, enc_pkt.dts = enc_pkt.pts;
avcodec_alloc_frame
//Frame分配内存
avpicture_fill
av_init_packet
//编码
avcodec_encode_video2
av_frame_free
//设置DTS -->PTS ,通过DTS\PTS实现音视频同步
enc_pkt.pts = av_rescale_q(framecnt*calc_duration, time_base_q, time_base);
//DTS -->PTS
enc_pkt.dts = enc_pkt.pts;
av_interleaved_write_frame
av_free_packet
flush:
while (1) {
av_init_packet
avcodec_encode_video2
//Write PTS
}
close:
释放内存。。。
av_register_all
avformat_alloc_output_context2
avcodec_find_encoder
avcodec_alloc_context3
av_dict_set
//打开编码器
avcodec_open2
//Add a new stream to output,should be called by the user before avformat_write_header() for muxing
avformat_new_stream
//Open output URL,set before avformat_write_header() for muxing
avio_open
//Write File Header
avformat_write_header(ofmt_ctx, NULL);
循环编码: 编码时需写入PTS, enc_pkt.dts = enc_pkt.pts;
avcodec_alloc_frame
//Frame分配内存
avpicture_fill
av_init_packet
//编码
avcodec_encode_video2
av_frame_free
//设置DTS -->PTS ,通过DTS\PTS实现音视频同步
enc_pkt.pts = av_rescale_q(framecnt*calc_duration, time_base_q, time_base);
//DTS -->PTS
enc_pkt.dts = enc_pkt.pts;
av_interleaved_write_frame
av_free_packet
flush:
while (1) {
av_init_packet
avcodec_encode_video2
//Write PTS
}
close:
释放内存。。。
阅读全文