How to create a FLV stream from raw h264 that can be played by ActionScript NetStream?

I have a problem with the FLV stream. I developed a DVR system, it should be able to transmit video in FLV format (to play it in ActionScript NetStream). I receive video from the encoder in raw NAL H264 units (0x00 0x00 0x00 0x01), I can also recognize the encoded frame IDR or non-IDR.

My decision is to create a FLV stream (based on the Adobe specification: video file format specification version 10):

  • waiting for an IDR frame;
  • add flv header
  • Add PrevTagSize (0)
  • Put FLV tag with VIDEODATA video tag with AVCVIDEODATA
  • install PrevTagSize
  • Repeat steps 4.5 until the end of the streaming.

The stream looks good and can be played using ffplay, mplayer, vlc, etc. But it is not played by a player based on ActionScript NetStream.

So, I get the 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 compile both flv my and ffmpeg.

First of all, I see that ffmpeg adds the AVC sequence header right after the FLV header. I started to do the same, but NetStream still does not support my stream, and other players also stopped playing it.

OK, then I keep comparing flv. Now I see that the headers of the NAL blocks in ffmpeg encoded FLV have changed a bit, but I cannot understand what the meaning of the changes is. I read a lot of specs but nothing useful. Can anyone clarify this for me?

, NAL : 00 00 00 01 XX XX... -

FFmpeg NAL: 00 00 [14 BA] 61 9A... - IDR ( ) 00 00 [7A 02] 65 88... - IDR ( ) 00 00 00 40 06 05... - SEI

- - ?

, ..

+5
2

H.264.

  • B : 00 00 01
  • MP4 - XX XX XX XX

B, , mp4 ( ) FLV. (00) 00 00 01 .

+1

:

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

vlc- .h264, NAL 00 00 00 01.

+3

All Articles