0

我正在尝试生成仅视频的 FLV 文件,我正在使用:

  1. libx264 + ffmpeg
  2. 30 fps(固定)
  3. 使用 VLC 2.0.1 和 flowplayer 完成播放

播放 FLV 时,帧速率似乎约为每秒 1 帧,以下是我 cfg 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

Stepping through the flv muxer code With a debugger, I have found the ffmpeg implementation to support PTS of a resolution no other than msec, that is, having time_base = (AVRational){ 1, 1000 }.

Also, 'AVStream::r_frame_rate' must be set in order for the flv muxer to properly resolve the frame-rate.

于 2012-03-25T07:34:35.340 回答