This article simply share some of the experience of doing HTTP side download on Android platform, hoping to help beginners.
1. Why does the player know how to decode the video file when it is playing, and how to display each frame at what intervals?
Because whether it is MP4, AVI, FLV, MKV or other format of audio and video files, there is a data block called metadata, recording the current file image size, encoding format, frame rate, bitrate and other information, the player can be analyzed metadata to obtain this information.
2. What is the principle of the bottom sowing of thunder?
Thunder in the side of the next broadcast, will not be as usual according to the priority of the number of resources linked to the order of the download, but will first download the data block containing metedata, so that the decoder and display interval to configure the logic, and then ensure that at least one thread in order to obtain/download the data block that will be played, This allows for edge-to-bottom seeding.
3. How do I implement edge-to-bottom playback in Android?
Android Videoview is supported on the edge of the HTTP protocol, only need to transfer the HTTP URL of the video file on the remote HTTP server through Videoview.setvideopath, After start Videoview will directly download the side decoding playback.
However, Videoview supported video format is limited, generally only support MP4, 3GP, AVI format
Therefore, you can also directly through the "HTTP GET" request file download, get the file Metedata, parse out the file encoding, frame rate and other information (such as: MP4 stream, can be through "how to extract and generate MP4 files in Android" This article provides a method for the decoupling of audio and video data, and then the side of the download side into the soft/hard decoder for decoding, finally through the Surfaceview will decode the data display, more complex, equivalent to do their own streaming media player.
4. Pits to be aware of
(1) Not all MP4 files are supported by the HTTP protocol edge, because some MP4 file metadata data block at the end of the file, only after downloading the entire file to successfully parse.
Note: For metadata data block at the end of the file MP4 file, can be converted through FFmpeg Qt-faststart tool, or directly using the following FFMPEG command to transfer metadata to the file header, so as to support side download side play.
Ffmpeg-i input.mp4-movflags FastStart Output.mp4
(2) If the HTTP GET request by the side of the download side decoding playback, you need to note that the real-time audio and video data transmission is very different from the normal file transfer, received a file stream can write disk immediately, But received a frame of audio and video data must be based on the time stamp to determine when the decoder decoding and display, no time, you have to sleep, otherwise, the playback process will be due to network jitter and the phenomenon of the card.
Note: In general, two-frame video time interval = 1000/frame rate
5. Summary
Some of the experience of doing HTTP edge-down on Android is shared here, have any questions or suggestions welcome message or letter [email protected] exchange, or follow my Sina Weibo @ Lu _ June get the latest articles and information.
This article is from the "Shadow Three People" blog, please be sure to keep this source http://ticktick.blog.51cto.com/823160/1713220
Android HTTP side-bottom broadcast