[Libav-user] Can't get MPEG4 decoder
Dan Haddix
dan6992 at hotmail.com
Fri Nov 10 01:49:36 EET 2017
I missed the rest of your question... Here is some code I think will help you get on the right track
// First off open the file...
AVFormatContext *pFormatContext;
avformat_open_input(&pFormatContext, sFilename_UTF8, fmt, NULL);
// Next parse the streams...
avformat_find_stream_info(pFormatContext, NULL);
// Next setup the video decoder...
AVCodec *pVideoCodec = avcodec_find_decoder(pFormatContext->streams[0]->codecpar->codec_id);
AVCodecContext *pVideoContext = NULL;
if (m_pVideoCodec)
{
// Allocate a decoding context
pVideoContext = avcodec_alloc_context3(pVideoCodec);
if (avcodec_parameters_to_context(pVideoContext, pFormatContext->streams[0]->codecpar) >= 0)
{
// Open codec
avcodec_open2(pVideoContext, pVideoCodec, NULL) ;
}
}
// Decode the frame from a read
AVPacket avPacket;
av_init_packet(&avPacket);
if (av_read_frame(pFormatContext, &avPacket) == 0)
{
AVFrame *pAVFrameVideo = av_frame_alloc();
if ( avFrame)
{
int ret = avcodec_send_packet(pVideoContext, &avPacket);
if (ret == 0 || (ret == AVERROR_EOF && avPacket.size == 0))
{
if (avcodec_receive_frame(pVideoContext, avFrame) == 0)
{
// avFrame has your decoded frame, do something with it
}
}
}
}
You'll need to do something similar for the audio decoder
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
Dan
________________________________
From: Libav-user <libav-user-bounces at ffmpeg.org> on behalf of Michael IV <explomaster at gmail.com>
Sent: Thursday, November 9, 2017 10:05 AM
To: This list is about using libavcodec, libavformat, libavutil, libavdevice and libavfilter.
Subject: Re: [Libav-user] Can't get MPEG4 decoder
Ok.then why when I configure FFMPEG build to include mp4 demuxer,the after-config report doesn't show mp4?
I do set that name:
--enable-demuxer='mov,h264,mp4,ogg,matroska,wav,flac'
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
with h264 AVC. and
dec = avcodec_find_decoder(dec_ctx->codec_id); //codec_id h264
returns a valid codec. But I have another problem, even though I call avformat_find_stream_info()
I am getting both streams' codecpar uninitialized:
AVCodecParameters* id0= pFormatCtx->streams[0]->codecpar; //here should be AAC props
AVCodecParameters* id1 = pFormatCtx->streams[1]->codecpar; //here should be h264 props
Why that happens?
On Thu, Nov 9, 2017 at 7:56 PM, Dan Haddix <dan6992 at hotmail.com<mailto:dan6992 at hotmail.com>> wrote:
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.
I think you're a little confused on the terminology.
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.
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.
In avlib the MP4 demuxer is "mp4". The MPEG-4 part 2 decoder is "mpeg4", the H.264 decoder is "h264".
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.
Good luck,
Dan
On Nov 9, 2017 at 9:38 AM, <Michael IV<mailto:explomaster at gmail.com>> wrote:
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?
On Thu, Nov 9, 2017 at 7:26 PM, Michael IV <explomaster at gmail.com<mailto:explomaster at gmail.com>> wrote:
And testing the actual codecId of the video stream in the file I am also getting NULL for avcodec_find_decoder:
ret = av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, NULL, 0);
st = pFormatCtx->streams[ret];
AVCodecContext *dec_ctx = NULL;
AVCodec *dec = NULL;
dec_ctx = st->codec;
dec = avcodec_find_decoder(dec_ctx->codec_id);
where ec_ctx->codec_id == AV_CODEC_ID_MPEG4
On Thu, Nov 9, 2017 at 7:22 PM, Michael IV <explomaster at gmail.com<mailto:explomaster at gmail.com>> wrote:
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.
I started to check those because I am getting into trouble in this part:
pFormatCtx = avformat_alloc_context(); //ok
AVDictionary *d = NULL;
av_dict_set(&d, "protocol_whitelist","file", 0); //ok
int ret = avformat_open_input(&pFormatCtx, in_f_name , NULL, &d); //ok
avformat_find_stream_info(pFormatCtx, NULL) ///also ok
But once I get to access the codecpar I hit "access violation reading location:
pFormatCtx->streams[i]->codecpar->codec_type==AVMEDIA_TYPE_VIDEO
Because my codecpar is not initialized. That's what I don't understand here.
On Nov 9, 2017 8:14 PM, "Carl Eugen Hoyos" <ceffmpeg at gmail.com<mailto:ceffmpeg at gmail.com>> wrote:
Hi!
> Am 09.11.2017 um 17:13 schrieb Michael IV <explomaster at gmail.com<mailto:explomaster at gmail.com>>:
>
> Hi All. What maybe a reason that avcodec_find_decoder returns NULL ?
>
> I enabled in my FFMPEG build MOV and h264 demuxer. Configure report clearly
> states that.
>
> But doing this test:
>
> av_register_all();
> avcodec_register_all();
> avformat_network_init();
> AVCodec* h264codc = avcodec_find_decoder_by_name("h264");
This is supposed to work.
> AVCodec* h264codc1 = avcodec_find_decoder_by_name("MOV");
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).
> AVCodec* h264codc3 = avcodec_find_decoder_by_name("MPEG4");
There is codec "mpeg4" but that's not h264.
> AVCodec* h264codc4 = avcodec_find_decoder_by_name("MP4");
See above for mov, although the same demuxer handles mov and mp4.
> AVCodec* h264codc5 = avcodec_find_decoder(AV_CODEC_ID_MPEG4);
Again, this codec exists but it's not h264.
> Only h264codc returns a valid codec.
> The only thing I didn't do during build config was not to enable libx264.
This only means that you have no h264 encoder.
> 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.
Then you don't care about a decoder, you only need a demuxer (and maybe a parser).
Carl Eugen
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org<mailto:Libav-user at ffmpeg.org>
http://ffmpeg.org/mailman/listinfo/libav-user<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>
_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org<mailto:Libav-user at ffmpeg.org>
http://ffmpeg.org/mailman/listinfo/libav-user<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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20171109/27fc6f3e/attachment.html>
More information about the Libav-user
mailing list