Using Nginx+nginx-rtmp-module+ffmpeg to build a streaming server note (eight)

Source: Internet
Author: User

Part---ffmpeg transplanted to Android

The last few days have been engaged in the FFmpeg Android transplant, my goal is to cross-compile ffmpeg on Linux eventually get can push to the Android directory execution of the FFmpeg executable file.

In order to achieve this goal, to complete the transplant of ffmpeg, I can say that I have searched through almost all the Internet articles, tried the various methods on the Internet, but eventually there are all kinds of errors, it is the egg broke a land!

Just started the test, in the time of the compilation of the small heart also accelerated jumping fear of failure error, to later try more, the failure of the more directly did not feel, thinking about not going through, very calm. To tell the truth, this work is still very complicated and anxious to get angry. I'm not going to be able to make it through the compilation.


Okay, step into the chase ~~~~~~~~~~~~~~~

1, in this specially thank netizens Livingstone, thank him for his patience to help and guidance.

I can't finish compiling the porting today without Livingstone providing the configuration file.

2, through the access to various online tutorials, I found that the ultimate goal of the transplant is to get the. so file, and then put it into the Android project, and then through the various methods of JNI call FFmpeg, the Android application layer above the various methods called FFmpeg to complete a variety of tasks, such as video format conversion.

But my current goal is not set to use JNI to invoke the FFmpeg method to complete the corresponding function, I just want to be able to use the command line in the Android directory can be executed by the FFmpeg executable file can be, JNI packaging after the matter.

According to this goal, I checked a blog post.

FFmpeg porting optimization steps on Android

This article achieves the effect and I want the basic is the same, so I step by step in accordance with his method to do, there has been a mistake, may be my environmental problems or what I finally did not follow his method of success.

Since he achieved the same effect as I wanted, I've changed the configuration file over and over again for a long time or a failure. Have the same needs can refer to this article, feel good to write, maybe you follow his way through it.

3, yesterday afternoon I in the discussion group ffmpeg+live555=h.264 asked this question, the kind Netizen Livingstone once did the similar work, sends me one he once used the configuration file, after I modified the NDK path following build_bin_ Ffmpeg_1.sh:

ndk=/home/wangrui/java/android-ndk-r9dplatform= $NDK/platforms/android-9/arch-arm/prebuilt= $NDK/toolchains/ Arm-linux-androideabi-4.8/prebuilt/linux-x86cpu=armv7-aoptimize_cflags= "-mfloat-abi=softfp-marm-mcpu=cortex-a8 "Prefix=./android/$CPU./configure--target-os=linux--prefix= $PREFIX--enable-cross-compile--arch=arm--e Nable-nonfree--enable-asm--cpu=cortex-a8--cc= $PREBUILT/bin/arm-linux-androideabi-gcc--cross-prefix= $PR ebuilt/bin/arm-linux-androideabi---nm= $PREBUILT/bin/arm-linux-androideabi-nm--sysroot= $PLATFORM--extra-cfla gs= "-o3-fpic-dandroid-dhave_sys_uio_h=1 $OPTIMIZE _cflags"--disable-shared--enable-static--extra-ldflag  s= "-wl,-rpath-link= $PLATFORM/usr/lib-l$platform/usr/lib-nostdlib-lc-lm-lz-ldl-llog-lavcodec-lavformat-lswscale -lavutil-lswresample "--disable-ffmpeg--disable-ffplay--disable-ffprobe--disable-ffserver--enabl E-swscale--disable-swresample--ENABLE-AVFOrmat--enable-avcodec--disable-optimizations--disable-debug--disable-doc--disable-stripping- -enable-pthreads--disable-yasm--enable-zlib--enable-pic--enable-smallmake cleanmake-j4 Install$PREBU Ilt/bin/arm-linux-androideabi-ar d LIBAVCODEC/LIBAVCODEC.A Inverse.o$prebuilt/bin/arm-linux-androideabi-ld- rpath-link= $PLATFORM/usr/lib-l$platform/usr/lib-soname libffmpeg.so-shared-nostdlib-z noexecstack-bsymbolic--who Le-archive--no-undefined-o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavformat/libavformat.a libavutil/ LIBAVUTIL.A libswscale/libswscale.a-lc-lm-lz-ldl-llog--dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/ Arm-linux-androideabi/4.8/libgcc.a

The FFmpeg version he was porting was 2.5.3 and I used this version, but I was disappointed by the result:

libavcodec/opusdec.c:376:error:undefined reference to ' swr_is_initialized ' Libavcodec/opusdec.c:222:error: Undefined reference to ' swr_is_initialized ' libavcodec/opusdec.c:163:error:undefined reference to ' Swr_ Init ' libavcodec/opusdec.c:169:error:undefined reference to ' Swr_convert ' libavcodec/opusdec.c:236:error:undefined Reference to ' Swr_convert ' libavcodec/opusdec.c:117:error:undefined reference to ' Swr_convert ' libavcodec/opusdec.c : 408:error:undefined reference to ' Swr_close ' libavcodec/opusdec.c:563:error:undefined reference to ' Swr_ Close ' libavcodec/opusdec.c:585:error:undefined reference to ' Swr_free ' libavcodec/opusdec.c:638:error:undefined Reference to ' Swr_alloc '

Livingstone He himself has encountered this problem, and ultimately did not solve, I think it may be the ffmpeg version of the problem.

He said that FFmpeg's 2.0 version of the pre-and post-compilation porting method may be different, I think this is perhaps the test of some of the online tutorial is not successful reasons for it. The NDK version, the FFmpeg version, all have the potential to affect the results, so be flexible.

4, finally used an open source project Ffmpeg-android Source + The above configuration file to compile, incredibly no error, really excited to die.

The Open source project address is:

FFmpeg for Android

I remember to look at the information before the project has been downloaded, but looked at a long time is not know how to use, and later on the shelve. I didn't expect to use it this time.

(1) Download ffmpeg for Android project source code, address http://sourceforge.net/projects/ffmpeg4android/files/20140318/ I chose this version of Ffmpeg-2.1.4.android.

(2) Copy the contents of the above build_bin_ffmpeg_1.sh file to the Ffmpeg-2.1.4.android directory.

(3) Modify the permissions of the build_bin_ffmpeg_1.sh file

chmod 755 build_bin_ffmpeg_1.sh

(4) Execute configuration file

./build_bin_ffmpeg_1.sh

(5) Without error, wait a few minutes after the following screen appears:

Open the Ffmpeg-2.1.4.android directory, you will find a number of Android directory, there is a armv7-a folder inside the bin, include, Lib, share and libffmpeg.so files.

What we need is a ffmpeg executable file in the bin directory, and the file command can be used to view its properties:

[Email protected]:~/345/ffmpeg-2.1.4.android/android/armv7-a/bin$ file ffmpeg ffmpeg:elf 32-bit LSB  executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), stripped

You can see that it is an executable file under arm, size 9.1M.

(6) Push the executable file in the bin directory to the Android/data/misc/directory

[Email protected]:~$ adb push/home/wangrui/345/ffmpeg-2.1.4.android/android/armv7-a/bin/ffmpeg  /data/misc/ Ffmpeg

You can see a ffmpeg file in the/data/misc directory stating that push succeeded

[email protected]:/# CD data/misc/[Email protected]:/data/misc # lldrwxrwxr-x root root 2015-03-04 18:52-rdrwxrwxr-x root root 2015-03-04 18:52-rfdr WXRWX---system system 2000-01-01 08:02 bluetoothdrwxrwx---bluetooth bluetooth 2000-01-01-Blu ETOOTHDDRWXRWX---dhcp dhcp 2015-03-10 17:12 dhcp<span style= "color: #FF0000;" >-rwxrwxrwx root root 9145536 2015-03-10 10:48 ffmpeg</span>drwx------Nobody root 2015-0 3-05 18:04 hlsdrwxrwxr-x root root 2015-03-04 18:52 htmldrwxrwx--x system System 2000-01-01 keychaindrwx------KeyStore KeyStore 2000-01-01 keystoredrwxrwxr-x root root 2015-03  -04 18:52 logsdrwxrwxrwx root root 2015-03-04 19:15 nginxdrwxrwxr-x root root 2015-03-05      18:04 nginx-rtmpdrwx------System System      2000-01-01 systemkeysdrwxrwx---System VPN 2000-01-01 vpndrwxrwxrwx WiFi wifi 2000-03-13 16:55 WiFi

(7) Execute FFmpeg file

./ffmpeg

Shown below:

[Email protected]:/data/misc #./ffmpeg ffmpeg version 2.1.4 Copyright (c ) 2000-2014 The FFmpeg developers built on April 10:48:10 with GCC 4.8 (GCC) configuration:--target-os=linux--PR Efix=./android/armv7-a--enable-cross-compile--arch=arm--enable-nonfree--enable-asm--cpu=cortex-a8--cc=/home/ wangrui/java/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/ ARM-LINUX-ANDROIDEABI-GCC--cross-prefix=/home/wangrui/java/android-ndk-r9d/toolchains/ arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi---nm=/home/wangrui/java/android-ndk-r9d /TOOLCHAINS/ARM-LINUX-ANDROIDEABI-4.8/PREBUILT/LINUX-X86/BIN/ARM-LINUX-ANDROIDEABI-NM--sysroot=/home/wangrui/ java/android-ndk-r9d/platforms/android-9/arch-arm/--extra-cflags= '-o3-fpic-dandroid-dhave_sys_uio_h=1- Mfloat-abi=softfp-marm-mcpu=cortex-a8 ' Libavutil 52. 48.101/52. 48.101 Libavcodec 55. 39.101/55.   39.101 Libavformat 55.19.104/55.  19.104 Libavdevice 55.  5.100/55. 5.100 Libavfilter 3. 90.100/3.  90.100 Libswscale 2.  5.101/2. 5.101 libswresample 0. 17.104/0. 17.104Hyper Fast Audio and Video encoderusage:ffmpeg [options] [[infile Options]-I infile] ... {[outfile options] outfile} ... Use-h to get full help or, even better, run ' man ffmpeg '

5, finally I will compile the executable file upload, if necessary, you can download try.

http://download.csdn.net/detail/xdwyyan/8488351


6. Summary

FFmpeg's transplant work can be said to cost me a lot of energy, through the failure over and over again, try again, in the end success.

Some of the online tutorials may be based on their own environment configuration, for other people do not necessarily do, including my method others may compile errors, but it is nothing. Experiment a few times, try to believe in the end will be successful.


Using Nginx+nginx-rtmp-module+ffmpeg to build a streaming server note (eight)

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.