Кодирование видео только FLV

Я пытаюсь создать FLV-файл только для видео, я использую:

  1. libx264 + ffmpeg
  2. 30 кадров в секунду (фиксировано)
  3. воспроизведение осуществляется с помощью VLC 2.0.1 и flowplayer

При воспроизведении FLV частота кадров кажется ~ 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 кадр/с)?

Любая помощь будет оценена.

Надав в Софине


person NadavRub    schedule 24.03.2012    source источник


Ответы (1)


Пошаговое выполнение кода мультиплексора flv С помощью отладчика я обнаружил, что реализация ffmpeg поддерживает PTS с разрешением, не отличным от msec, то есть с time_base = (AVRational){ 1, 1000 }.

Также , 'AVStream::r_frame_rate' должен быть установлен для того, чтобы мультиплексор flv правильно определял частоту кадров.

person NadavRub    schedule 25.03.2012