Implementation of cross-platform player based on FFmpeg

Source: Internet
Author: User

Implementation of cross-platform player based on FFmpeg

First, Background introduction

FFmpeg is a super-powerful open source multimedia codec framework that provides a complete solution for recording, converting, and streaming audio and video, including Libavcodec, Libavformat and many more multimedia libraries. FFmpeg is based on the Linux platform and can also run on Android (Linux, you know!). ), Windows, Mac, and other platforms.

How important is FFmpeg? List of our commonly used multimedia processing software: Storm audio, QQ audio and video, KMP (this cow broke AH), format Factory ... Have used the ffmpeg, but they are ffmpeg carved on the stigma: The reason is to transform the open source of things into non-open source to make money!

When it comes to players, don't equate ffmpeg with players, which is what I've focused on in this blog post: ffmpeg processing data We can't see, to see the results of data processing, but also with the help of another set of multimedia processing framework, here is to use surface instead of it.

Figure A

So how do you mix ffmpeg and surface under different platforms? I use the following scheme to achieve:

Linux platform: FFmpeg + SDL.

Android Platform: FFmpeg + surface (JNI injection).

Windows:ffmpeg + D3D.

The above three kinds of platform with me all realized (the code is uploaded to GitHub, welcome everyone to criticize correct). Hard to achieve, personal feeling Android hardest, Linux second, Windows is simpler. I am engaged in the development of Linux platform, according to the reason that Linux derived from Android should not have too much difficulty, here strongly sprayed gfw, you put Google banned also just, Android related resources also banned? Android source, ADT These resources for 10 days and a half months, wasting bloggers I have a lot of youth.

Less gossip, cut to the chase.

Second, FFmpeg + surface (JNI injection)

platform Resources : adt-bundle-windows-x86-20140702, android-ndk-r4b, Libffmpeg, Cygwin.

knowledge : JNI, FFmpeg, Android surface.

1. The Android development environment on Adt-bundle-windows-x86-20140702:windows is comprised of Eclipse, Android SDk, and Android emulator.

2, android-ndk-r4b: Cross compiler, used in the Android development environment to compile C-language cross-compiler.

3, Libffmpeg modified can be compiled by android-ndk-r4b ffmpeg source code.

4, Jni:java call C, C + + technology.

5, Android surface:android display technology.

6. Cygwin: Because the Cross compiler runs on Linux, you need to emulate a Linux environment Cygwin on Windows.

Reference URL :

Http://www.cnblogs.com/bjzhanghao/archive/2012/11/14/2769409.html

(Development resources Download, solved the Android website is the wall inconvenience)

http://blog.csdn.net/buleriver/article/details/26139109

(Java calls C, C + + implementation method)

Http://www.cnblogs.com/android100/p/android-surfaceView.html

(Android Surface Implementation method)

Https://github.com/havlenapetr/FFMpeg

(Super Daniel, FFmpeg, the originator of Android)

http://blog.csdn.net/conowen/article/details/7526398

(for the originator's explanation)

Https://github.com/dongguadan/surfaceDraw

(Demo by Bo Master)

Development steps

1, build the environment.

Beginners do not recommend the use of the original ecological eclipse plus a variety of complex configuration to build the environment, it will only make you lose the fun of learning, direct use of ancillary products adt-bundle-windows-x86 relatively concise. Decompression ready adt-bundle-windows-x86, ndroid-ndk-r4b, install the Cygwin, the project configuration, mainly to configure the cross-compiler (eclipse is not directly compiled C-series, requires an external compiler), 2, 3.

Figure 2

Figure 3

2. Compiling project

You can use the Hello-jni that comes with android-ndk-r4b, or you can use the Surfacedraw (a simple player, which enables playback of the video files in the SD card) based on the HAVLENAPETR clip. Compared to the simplicity of havlenapetr,surfacedraw, there are some complex technologies in C + + and Java that can clearly see the process of Android calling the C + + encapsulated FFmpeg interface.

3. Create and run the simulator

First create the emulator (must be based on API2.2, which will explain why), then run, import the video file to the SD card, run app,4, Figure 5, figure 6.

Figure 4

Figure 5

Figure 6

In fact, the Android platform is built-in multimedia processing API, such as MediaPlayer, in just a few lines of code can be implemented above the entire project function. But the reader can think carefully, if it is so simple, then not anyone can develop a simple mobile version of the Storm video? On the other hand, if the developer wants to play a stream of media with the player, the receiving parameter of this stream is a URL (just like Youku online), not the local video path, MediaPlayer? Of course not. So we need to develop a set of APIs that can meet our needs.

This involves the knowledge of the Android framework layer. Android is simply said to be running on the Linux virtual machine, the people who used the virtual machine know that it is a considerable consumption of resources, in the virtual machine running a complex multimedia processing software, the efficiency imaginable. So how can we improve efficiency? Running the C program on Linux is, of course, the highest efficiency, and is recognized in the industry. So there needs to be a way for Android applications to bypass the virtual layer to directly call the Linux layer interface for processing, this is the essence of JNI technology, but also HAVLENAPETR, surfacedraw implementation principle. MediaPlayer is also used in this technology, but based on the MediaPlayer of multimedia processing capacity, flexibility of course, is not able to meet our needs.

Figure 7

The only pity is that so far the Surfacedraw can only be run on Android 2.X, because the most important two libraries libjniaudio.so, Libjnivideo.so is based on android2.x source code compiled. Android4.x Source based on the compilation of the master still bit compiled through, the main reason is that the android4.x to compile the environment requirements are relatively high. There is time behind the bloggers will be available to the relevant version of Libjniaudio.so, libjnivideo.so.

FFmpeg porting on the Android platform is presented here, and the next article introduces the combination of FFmpeg and SDL on the Linux platform.

Implementation of cross-platform player based on FFmpeg

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.