[Libav-user] Getting SPS and PPS-information from x264 encoding

Christian Brümmer christian.bruemmer at gmx.de
Thu May 31 15:51:00 CEST 2012


Am 30.05.2012 12:44, schrieb Christian Brümmer:
> Am 30.05.2012 04:07, schrieb Kalileo:
>> On May 29, 2012, at 20:26 , Christian Brümmer wrote:
>>
>>> "Cant be that hard - or?"
>>>
>>> Okay now im pretty sure it is:
>>>
>>> I read AVCodecContex.extradata contains the informations i need. For decoding i used that code ->  http://cgit.lscube.org/cgit.cgi/feng/tree/src/media/parser/h264.c#n218  - in a slightly modified way (replaced glib functions with e.g. libavs base64.h). Finally the decoding stuff is running - BUT...
>>>
>>> my AVCodecContext.extradata_size == 0<- what the heck?!? So no data for decoding and really no idea left how to get those informations.... WHAA!
>>>
>>> I make desperate efforts but i cant get into that...
>>>
>>> At least i need another hint. Im not asking for complete solution - its enough to know roughly the right way!
>> > From what I think I understood extradata contains what you expect when your source is a video format with a global header.
>>
>> What's the source format you use for your tests?
>>
>>
>> _______________________________________________
>> Libav-user mailing list
>> Libav-user at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/libav-user
>>
> I create dummy images (should be replaced later on) and encoding them 
> to x264 frames. Further i stream those images via rtsp which is 
> working on VLC but not on android and i thinks its a stream 
> configuration problem.
>
> When should extradata be filled? In my text a dont encode a frame 
> before i try to get the sps pps infos out of extradata. I may have to 
> call a special function or encode a frame or header before?
>
> So my source format is:
>
>     codec = avcodec_find_encoder(c->codec_id);
>     if(!codec)
>     {
>         std::cout << "Codec not found." << std::endl;
>         std::cin.get();std::cin.get();exit(1);
>     }
>
> *if(avcodec_get_context_defaults3 (c, codec) < 0) // cause i dont know 
> a working x264 configuration without deprecated flags *
>     {
>         std::cout << "Cannot get default codec context! \n" << std::endl;
>         std::cin.get();
>         exit(1);
>     }
>
> and
>
>     codec = stream->codec;
>     codec->codec_id = codecID;
>     codec->codec_type = AVMEDIA_TYPE_VIDEO;
>     codec->bit_rate = mParameters.mBitRate;
>     codec->width = mParameters.mWidth;
>     codec->height = mParameters.mHeight;
>     codec->time_base.den = mParameters.mFrameRate;
>     codec->time_base.num = 1;
>     codec->gop_size = mParameters.mFrameRate;
>     codec->pix_fmt = PIXEL_FORMAT;
>     codec->b_frame_strategy = 0;
>     codec->level = 12;
>     if(codec->codec_id == CODEC_ID_MPEG2VIDEO)
>         codec->max_b_frames = 2; // for testing, B frames
>
>     if(codec->codec_id == CODEC_ID_MPEG1VIDEO)
>         codec->mb_decision = 2;
>
>     if(context->oformat->flags & AVFMT_GLOBALHEADER)
>         codec->flags |= CODEC_FLAG_GLOBAL_HEADER;
>
> where mParamters are:
>
>   imLiveStreamParameters param;
>   param.mBitRate = 4000;
>   param.mCodec = "x264";
>   param.mFrameRate = 24;
>   param.mHeight = 240;
>   param.mWidth = 320;
>
> Thank you for your reply!
>
>
>
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user
I figured out that if i add  c->flags |= CODEC_FLAG_GLOBAL_HEADER; for 
my video codec configuration AVCodecContext.extradata.size is bigger 
than 0.
Whats a reason for dont using global headers?

Further i tried the av_sdp_create function again and now i get a string 
containing "sprop-parameter-sets". My rtsp server accept the sdp string 
but the vlc cant play my stream. But i will ask the live555 mailing list 
for that!

Are there other aspects i have to consider using global header with x264 
encoding (other configurations)?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120531/ea5e62ec/attachment.html>


More information about the Libav-user mailing list