0

ビデオのみの FLV ファイルを生成しようとしています。

  1. libx264 + ffmpeg
  2. 30fps(固定)
  3. 再生は VLC 2.0.1 と flowplayer を使用して行われます

FLV を再生するとき、フレームレートは 1 秒あたり約 1 フレームのように見えます。以下は、ffmpeg を設定する方法です。

AVOutputFormat* fmtOutput = av_oformat_next(0);
while((0 != fmtOutput) && (0 != strcmp(fmtOutput->name, "flv")))
    fmtOutput = av_oformat_next(fmtOutput);
m_pFmtCtxOutput          = avformat_alloc_context();
m_pFmtCtxOutput->oformat = fmtOutput;

AVStream* pOutVideoStream= av_new_stream(m_pFmtCtxOutput, pInVideoStream->id);
AVCodec*  videoEncoder   = avcodec_find_encoder(CODEC_ID_H264);

pOutVideoStream->codec->width    = 640;
pOutVideoStream->codec->height   = 480;
pOutVideoStream->codec->level    = 30;
pOutVideoStream->codec->pix_fmt  = PIX_FMT_YUV420P;
pOutVideoStream->codec->bit_rate = 3000000;

pOutVideoStream->cur_dts         = 0;
pOutVideoStream->first_dts       = 0;
pOutVideoStream->index           = 0;
pOutVideoStream->avg_frame_rate  = (AVRational){ 30, 1 };
pOutVideoStream->time_base       =
pOutVideoStream->codec->time_base= (AVRational){ 1, 30000 };
pOutVideoStream->codec->gop_size = 30;
%% Some specific libx264 settings %%
m_dVideoStep                     = 1000;// packet dts/pts is incremented by this amount each frame

pOutVideoStream->codec->flags   |= CODEC_FLAG_GLOBAL_HEADER;
avcodec_open(pOutVideoStream->codec, videoEncoder);

再生フレームレートを除いて、結果のファイルは問題ないようです。
次のことを念頭に置いてください。

  1. pOutVideoStream->avg_frame_rate = (AVRational){ 30, 1 };
  2. pOutVideoStream->time_base = (AVRational){ 1, 30000 };
  3. pOutVideoStream->codec->time_base= (AVRational){ 1, 30000 };
  4. フレームごとに、dts/pts を 1000 ずつ増やします

ここで何が間違っていますか?ファイルの再生が途切れる ( ~1 fps ) のはなぜですか?

どんな助けでも大歓迎です。

ソフィンのナダブ

4

1 に答える 1

0

flv muxer コードのステップ実行 デバッガーを使用して、ffmpeg 実装がミリ秒以外の解像度の PTS、つまり time_base = (AVRational){ 1, 1000 } をサポートすることを発見しました。

また、flv マルチプレクサがフレームレートを適切に解決するには、「AVStream::r_frame_rate」を設定する必要があります。

于 2012-03-25T07:34:35.340 に答える