Reputation: 394
I'm tired of searching the solution about this theme. Can anybody help?
Types:
AVOutputFormat* m_outFormat;
AVFormatContext* m_formatContext;
AVCodecContext* m_videoCodecContext;
AVCodec* m_videoCodec;
Code:
avcodec_register_all();
av_register_all();
m_outFormat = av_guess_format(NULL,filePath().toUtf8().constData(),NULL);
//filePath ended like ".mp4"
if (!m_outFormat)
return; //all is fine
avformat_alloc_output_context2(&m_formatContext,NULL,NULL,filePath().toUtf8().constData());
m_formatContext->oformat->video_id = CODEC_ID_H264;
m_outFormat=m_formatContext->oformat;
////////////////////////////////////////////////////////////////////
m_videoCodec=avcodec_find_encoder(CODEC_ID_H264);
m_videoStream = avformat_new_stream(m_formatContext,m_videoCodec);
if (m_videoStream)
return; //all is fine
m_videoCodecContext = avcodec_alloc_context3(m_videoCodec);
m_videoCodecContext->codec_id = CODEC_ID_H264;
m_videoCodecContext->width = 1280;
m_videoCodecContext->height = 720;
m_videoCodecContext->codec_type = AVMEDIA_TYPE_VIDEO;
m_videoCodecContext->pix_fmt = PIX_FMT_YUV420P;
av_codec_open2(M_videoCodecContext,m_videoCodec,NULL);
I'm getting an error: [libx264 @.....] Codec type or id mismathes.
av_codec_open2(..) returned (-22 error). Where I did mistake?More info:av_guess_format(...)
I've got audio_codec = CODEC_ID_H264, video_codec = CODEC_ID_NONE, long_name MP4(MPEG-4 Part 14) in m_outFormat.avformat_alloc_context3(...)
I've got audio_codec_id = video_codec_id = CODEC_ID_NONE in m_formatContext.avcodec_find_encoder(CODEC_ID_H264)
I've got name = "libx264", id = CODEC_ID_MPEG1VIDEO in m_videoCodec.
I can share more info if You can say, what do You exactly need.
Upvotes: 1
Views: 850
Reputation: 394
I've found the answer... It's so stupid...
I had old headers, from old ffmpeg sources, but with the libs from new sources.. So I replaced new headers and all errors has gone! I don't change code above.
Upvotes: 1