【问题标题】:vlc pays video created with libavcodec at wrong frame ratevlc 以错误的帧速率支付使用 libavcodec 创建的视频
【发布时间】:2013-12-17 19:22:50
【问题描述】:

作为测试,我想创建一个帧速率为 1 fps 的视频。当我像这样创建它时,vlc 仍然以 25 fps 的速度播放。有人有想法吗?

AVFormatContext* formatContext;
avformat_alloc_output_context2(&formatContext, NULL, NULL, "test.h264");
AVOutputFormat* outputFormat = formatContext->oformat;

AVStream* videoStream = av_new_stream(formatContext, 0);
AVCodecContext* ctx  = videoStream->codec;

ctx->codec_type = AVMEDIA_TYPE_VIDEO;  
ctx->codec_id = CODEC_ID_H264;    

ctx->bit_rate = 500*1000;
ctx->bit_rate_tolerance = 0;
ctx->width = w;
ctx->height = h;
ctx->pix_fmt = AV_PIX_FMT_YUV420P;
ctx->time_base.den = 1;//25;
ctx->time_base.num = 1;

【问题讨论】:

  • ffmpeg -i 显示文件的帧率是多少? vlc 怎么样?

标签: h.264 vlc libavcodec


【解决方案1】:

这是一个老问题,但我希望它可以帮助其他有同样问题的人

AVStream 有一个明确的time_base,它是由复用器根据容器设置的。 如AVStream.time_base 评论所述:

复用器可以使用用户提供的值 AVCodecContext.time_base 作为提示。

您需要使用av_rescale_q() 将您的RAW FRAME pts 设置为正确的值:

/* AVFrame* */ raw_frame->pts = av_rescale_q(my_pts, ctx->time_base, videoStream->time_base);
.
.
.
/* AVPacket pkt; */
avcodec_encode_video2(ctx, pkt, &got_packet);
.
.
.
av_write_frame(formatContext, &pkt);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 2012-11-12
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 2013-10-16
    相关资源
    最近更新 更多