首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >avcodec on C,定格图像

avcodec on C,定格图像
EN

Stack Overflow用户
提问于 2017-12-11 01:05:24
回答 1查看 156关注 0票数 0

我将视频数据包从视频流写入缓冲区。然后我试着把它们写到文件中。

代码语言:javascript
复制
            av_init_packet( &pkt );
            int bufer_size=250;

            while ( av_read_frame( ifcx, &pkt ) >= 0 && start_flag==0 && stop_flag==0){
                printf("reading packet - %i \n", pkg_index);
                if ( pkt.stream_index == i_index ) {
                    pkt.stream_index = ost->id;
                    pkt.pts = av_rescale_q_rnd(pkt.pts, ist->time_base, ost->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
                    pkt.dts = av_rescale_q_rnd(pkt.dts, ist->time_base, ost->time_base, AV_ROUND_NEAR_INF|AV_ROUND_PASS_MINMAX);
                    pkt.duration = av_rescale_q(pkt.duration, ist->time_base, ost->time_base);
                    pkt.pos = -1;
                    av_copy_packet(&pkt_arr[pkg_index],&pkt);
                }
                av_free_packet( &pkt );
                av_init_packet( &pkt );
                pkg_index++;

                if(pkg_index>=bufer_size){

                    int ret = avformat_write_header(ofcx, NULL);
                    av_dump_format( ofcx, 0, ofcx->filename, 1 );

                        int i;
                        int start_frame=0;
                        for(i=start_frame; i<bufer_size; i++){
                            av_interleaved_write_frame( ofcx, &pkt_arr[i] );
                        }

                          av_write_trailer( ofcx );
                          avio_close( ofcx->pb );
                          printf("END \n");
                          return 0;

                }
            }

现在的问题是:如果start_frame=0一切正常,我有10秒的视频文件。但如果start_frame=125 (例如)在resault中,我有5秒冻结图片和5秒视频的视频文件。

怎么啦?

同样在最后,我也有错误:

代码语言:javascript
复制
[avi @ 0x287a9f0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6 >= 1
[avi @ 0x287a9f0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6 >= 2
[avi @ 0x287a9f0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6 >= 3
[avi @ 0x287a9f0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6 >= 4
[avi @ 0x287a9f0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6 >= 5
[avi @ 0x287a9f0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 6 >= 6

也许你知道它是什么。

EN

回答 1

Stack Overflow用户

发布于 2017-12-11 19:35:43

这说明你必须重新调整数据包pts/dts,以适应+125帧的变化。尝试在av_interleaved_write_frame之前重新标记pt/dts。对于pts,这个简单的公式可能适用于pkt.pts = frame_count * pkt.durationdts更复杂,但对于测试推送,请尝试pkt.dts = pkt.pts。希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47741259

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档