2012-03-24 120 views
0

我想生成的視頻只有FLV文件,我使用:視頻編碼只FLV

  1. libx264 + ffmpeg的
  2. 使用VLC 2.0.1
  3. 30 FPS(固定)
  4. 播放完成和的Flowplayer

當播放幀速率似乎每秒〜1幀中的FLV,以下是這樣我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. 對於每一幀我增加了1000

的DTS/PTS我在做什麼錯在這裏?爲什麼文件播放起伏不定(〜1 fps)?

任何幫助將不勝感激。

Nadav在Sophin

回答

0

通過FLV複用器代碼與調試器步進,我已發現了FFMPEG實施到支持的分辨率不大於毫秒其他的PTS,即,具有基time_base =(AVRational){1, 1000}。

此外,必須設置'AVStream :: r_frame_rate'才能讓flv複用器正確解析幀速率。

+0

1/1000是flv格式的限制。 – szatmary 2013-07-13 00:07:21