Linux 仅编码视频FLV
我正在尝试生成仅视频的FLV文件,我正在使用:Linux 仅编码视频FLV,linux,ffmpeg,libx264,Linux,Ffmpeg,Libx264,我正在尝试生成仅视频的FLV文件,我正在使用: libx264+ffmpeg 每秒30帧(固定) 播放是使用VLC2.0.1和flowplayer完成的 播放FLV时,帧速率似乎约为每秒1帧,以下是我播放ffmpeg的方式: AVOutputFormat* fmtOutput = av_oformat_next(0); while((0 != fmtOutput) && (0 != strcmp(fmtOutput->name, "flv"))) fmtOutput
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);
结果文件似乎正常,但播放帧速率除外铭记:
Nadav在Sophin通过一个调试器逐步完成flv muxer代码,我发现ffmpeg实现支持分辨率不超过毫秒的PTS,即,具有time_base=(AVRational){1,1000}。
此外,必须设置“AVStream::r_frame_rate”,以便flv muxer正确解析帧速率