[FFmpeg-devel] Splitting an h.264 encoded stream in NALs?

Måns Rullgård mans
Sat Nov 10 13:23:47 CET 2007


Luca Abeni <lucabe72 at email.it> writes:

> Hi Luca,
>
> On Sat, 2007-11-10 at 13:05 +0100, Luca Barbato wrote:
> [...]
>> > I have an H.264 stream (from linbx264), and I need to split it in NALs
>> > (yes, I am working on H.264 support in the RTP muxer :).
>> > I wrote my own code for this (and it seems to work well), but I am
>> > wondering if we have some function in libavcodec that I can call for
>> > this (I had a look at libavcodec/h264.c, and it does not seem to call
>> > ff_find_start_code()).
>> 
>> it is a bit convoluted inside that file, you may just take the
>> h264_parse from feng and change the parameters to fit ffmpeg.
>> 
>> http://live.polito.it/gitweb/?p=feng.git;a=blob;f=mediathread/h264.c;h=1db11b264e7dfc051bca1b45b2a2a7b3ab8bbef3;hb=HEAD
>
> Thanks; I just had a look at it. It seems that your parser is using the
> same code as libavcodec/h264.c (and my one is similar to it, too ;-)
>
> BTW, I have a question about it: isn't the NAL start code composed by 4
> bytes: "0x00 0x00 0x00 0x01"? It looks like your code is searching for a
> 3-bytes start code?

A NAL start code can be 3 or 4 bytes.  A few words from the spec:

  When any of the following conditions are fulfilled, the zero_byte
  syntax element shall be present.

  - the nal_unit_type within the nal_unit( ) is equal to 7 (sequence
    parameter set) or 8 (picture parameter set)

  - the byte stream NAL unit syntax structure contains the first NAL
    unit of an access unit in decoding order, as specified by subclause
    7.4.1.2.3.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list