c - C 上的 avcodec,卡住图像

标签 c ffmpeg libavcodec

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

            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(例如),我的视频文件包含 5 秒卡住图片和 5 秒视频。

出了什么问题?

最后我也有错误:

[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

也许你知道那是什么。

最佳答案

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

关于c - C 上的 avcodec,卡住图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47741259/

相关文章:

c - 在函数内链接函数时出错

c - K&R C 示例中的指针类型不匹配警告

c - 提取特定范围的位并在 C 中找到它们之间的零数

c - 如何使数组中的每一列适合宾果卡的随机数?

bash - 使用 ffmpeg 将 .wav 转换为 .mp3 需要什么编解码器?

Bash 脚本 : automate ffmpeg encoding for mpeg-dash

ffmpeg - 使用 libswscale 从 NV12 转换为 RGB/YUV420P

ffmpeg - 使用 FFMPEG 分割视频时发出警告

ruby-on-rails - ffmpegcarrierwave-video 总是返回 "unknown encoder libfaac"

ffmpeg - 为什么 LZW 压缩中压缩缓冲区需要大于输入缓冲区?