<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>I missed the rest of your question... Here is some code I think will help you get on the right track</p>
<p><br>
</p>
<p>// First off open the file...</p>
<p><span>AVFormatContext *pFormatContext;</span><br>
<span>avformat_open_input(&pFormatContext, sFilename_UTF8, fmt, NULL);</span></p>
<p><span><br>
</span></p>
<p><span>// Next parse the streams...</span></p>
<p><span><span><span>avformat_find_stream_info(pFormatContext, NULL);</span></span><br>
</span></p>
<p><span><br>
</span></p>
<p><span>// Next setup the video decoder...</span></p>
<p><span></span></p>
<div><span>AVCodec</span> *pVideoCodec = avcodec_find_decoder(<span>pFormatContext</span><span>->streams[0]->codecpar</span>->codec_id);</div>
<div>
<div><span>AVCodecContext *</span>pVideoContext = NULL;</div>
if (m_pVideoCodec)<br>
{<br>
// Allocate a decoding context<br>
<span>pVideoContext = </span>avcodec_alloc_context3(pVideoCodec);<br>
if (avcodec_parameters_to_context(pVideoContext, <span>pFormatContext</span><span>->streams[0]->codecpar</span>) >= 0)<br>
{<br>
// Open codec<br>
avcodec_open2(pVideoContext, pVideoCodec, NULL) ;<br>
}<br>
}</div>
<div><br>
</div>
<div>// Decode the frame from a read</div>
<div>
<div>AVPacket avPacket;<br>
av_init_packet(&avPacket);</div>
<br>
</div>
<div><span>if (av_read_frame(pFormatContext, &avPacket) == 0)</span></div>
<div><span>{</span></div>
<div>
<div>
<div> AVFrame *pAVFrameVideo = av_frame_alloc(); <br>
if ( avFrame)<br>
{<br>
int ret = avcodec_send_packet(pVideoContext, &avPacket);<br>
if (ret == 0 || (ret == AVERROR_EOF && avPacket.size == 0))<br>
{<br>
if (avcodec_receive_frame(pVideoContext, avFrame) == 0)</div>
<div> {</div>
<div> // avFrame has your decoded frame, do something with it<br>
</div>
<div> }<br>
}<br>
}</div>
<div>}</div>
<div><br>
</div>
<div>You'll need to do something similar for the audio decoder</div>
<div><br>
</div>
<div>Disclaimer... This code was adapted quickly from fragments of a much bigger project so I might have missed something, but it should give you the gist</div>
<div><br>
</div>
<div>Dan<br>
</div>
<br>
</div>
<br>
</div>
<br>
<p></p>
<p><span><br>
<br>
</span></p>
<br>
<div style="color: rgb(0, 0, 0);">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" color="#000000" face="Calibri, sans-serif"><b>From:</b> Libav-user <libav-user-bounces@ffmpeg.org> on behalf of Michael IV <explomaster@gmail.com><br>
<b>Sent:</b> Thursday, November 9, 2017 10:05 AM<br>
<b>To:</b> This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.<br>
<b>Subject:</b> Re: [Libav-user] Can't get MPEG4 decoder</font>
<div> </div>
</div>
<div>
<div dir="ltr">Ok.then why when I configure FFMPEG build to include mp4 demuxer,the after-config report doesn't show mp4?
<div><br>
</div>
<div>I do set that name:</div>
<div><br>
</div>
<div><b>--enable-demuxer='mov,h264,mp4,ogg,matroska,wav,flac' </b><br>
</div>
<div><b><br>
</b></div>
<div><br>
</div>
<div>Also,right,I was confused with MPEG4 name. In fact I need h264 codec and my initial video was with MPEG4 .Now I tried to use a video encoded </div>
<div>with h264 AVC. and </div>
<div><br>
</div>
<div><br>
</div>
<div>dec = avcodec_find_decoder(dec_ctx->codec_id); //codec_id h264<br>
</div>
<div><br>
</div>
<div>returns a valid codec. But I have another problem, even though I call avformat_find_stream_info()</div>
<div><br>
</div>
<div>I am getting both streams' codecpar uninitialized:</div>
<div><br>
</div>
<div>
<div> AVCodecParameters* id0= pFormatCtx->streams[0]->codecpar; //here should be AAC props </div>
<div><span style="white-space:pre"></span>AVCodecParameters* id1 = pFormatCtx->streams[1]->codecpar; //here should be h264 props</div>
</div>
<div><br>
</div>
<div>Why that happens?</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
</div>
<div class="x_gmail_extra"><br>
<div class="x_gmail_quote">On Thu, Nov 9, 2017 at 7:56 PM, Dan Haddix <span dir="ltr">
<<a href="mailto:dan6992@hotmail.com" target="_blank">dan6992@hotmail.com</a>></span> wrote:<br>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div>
<div id="x_m_4612062319792355717edo-message">
<div></div>
You don't need to enable codecs explicitly when you build ffmpeg unless you want to exclude everything else. Just do a build without any of the enable/disable flags and it will include most of the codecs and muxers by default. </div>
<div id="x_m_4612062319792355717edo-message"><br>
</div>
<div id="x_m_4612062319792355717edo-message">I think you're a little confused on the terminology. </div>
<div id="x_m_4612062319792355717edo-message"><br>
</div>
<div id="x_m_4612062319792355717edo-message">First off "mov" is part of the "mp4" demuxer. It's a slight variation of mp4 tha was developed by Apple before mp4 existed. It's actually what the mp4 specification was built from.</div>
<div id="x_m_4612062319792355717edo-message"><br>
</div>
<div id="x_m_4612062319792355717edo-message">Secondly the MPEG-4 spec actually contains two video codecs. MPEG-4 part 2 is the older one that Divx and Xvid were based on. MPEG-4 part 10 is H.264 (aka AVC) and is what most people think of these days when you
say MPEG-4.</div>
<div id="x_m_4612062319792355717edo-message"><br>
</div>
<div id="x_m_4612062319792355717edo-message">In avlib the MP4 demuxer is "mp4". The MPEG-4 part 2 decoder is "mpeg4", the H.264 decoder is "h264". </div>
<div id="x_m_4612062319792355717edo-message"><br>
</div>
<div id="x_m_4612062319792355717edo-message">A little trick for finding the right name. Look for the code file that you're trying to use, like h264dec.c for H.264 decoder, then scroll all the way to the bottom. There is a little constructor class and one of
the variables is the .name which is what you're looking for. </div>
<div id="x_m_4612062319792355717edo-message"><br>
</div>
<div id="x_m_4612062319792355717edo-message">Good luck,</div>
<div id="x_m_4612062319792355717edo-message">Dan</div>
<div>
<div class="x_h5">
<div id="x_m_4612062319792355717edo-meta"></div>
<div id="x_m_4612062319792355717edo-original">
<div><br>
<br>
<blockquote type="cite" style="margin:1ex 0 0 0; border-left:1px #ccc solid; padding-left:0.5ex">
<div>On Nov 9, 2017 at 9:38 AM, <<a href="mailto:explomaster@gmail.com" target="_blank">Michael IV</a>> wrote:<br>
<br>
</div>
<div>
<div dir="ltr">But now I see in vlc that the MPEG4 codec is actually named "mp4v" .So that's the name I have to specificy in --enable-decoder when doing FFMPEG config?
<div><br>
</div>
</div>
<div class="x_gmail_extra"><br>
<div class="x_gmail_quote">On Thu, Nov 9, 2017 at 7:26 PM, Michael IV <span dir="ltr">
<<a href="mailto:explomaster@gmail.com" target="_blank">explomaster@gmail.com</a>></span> wrote:<br>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">And testing the actual codecId of the video stream in the file I am also getting NULL for avcodec_find_decoder:
<div><br>
</div>
<div>
<div> ret = av_find_best_stream(pFormatCtx<wbr>, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);</div>
<div><span style="white-space:pre-wrap"></span>st = pFormatCtx->streams[ret];</div>
<div><span style="white-space:pre-wrap"></span>AVCodecContext *dec_ctx = NULL;</div>
<div><span style="white-space:pre-wrap"></span>AVCodec *dec = NULL;</div>
<div><span style="white-space:pre-wrap"></span>dec_ctx = st->codec;</div>
<div><span style="white-space:pre-wrap"></span>dec = avcodec_find_decoder(dec_ctx-><wbr>codec_id);</div>
</div>
<div><br>
</div>
<div> <b> where ec_ctx->codec_id == AV_CODEC_ID_MPEG4</b></div>
</div>
<div class="x_m_4612062319792355717HOEnZb">
<div class="x_m_4612062319792355717h5">
<div class="x_gmail_extra"><br>
<div class="x_gmail_quote">On Thu, Nov 9, 2017 at 7:22 PM, Michael IV <span dir="ltr">
<<a href="mailto:explomaster@gmail.com" target="_blank">explomaster@gmail.com</a>></span> wrote:<br>
<blockquote class="x_gmail_quote" style="margin:0 0 0 .8ex; border-left:1px #ccc solid; padding-left:1ex">
<div dir="ltr">
<div dir="auto">Hi, thanks for the input. Now I am confused even more. All I need is to start demuxing an mp4 file. Those codecs test above is not what I do.</div>
<div>I started to check those because I am getting into trouble in this part:</div>
<div><br>
</div>
<div>
<div> pFormatCtx = avformat_alloc_context(); //ok</div>
<div><span style="white-space:pre-wrap"></span>AVDictionary *d = NULL; </div>
<div><span style="white-space:pre-wrap"></span>av_dict_set(&d, "protocol_whitelist","file", 0); //ok<br>
</div>
<div> int ret = avformat_open_input(&pFormatCt<wbr>x, in_f_name , NULL, &d); //ok<br>
</div>
</div>
<div> avformat_find_stream_info(pFo<wbr>rmatCtx, NULL) ///also ok</div>
<div><br>
</div>
<div>But once I get to access the codecpar I hit "access violation reading location:</div>
<div><br>
</div>
<div><b>pFormatCtx->streams[i]->codecp<wbr>ar->codec_type==AVMEDIA_TYPE_V<wbr>IDEO</b><br>
</div>
<div><br>
</div>
<div>Because my <b>codecpar </b>is not initialized. That's what I don't understand here.</div>
<div>
<div class="x_m_4612062319792355717m_1235953485649798123h5">
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div dir="auto"><br>
</div>
<div class="x_gmail_extra"><br>
<div class="x_gmail_quote">On Nov 9, 2017 8:14 PM, "Carl Eugen Hoyos" <<a href="mailto:ceffmpeg@gmail.com" target="_blank">ceffmpeg@gmail.com</a>> wrote:<br type="attribution">
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
Hi!<br>
<br>
> Am 09.11.2017 um 17:13 schrieb Michael IV <<a href="mailto:explomaster@gmail.com" target="_blank">explomaster@gmail.com</a>>:<br>
><br>
> Hi All. What maybe a reason that avcodec_find_decoder returns NULL ?<br>
><br>
> I enabled in my FFMPEG build MOV and h264 demuxer. Configure report clearly<br>
> states that.<br>
><br>
> But doing this test:<br>
><br>
> av_register_all();<br>
> avcodec_register_all();<br>
> avformat_network_init();<br>
> AVCodec* h264codc = avcodec_find_decoder_by_name("<wbr>h264");<br>
<br>
This is supposed to work.<br>
<br>
<br>
> AVCodec* h264codc1 = avcodec_find_decoder_by_name("<wbr>MOV");<br>
<br>
This is not the name of any decoder, mov is a file format, you will find a demuxer (and a muxer) with that name (I think).<br>
<br>
> AVCodec* h264codc3 = avcodec_find_decoder_by_name("<wbr>MPEG4");<br>
<br>
There is codec "mpeg4" but that's not h264.<br>
<br>
> AVCodec* h264codc4 = avcodec_find_decoder_by_name("<wbr>MP4");<br>
<br>
See above for mov, although the same demuxer handles mov and mp4.<br>
<br>
> AVCodec* h264codc5 = avcodec_find_decoder(AV_CODEC_<wbr>ID_MPEG4);<br>
<br>
Again, this codec exists but it's not h264.<br>
<br>
> Only h264codc returns a valid codec.<br>
<br>
<br>
> The only thing I didn't do during build config was not to enable libx264.<br>
<br>
This only means that you have no h264 encoder.<br>
<br>
> May this be the source of the problem? I didn't do that because I just need to demux mp4 movie and get its elementary stream.<br>
<br>
Then you don't care about a decoder, you only need a demuxer (and maybe a parser).<br>
<br>
Carl Eugen<br>
______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fffmpeg.org%2Fmailman%2Flistinfo%2Flibav-user&data=02%7C01%7Cdan6992%40hotmail.com%7Cfb6faa38f00548ee8fc108d52798a8a9%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636458458994105842&sdata=o6jGGddtpys4%2Bnt6m8wvQx3RNDzVptAvSyQojdIlR5g%3D&reserved=0" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/list<wbr>info/libav-user</a><br>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
<br>
______________________________<wbr>_________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a><br>
<a href="https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fffmpeg.org%2Fmailman%2Flistinfo%2Flibav-user&data=02%7C01%7Cdan6992%40hotmail.com%7C8f2e9594098c4d8344b108d5279c79c8%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636458475363544071&sdata=RXCkDyrVkeLyK6M6T0es5iw2oIPrnVbt1cLUp4G9y9U%3D&reserved=0" rel="noreferrer" target="_blank">http://ffmpeg.org/mailman/<wbr>listinfo/libav-user</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>