gpt4 book ai didi

c - .avi 文件的无操作重新混合

转载 作者:行者123 更新时间:2023-12-04 23:18:16 31 4
gpt4 key购买 nike

我想解复用然后复用 .avi 文件而不更改任何内容。
我的程序是这样的(为简洁而编辑):

    AVFormatContext *input_format_context = NULL;
avformat_open_input(
&input_format_context,
input_url,
NULL, // fmt
NULL // options
);

avformat_find_stream_info(input_format_context, NULL);

AVFormatContext *output_format_context = NULL;
avformat_alloc_output_context2(
&output_format_context,
NULL, // oformat
NULL, // format_name
output_url
);

avio_open2(
&output_format_context->pb,
output_url,
AVIO_FLAG_WRITE,
NULL, // int_cb,
NULL // options
);

for (int i = 0; i < input_format_context->nb_streams; i++) {
avformat_new_stream(output_format_context, NULL);

AVStream *input_stream = input_format_context->streams[i];
AVStream *output_stream = output_format_context->streams[i];

AVCodecParameters *params = avcodec_parameters_alloc();

avcodec_parameters_copy(params, input_stream->codecpar);

output_stream->codecpar = params;
}

avformat_write_header(output_format_context, NULL))

AVPacket *input_packet = NULL;
input_packet = av_packet_alloc();
while (!av_read_frame(
input_format_context,
input_packet
)) {
av_write_frame(output_format_context, input_packet);
av_packet_unref(input_packet);
}

av_write_trailer(output_format_context);
问题:
输出文件已创建,但不是接近 10 分钟的视频,而是由大约 3 帧组成的 24 秒幻灯片。
似乎问题是(也许不是唯一的)数据包上缺少 PTS。
当我为每个数据包显式打印它( input_packet->pts )时,它是 -9223372036854775808 .并且还会打印以下警告:
[avi @ 0x562868c6c000] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
那么我该如何“修复我的代码以正确设置时间戳”?

最佳答案

我刚刚找到了解决方案。
我添加了这个:

        output_stream->time_base = input_stream->time_base;
然后,据我所知,它允许视频播放器即时计算 PTS。
但是,这并不会删除警告本身。我知道 .avi 根本没有 PTS,所以这不是一个错误。要摆脱警告,可以在数据包上手动设置 PTS:
        input_packet->pts = calculated_ts;
我想我也应该能够做到:
    output_format_context->oformat->flags |= AVFMT_NOTIMESTAMPS;
但是,我不能这样做:
error: assignment of member ‘flags’ in read-only object
因此,看起来 ffmpeg 即使对于 .avi 也需要 PTS,或者存在错误,或者我仍然做错了什么。

关于c - .avi 文件的无操作重新混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72103357/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com