How to get x264 SPS / PPS parameter out of AVCodecContext?

For the developers that use FFmpeg in their software.
Post Reply
technique
Posts: 14
Joined: Wed May 09, 2012 2:20 pm

How to get x264 SPS / PPS parameter out of AVCodecContext?

Post by technique » Tue May 29, 2012 9:11 am

Hey its me again!

While i am still failing in writing a encoded x264 video to file (as you can read here > http://ffmpeg.zeranoe.com/forum/viewtop ... f=15&t=534) i get another problem on another task. My goal is to stream (luckily dont need to write a frame) the encoded videoframes via RTSP (live555) to a android phone. For VLC this is working so far without the header-information (sps / pps) but on android the media player dont accept my videostream.

Since i didnt know how to set up a working x264 configuration (in c-code on up-to-date build) without deprecated header files which i cant translate into newer ones i m using a default codec-configuration via avcodec_get_context_defaults3.

This is where it becomes complicated: i need the sps and pps from the default codec configurations in a byte array (so something like uint8_t* spsData, int spsSize, uint8_t* ppsData, int ppsSize).

One way i figured out is to parse the AVCodecContext.extradata into that informations using weired and ugly functions like that (http://cgit.lscube.org/cgit.cgi/feng/tr ... 264.c#n218). I guess i will never get into that.

So my question: is there a easy - or better 'easier' way to get those informations?

technique
Posts: 14
Joined: Wed May 09, 2012 2:20 pm

Re: How to get x264 SPS / PPS parameter out of AVCodecContex

Post by technique » Tue May 29, 2012 1:08 pm

technique wrote: I guess i will never get into that.
I was wrong!
Indeed i didnt get any line in detail but its running (had to replace the glib functions e.g. libav's base64.h helping a lot).

Another problem appears -> codecContext.extradata_size == 0. So what the heck!?! No extradata on x264 encoding ... but i read many discussions where it is recommended to use extradata for header generation e.g. sps pps data.

I make desperate efforts but i cant get into that #!%** ##"!. :evil:

Ah.... i need a break - back in few hours hoping anyone give his two cents helping me out!

rogerdpack
Posts: 1878
Joined: Fri Aug 05, 2011 9:56 pm

Re: How to get x264 SPS / PPS parameter out of AVCodecContex

Post by rogerdpack » Tue May 29, 2012 2:25 pm

I might ask on the libav user group http://ffmpeg.org/contact.html

technique
Posts: 14
Joined: Wed May 09, 2012 2:20 pm

Re: How to get x264 SPS / PPS parameter out of AVCodecContex

Post by technique » Thu May 31, 2012 3:38 pm

I finally got it.
I added c->flags |= CODEC_FLAG_GLOBAL_HEADER; for my video codec configuration and now AVCodecContext.extradata.size is bigger than 0.

There is a nice function called av_sdp_create() which returns a sdp-header containing a ""sprop-parameter-sets=XXX" string beside other configurations.
Live555 itself is able to parse a "sprop-parameter-sets" bytestream to the needed sps and pps informations.

So thats all! Its done!
Thank you for helping me!
Best regards,
technique

machang
Posts: 1
Joined: Thu Jun 20, 2013 8:31 pm

Re: How to get x264 SPS / PPS parameter out of AVCodecContex

Post by machang » Thu Jun 20, 2013 8:41 pm

How exactly were you able to extract the x264 SPS/PPS parameters from the encoded video?

Post Reply