7

カメラ出力をキャプチャし、libavcodec を使用してビデオを作成しようとしています。これを達成する方法の例として、私はffmpeg muxing exampleを使用しました。

問題は、AVCodecContext のビットレートを 400000 に設定したにもかかわらず、4 秒のビデオのサイズが ~15mb でビットレートが ~30000 kb/s であることです (この値は kb/s ではなくビット/秒であると考えています)。 .

また、コマンド ラインから ffmpeg を使用してビデオを録画しようとしましたが、ビットレートは ~700 kb/s です。

ビットレートが保持されず、結果のファイルが非常に大きくなる理由を知っている人はいますか? コーデック コンテキストを初期化するために使用したコードは次のとおりです。

初期化部分:

avformat_alloc_output_context2(&m_formatContext, NULL, NULL, filename);
outputFormat = m_formatContext->oformat;

codec = avcodec_find_encoder(outputFormat->video_codec);

m_videoStream = avformat_new_stream(m_formatContext, codec);

m_videoStream->id = m_formatContext->nb_streams - 1;

codecContext = m_videoStream->codec;

codecContext->codec_id = outputFormat->video_codec;

codecContext->width = m_videoResolution.width();
codecContext->height = m_videoResolution.height();

int m_bitRate = 400000;
codecContext->bit_rate = m_bitRate;
codecContext->rc_min_rate = m_bitRate;
codecContext->rc_max_rate = m_bitRate;
codecContext->bit_rate_tolerance = 0;

codecContext->time_base.den = 20;
codecContext->time_base.num = 1;

codecContext->pix_fmt = AV_PIX_FMT_YUV422P;

if (m_formatContext->oformat->flags & AVFMT_GLOBALHEADER)
    codecContext->flags |= CODEC_FLAG_GLOBAL_HEADER;
/* open it */
ret = avcodec_open2(codecContext, codec, NULL);

avFrame = avcodec_alloc_frame();

ret = avpicture_alloc(&avPicture, codecContext->pix_fmt, codecContext->width, codecContext->height);

*((AVPicture *)avFrame) = avPicture;

av_dump_format(m_formatContext, 0, filename, 1);

if (!(outputFormat->flags & AVFMT_NOFILE)) {
    ret = avio_open(&m_formatContext->pb, filename, AVIO_FLAG_WRITE);
}

ret = avformat_write_header(m_formatContext, NULL);

if (avFrame)
    avFrame->pts = 0;
4

1 に答える 1