[Red5devs] RTMP Protocol and timestamp

Posco, TSO Fung Po posco.tso at gmail.com
Wed Aug 27 23:49:43 PDT 2008


Hi Falasca,

Sorry that I was out of town for a few days. I am not familiar with
RTMP protocol here I focus on discussing FLV headers.

The first frame of a FLV stream is always a metadata which begins with
'F' (0x46), 'L' (0x4C), 'V' (0x56) and other header informations.
and all following audio/video frames are treated as frame body which
complies following format:
TagType (1 byte) (18 for metadata, 8 for audio, 9 for video)
DataSize(3 bytess) (Length of data, excluding header's length)
TimeStamp (3 bytes) (you need to put your time stamp here)
TimestampExtended (1 byte, i've never used this field :) )
streamID(1 byte) ( always 0)
data (Audo/video data)

Becareful that audio/video data come with their own header too, you
can check it out from a flv specification.

So neither byHeader1 nor byHeader2 looks like a valid FLV header (or
they are RTMP headers? I have no idea about RTMP headers)

Cheers,
Posco



On Fri, Aug 22, 2008 at 2:01 AM, Stefano Falasca <fala70 at alice.it> wrote:
> Hi Posco thanks for your answer, Interesting to found somebody about this
> argument.
>
> I am not using a java app. I builded a my c# app and studied all protocol
> RTMP.
>
> I am already using audio and video data type packet. I use this header
> packet:
>
> byte[] byHeader1 = {0x06, 0x00, 0x16, 0x2a, 0x00, (byte)((iSizeL >> 8) &
> 0xff),     (byte)(iSizeL & 0xFF), 0x09, 0x01, 0x00, 0x00, 0x00, 0x12};
>
> byte[] byHeader2 = {0x46, 0x00, 0x00, 0xE4, 0x00, (byte)((iSizeL >> 8) &
> 0xff), (byte)(iSizeL & 0xFF), 0x09,0x22};
>
> byHeader1 used how first frame of stream, byHeader2 for other frames. After
> the header I send the data...iSizeL is the size frame data. But where must I
> insert the timestamp ???
>
>
>
>
> Posco, TSO Fung Po ha scritto: in data 21/08/2008 17.59:
>
> Hi Stefano,
>
> I did a similar java app, and I solved the problem by using AudioData
> and VideoData type provided by Red5. The following few lines are about
> constructing a VideoData packet that is to be published to the server:
>
>   RTMPMessage msg = new RTMPMessage();
>
>   //content is a byte array carry video content (encoded by ffmpeg)
>   ByteBuffer frame=ByteBuffer.wrap(content);
>   VideoData videoData = new VideoData(frame);
>
>   videoData.setTimestamp(PUT YOUR TIME STAMP REF HERE);
>   msg.setBody(videoData);
>
>  //the VideoData is ready, publish it
>   publishStreamData(streamId, msg);
>
> Hope this helps.
>
> Cheers,
> Posco
>
>
> On Thu, Aug 21, 2008 at 9:40 PM, Stefano Falasca <fala70 at alice.it> wrote:
>
>
> I posted a few week ago a problem about audio video sync using RTMP
> protocol for a custom live application. Mainly my app open a connection
> socket on 1935 port establish the conection with red5 and push audio and
> video frames. My problem is that I didn't understand how pass to red5
> the timestamp for a correct audio and video sync. The actul protocol
> provide to send audio and video frames without any information about
> timestamp frames.
>
> looking here:
> http://osflash.org/documentation/rtmp?s=rtmp%20timestamp
>
> I implemented 0x8 and 0x9 data type. I suppose that I need to implement
> 0x16 datatype. It should be similar a flv packet file format. I tried to
> implement 0x16 datatype into rtmp protocol, but red5 disconnected the
> connection..
>
> That my code for 0x16 datatype, video frame:
>
>        void SendDataStreamVideo(byte[] byBuffer, int iLen, byte
> bKeyFrame,
> int iTimeStamp){
>
>                .
>                .
>                .
>
>            int iSizeL = 12 + iLen + 4;
>             byte[] byFlv = new byte[iSizeL];
>            int iSizeData=iLen+1;
>             byFlv[0] = 0x09;
>             byFlv[1] = (byte)((iSizeData >> 16) & 0xff);
>             byFlv[2] = (byte)((iSizeData >> 8) & 0xff);
>             byFlv[3] = (byte)(iSizeData & 0xFF);
>             byFlv[4] = (byte)((iTimeStamp >> 16) & 0xff);
>             byFlv[5] = (byte)((iTimeStamp >> 8) & 0xff);
>             byFlv[6] = (byte)(iTimeStamp & 0xFF);
>             byFlv[7] = byFlv[8] = byFlv[9] = byFlv[10] = 0;
>             if (bKeyFrame == 0 && iFirstByte != 0)
>                 byFlv[11] = 0x22;
>             else
>             {
>                 byFlv[11] = 0x12;
>                 iFirstByte++;
>             }
>             Array.Copy(byBuffer, 0, byFlv, 12, iLen);
>             int iFoot = iLen + 11;
>             byFlv[12 + iLen] = (byte)((iFoot >> 24) & 0xff);
>             byFlv[12 + iLen + 1] = (byte)((iFoot >> 16) & 0xff);
>             byFlv[12 + iLen + 2] = (byte)((iFoot >> 8) & 0xff);
>             byFlv[12 + iLen + 3] = (byte)(iFoot & 0xFF);
>
>
>             byte[] byHeader1 = {
>                                0x06, 0x00, 0x16, 0x2a, 0x00, (byte)((iSizeL
>>> 8) &
> 0xff), (byte)(iSizeL & 0xFF), 0x16,
>                                0x01, 0x00, 0x00, 0x00};
>             byte[] byHeader2 = {
>                                0x46, 0x00, 0x00, 0xE4, 0x00, (byte)((iSizeL
>>> 8) &
> 0xff), (byte)(iSizeL & 0xFF), 0x16};
>
>             if (!bFirstHeaderSent)
>             {   bFirstHeaderSent = true;
>                 m_sock.Send(byHeader1, 12, 0);
>             }
>             else
>                 m_sock.Send(byHeader2, 8, 0);
>
>             Array.Copy(byFlv, byBuffer, iSizeL);
>             iLen = iSizeL;
>
>
> byBuffer will be sent to red5 with a chunck byte each 128.
>
> thanks in advance.
>
>
>
>
>
>
> _______________________________________________
> Red5devs mailing list
> Red5devs at osflash.org
> http://osflash.org/mailman/listinfo/red5devs_osflash.org
>
>
>
> _______________________________________________
> Red5devs mailing list
> Red5devs at osflash.org
> http://osflash.org/mailman/listinfo/red5devs_osflash.org
>
>
>
> --
> Stefano Falasca
>
> _______________________________________________
> Red5devs mailing list
> Red5devs at osflash.org
> http://osflash.org/mailman/listinfo/red5devs_osflash.org
>
>



More information about the Red5devs mailing list