Push the PA a7l live video to rtmp server (1)

Source: Internet
Author: User

Use librtmp for H264 and AAC live

(ext: http://www.codeman.net/2014/01/439.html)

1. Frame Division 1.1 H. Frames

For H. 00 00 00 01 or 00 00 01 for each frame.

For example, the following H264 file fragment this packet three frame data

E0 9F 96 10 00 (C0)
In the F1 2A 00 00 00 01
3C (CE) 5D DC E9 BD
E6 D9 B7 2C D8 D9 EE EF ...

The first frame is the xx-C0-DA-E0-9F, which was F1 2A.
The second frame is xx 3C 80
The third frame is the FF FF 5D DC E9 BD E6 D9 B7 2C D8 D9 EE EF.

The frame types are:
Nal_slice = 1
NAL_SLICE_DPA = 2
NAL_SLICE_DPB = 3
NAL_SLICE_DPC = 4
NAL_SLICE_IDR = 5
Nal_sei = 6
Nal_sps = 7
Nal_pps = 8
Nal_aud = 9
Nal_filler = 12,

We only need to know four frame types when we send rtmp data, and other types I have to class as non-keyframe.
respectively is
Nal_sps (7), SPS frame
Nal_pps (8), PPS frame
NAL_SLICE_IDR (5), keyframe
Nal_slice (1) Non-keyframe

The way the frame type is judged to be the lower four bits of the first byte after the interface character.
The frame type for the first frame is: 0x67 & 0x1F = 7, which is an SPS frame
The frame type for the second frame is: 0x68 & 0x1F = 8, which is a PPS frame
The frame type for the third frame is: 0x06 & 0x1F = 6, which is an SEI frame

The above is the use of frame qualifiers to divide frames, and to determine the type of each frame.

Note: If the image is compressed into a H264 frame, we do not have to frame, because each compressed output is clear the size of the frame (including the qualifier), each time the result of the compression may be multi-frame function. A specific discussion will be given.

1.2 AAC Frames

For AAC frames It is defined as FF F1

I do not have an example here, you can see the following frame structure by looking at the AAC binary file.
FF F1 9F FD DE (6C) 32 38 00 00 42 15 95....

Note: For AAC, the first 7 bytes of each frame are the description of the frame, that is, the AAC's naked data is removed from the previous 7 bytes, and we want to remove the 7 bytes when we send rtmp. Similarly, if we are sending rtmp on one side of the compression, we also do not need to define frames, because the output of LIBFAAC each time the compression is complete is a complete frame data, we only need to package the frame to send.

As described above, if we just compress one side to send the compression results to the RTMP server, then we can not define the frame, if we are sending H264 and AAC files, then we need to define the frame.

2. Encoding information for video and audio

If we simply send the compressed data package to the RTMP server, then the RTMP server is not able to decode and play the data, before we send the encoded information of the audio and video to the RTMP server. Many people may be struggling to find the following three coding parameters. In fact, it is very simple to want to get.

2.1 (H264) SPS

For H264, the SPS is the first frame after encoding. If you are reading the H264 file, the length of the data between the first frame qualifier and the second frame qualifier is 4.

2.2 (H264) PPS

For H264, PPS is the second frame after encoding. If you are reading the H264 file, it is the data between the second frame qualifier and the third frame qualifier, and the length is not fixed.

2.3 (AAC) Audiodecoderspecificinfo

This is a length of 2 bytes, which can be obtained by calculating or calling functions.
Recommended by calling Faacencgetdecoderspecificinfo (Fh,&spec,&len);
In general, dual channel 44100 sampling, this value is 0x1210

Push the PA a7l live video to rtmp server (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.