[Libav-user] H264+flv bad video stream

Andy Shaules bowljoman at gmail.com
Fri Jun 21 21:07:10 CEST 2013

On 6/20/2013 4:51 PM, Alex Cohn wrote:
> On 20 Jun 2013 11:13, "Dragos Iordache" <dragoshiordache at gmail.com 
> <mailto:dragoshiordache at gmail.com>> wrote:
> >
> > Hi again,
> >
> > So I tested some more and the stream works ok with .\ffmpeg.exe -i 
> .\test.h264 -c:v copy -f  flv rtmp://live.justin.tv/app/live_**** 
> <http://live.justin.tv/app/live_****>
> > But the stream does not work with my implementation using libffmpeg.
> >
> > I tried different methods for sending the stream with libffmpeg but 
> none worked ok. What I do now:
> >
> > -create an oformat of flv
> > -create a context for flv and filename=rtmp:/...
> > -initialize a stream of h264 codec
> > -write header
> > -encode using stagefright
> > -create a packet
> > -write the packet
> >
> > The test.h264 in the ffmpeg line is created using this method and 
> filename is set to "test.h264" and not a rtmp server, so I think this 
> is ok.
> >
> > The captured frame data differs slightly between the command I run 
> with ffmpeg and my code using libffmpeg. One of the diferences if that 
> the NAL header "00 00 00 01" is not like this in the ffmpeg method.
> Absolutely. FLV uses the AVCC format to store h264 NALUs. See for 
> example an excellent explanation at 
> http://livertmpjavapublisher.blogspot.co.il/2011/06/h264-avcvideopacket.html.
> > What do you think is not right?
> Stagefright encoder produces packets in annex-b format. It could be 
> enough to change their headers to AVCC format to make your rtmp happy.
> > Thanks for your help.
> >
> > Dragos
> Regards,
> Alex
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user


Take the annex-b stream nals,  typically sps,pps,idr,slice,slice......

extract the sps and pps from the stream and create the flv avc config 
packet. For the rest of the frames, the idr and slices. Swap the marker 
bytes for size values, pre-pend pts offset and then wrap with the AMF 
flv audio block header.

I often refer to this java class which transcodes annex-b into AMF flash 
live streams for the red5 server.


Although the raw frame parsing code is old, the beef of the critical 
packets and format of the AMF payload is still valid.

If writing a file, those AMF packets will need to be wrapped with the 
FLV context tag header and trailing size marker, but for rtmp they are 
ready to fly..

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20130621/b3121db4/attachment.html>

More information about the Libav-user mailing list