-->

Sending Jcodec H264 Encoded RTMP Message to Wowza

2019-08-02 23:52发布

问题:

I am making screen share java based application. I am done with encoding frames into H264 using JCodec java Library. I have Picture data in Byte Buffer. How I will send these encoded frames to Wowza through rtmp client? Can Wowza recognize the H264 encoded frames, Encoded by Jcodec library?

回答1:

Pretty much any of the "flash" media servers will understand h264 data in a stream. You'll need to encode your frames with baseline or main profile and then "package" the encoded bytes into flv streaming format. The first step is creating an AMF video data item, what that means is prefixing and suffixing the h264 encoded byte array based on its "NALU" content; in pseudo code it looks something like this:

if idr 
flv[0] = 0x17 // 0x10 key frame; 0x07 h264 codec id
flv[1] = 0x01 // 0 sequence header; 1 nalu; 2 end of seq
flv[2] = 0 // pres offset
flv[3] = 0 // pres offset
flv[4] = 0 // pres offset
flv[5] = 0 // size
flv[6] = 0 // size cont
flv[7] = 0 // size cont
flv[8] = 0 // size cont

else if coded slice
flv[0] = 0x27
flv[1] = 0x01
flv[2] = 0 // pres offset
flv[3] = 0 // pres offset
flv[4] = 0 // pres offset
flv[5] = 0 // size
flv[6] = 0 // size cont
flv[7] = 0 // size cont
flv[8] = 0 // size cont

else if PPS or SPS
.... skipping this here as its really complicated, this is the h264/AVC configuration data

copy(encoded, 0, flv, 9, encoded.length)

flv[flv.length - 1] = 0

The next step is packaging the AMF video data into an RTMP message. I suggest that you look at flazr or one of the android rtmp libraries for details on this step.

I've got a small example project that takes raw encoded h264 and writes it to an flv here if you want to see how its done.