Android video encoding h263 mp4v h264

Source: Internet
Author: User

In the previous article, I talked about how to use JNI for h264 encoding, but the efficiency is not very practical.

After several days of hard work, refer to the real-time coding problem of Android with reference to http://www.javaeye.com/problems/27244.

 

Two important classes: mediarecorder parcelfiledescriptor

 

Mediarecorder is a collection encoding class provided by Android, while parcelfiledescriptor is a class that uses Socket to implement setoutputfile.

 

During the test of the liuzongan program, we found that the other guy has implemented most of the functions we need. The only thing we need to deal with is the server-side program.

 

Here I will first guess the process of mediarecorder writing files.

 

1. mediarecorder writes a Fixed Header. It is estimated that the placeholder value is 00 H (The placeholder length seems to be related to the encoder used)

Insert 00 00 00 08 6D 64 61 74 (mdat box)

2. Start encoding and add none of the frames after encoding to the file. We can see that 00 00 80 is missing. The comrades who know h263 must be familiar with it, is it the 263 video logo!

(If there is audio data, it will be intertwined with the video data, but our goal is to encode the video stream in real time and do not need to process the audio, therefore, when initializing mediarecorder, I do not want mediarecorder. setaudiosource, so there is no audio data .)

 

3. Complete the capture. Mediarecorder should return to the file header to fill the file header. However, because it is not a real file relationship, it cannot be returned to the header. Therefore, the file header is appended to the end of the file. This is the answer to the question raised by liuzongan.

 

This is the length of the mdat box at the beginning of the file, used to replace 00 00 08.

 

 

This is the header of the 3GP file, used to replace the placeholder at the beginning.

 

 

4 Finally, mediarecorder adds the moov box of the 3GP file, which is already part of the 3GP media index. The specific content is not very important to us. For more information, see http://www.cnitblog.com/zouzheng/archive/2007/04/04/25155.html.

 

 

 

 

 

 

 

 

Next, let's start with the Implementation content.

 

In fact, with the above description, we should be able to think that what we want to achieve is actually video frame splitting ..

 

How to process h263 on the server

 

1. Find the mdat string, and the subsequent data is the video data we want,

 

2. Search for the 00 00 80 mark in the stream. Each one starts with a frame of data.

 

 

For h264 and MPEG4, data needs to be pre-collected once. This is because the related decoding parameters of mp4v are in ESDs box, And ESDs box is written after the collection is complete, therefore, for our program, we need to encode the relevant decoding parameters of mp4v at a time, and then use the same parameters for collection, so that we can get the original mp4v stream.

 

 

The same as h264, but it exists in the avcc box.

 

 

 

 

 

 

Tip: http://blog.csdn.net/zblue78/article/details/6078040

Related Article

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.