5
votes

I have an issue with FLV stream generating. I've developed DVR system, an it should be able to stream video in FLV format (to play it on Actionscript NetStream). I receive video from encoder in raw H264 NAL units (0x00 0x00 0x00 0x01 ), also I can recognize is encoded frame IDR or non-IDR.

My solution to create FLV stream (based on Adobe spec: Video File Format Specification Version 10) was:

  1. wait for IDR frame;
  2. put FLV header
  3. put PrevTagSize(0)
  4. put FLV tag with video tag VIDEODATA with AVCVIDEODATA
  5. put PrevTagSize
  6. repeat steps 4,5 till end of streaming.

Stream looks good, and can be playable by ffplay, mplayer, vlc, etc. But not played by player based on Actionscript NetStream.

So, I've get raw h264 data and convert it to FLV using ffmpeg:

ffmpeg -f h264 -i d1.h264 -vcodec copy -f flv d1.flv

and try to compate both flv's my and ffmpeg's.

First of all I see that ffmpeg adds AVC sequence header, immediately after FLV header. I've started to do the same, but NetStream still not support my stream, and also another players ceased to play it.

Ok, then I've continue to compare flv's. Now I see that NAL unit headers in ffmpeg's coded FLV a bit changed, but I can't understand what the meaning of the changes. I read many specs, but nothing helpful. Did anybody can clarify me this?

Fo example my NAL units looks so: 00 00 00 01 XX XX ... - for all units

FFmpeg NALs: 00 00 [14 BA] 61 9A ... - non IDR (two bytes variable) 00 00 [7A 02] 65 88 ... - IDR (two bytes variable) 00 00 00 40 06 05 ... - SEI

Is there added some counter or anything else?

Will be happy to see any ideas, links, etc.

2
I'm working on a FLV muxer too and wondering how to store the x264_nal_t* data I got when encoding using x264_encoder_encode. Did you get your stream working? can you explain your approach a bit?pollux

2 Answers

3
votes

Try to use following command to do the work:

ffmpeg -y -i test.flv -vcodec copy -vbsf h264_mp4toannexb test.h264

You will got a vlc playable .h264 file, all NAL is begin with 00 00 00 01.

2
votes

There are two common H.264 bitstream packing formats.

  1. Annex B contains start codes: 00 00 01
  2. MP4 is length prefixed XX XX XX XX

You are creating annex B but it seems like you need mp4 packing format (length prefixed) for FLV. You have to remove (00) 00 00 01 and add the length as prefix.