Tuesday, March 12, 2019

Android开发笔记-ch3.4.9.4 ffmpe and vitamio, 3.4.9.5 Setting up streaming server/service


3.4.9.4 ffmpe and vitamio

Refer to SO tag of vitamio which has links to ffmpeg-vs-vitamio, how-to-integrate-vitamio-in-android-studio and how-to-add-vitamio-dependecny-on-android-studio. Also, refer this for how to sync and build Vitamio.
VitamioBundle is an open multimedia framework for Android and iOS, with full and real hardware accelerated decoder and renderer. However it is not free for comercial use. It is available from Maven Repo as vitamio-4.2.2.aar; I built from source. The latest version is using gradle. However I'm getting error like: “A problem occurred evaluating project ':vitamio'. > Failed to apply plugin [id 'com.android.library'] > Gradle version 1.10 is required. Current version is 2.8. If using the gradle wrapper, try editing the distributionUrl in /home/strongqu/qyq/michael/VitamioBundle/gradle/wrapper/gradle-wrapper.properties to gradle-1.10-all.zip ”. Refer to this SO. Anyway, I update gradle-wrapper.properties with this line and it works now: distributionUrl=https\://services.gradle.org/distributions/gradle-1.10-all.zip
I also update gradle.properties to use newer SDK/TOOLS as I don't want to install older SDK:
ANDROID_BUILD_MIN_SDK_VERSION=15
ANDROID_BUILD_TARGET_SDK_VERSION=23
ANDROID_BUILD_TOOLS_VERSION=23.0.3
ANDROID_BUILD_SDK_VERSION=23
Also need to update vitamio/build.gradle. Also need to change the plugin from 0.12.+ to 1.5.0 in build.gradle. The gradle output is an aar file. So just copy VitamioBundle/vitamio/build/intermediates/bundles/release/classes.jar.to your project as lib is not enough.
Their wiki is not very clear, and might be out-date. They mentioned copy vitamio.jar, vitamio/libs/*, vitamio/res/* to your own project. The dist dir contain 3 dirs: arm_x86(support ARM & x86 arch), arm_x86_mips(support ARM & x86 & MIPS), online_arm (online version for ARM). If want to use online version, please copy online_arm/* to vitamio/*. The main difference might be the libarm.so under each dir, which has different size: online:4.8M, arm_x86:12.7M, and arm_x86_mips:17.8M. Each libarm.so is actual an archive of multiple versions(has subfolder name like 60, 70, 71, which likes to be coresponding to ARM v6, v7 arch) of so files. Though not very clear what exactly online means, the online libarm.so is the smallest, from subfolder naming within the archive, it might only support ARMv6+, which is good enough to be used with.
Some other useful info from vitamio: wiki mentions 3 steps: 1) add Vitamo lib; 2) io.vov.vitamio.LibsChecker.checkVitamioLibs() 3) Declare InitActivity in AndroidManifest.xml. Also refer to Vitamio 错误大全. I also found that I have to add <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> to manifest xml, otherwise, get Fatal signal 6 (SIGABRT). Also I found calling vidHolder.setFormat(PixelFormat.RGBA_8888) is a must before start the mediaplayer, otherwise signall 11 SIGSEGV.

Refer below for aar vs jar. I did this to get other projects to use vitamio libs: 1) create a new folder and extract AndroidMainfest.xml, res folder and classes.jar from vitamio-release.aar. No need of the JNI code. Create a libs subfolder and move classes.jar to under it. 2) from Eclipse create or import an Android project with exist code, and pick the folder we extracted vitamio binaries to as source, and set this as library project, the project would be named as InitActivity; 3) With my App project, set InitActivity as reference, copy dist/online_arm libs to my project and res(libarm.so is under raw) to InitActivity; Though copy the res to my project is also ok, w/o enabling Proguard; But in that case, if enable Proguard, will get warning: java.lang.NoClassDefFoundError: io.vov.vitamio.R$raw. So better put the res along with other resource into InitActivity project. Declare InitActivity in AndroidManifest.xml, and call io.vov.vitamio LibsChecker.checkVitamioLibs
Alternatively, don't copy the dist/online_arm/res/raw/libarm.so, but let the App to download the libarm.so on fly. This way can save some storge in case the user doesn't want the support of vitamio.
To run the vitamio-sample, need to modify MediaPlayerDemo_Video.java to set the path/url of stream.
For the 1st time run checkVitamioLibs, it will try to extract the so files. Log shows:
05-21 20:23:14.476: W/dalvikvm(3891): VFY: unable to resolve static field 332 (libarm) in Lio/vov/vitamio/R$raw;
05-21 20:23:14.476: D/dalvikvm(3891): VFY: replacing opcode 0x60 at 0x0006
05-21 20:23:14.476: D/dalvikvm(3891): Trying to load lib /data/app-lib/io.vov.vitamio.demo-2/libvinit.so 0x418741a0
05-21 20:23:14.476: D/dalvikvm(3891): Added shared lib /data/app-lib/io.vov.vitamio.demo-2/libvinit.so 0x418741a0
...
05-21 20:23:15.057: I/ActivityManager(3891): Timeline: Activity_launch_request id:io.vov.vitamio.demo time:139601
05-21 20:23:15.087: I/LIB ROOT: %s(3891): /data/data/io.vov.vitamio.demo/libs/
05-21 20:23:15.087: D/dalvikvm(3891): Trying to load lib /data/data/io.vov.vitamio.demo/libs/libstlport_shared.so 0x418741a0
05-21 20:23:15.137: D/dalvikvm(3891): Added shared lib /data/data/io.vov.vitamio.demo/libs/libstlport_shared.so 0x418741a0
05-21 20:23:15.137: D/dalvikvm(3891): No JNI_OnLoad found in /data/data/io.vov.vitamio.demo/libs/libstlport_shared.so 0x418741a0, skipping init
05-21 20:23:15.137: D/dalvikvm(3891): Trying to load lib /data/data/io.vov.vitamio.demo/libs/libvscanner.so 0x418741a0
05-21 20:23:15.167: D/dalvikvm(3891): Added shared lib /data/data/io.vov.vitamio.demo/libs/libvscanner.so 0x418741a0
05-21 20:23:15.167: D/dalvikvm(3891): Trying to load lib /data/data/io.vov.vitamio.demo/libs/libstlport_shared.so 0x418741a0
05-21 20:23:15.167: D/dalvikvm(3891): Shared lib '/data/data/io.vov.vitamio.demo/libs/libstlport_shared.so' already loaded in same CL 0x418741a0
05-21 20:23:15.167: D/dalvikvm(3891): Trying to load lib /data/data/io.vov.vitamio.demo/libs/libvplayer.so 0x418741a0
05-21 20:23:15.187: D/dalvikvm(3891): Added shared lib /data/data/io.vov.vitamio.demo/libs/libvplayer.so 0x418741a0
05-21 20:23:15.187: I/Vitamio[4.2.1][Player](3891): Copyright (c) YIXIA (http://yixia.com).
05-21 20:23:15.187: I/Vitamio[4.2.1][Player](3891): THIS SOFTWARE (Vitamio) IS WORK OF YIXIA (http://yixia.com)
05-21 20:23:15.187: I/Vitamio[4.2.1][Player](3891): LOAD FFMPEG START: /data/data/io.vov.vitamio.demo/libs/libffmpeg.so
05-21 20:23:15.197: W/linker(3891): libffmpeg.so has text relocations. This is wasting memory and is a security risk. Please fix.
05-21 20:23:15.237: E/Vitamio[4.2.1][Player](3891): FIND_NAME_SYM ffmpeg, ff_ass_split
05-21 20:23:15.237: E/Vitamio[4.2.1][Player](3891): FIND_NAME_SYM ffmpeg, ff_ass_split_dialog
05-21 20:23:15.237: E/Vitamio[4.2.1][Player](3891): FIND_NAME_SYM ffmpeg, ff_ass_split_free
05-21 20:23:15.237: I/Vitamio[4.2.1][Player](3891): LOAD FFMPEG END: /data/data/io.vov.vitamio.demo/libs/libffmpeg.so
05-21 20:23:15.237: I/Vitamio[4.2.1][Player](3891): LOAD VVO START: /data/data/io.vov.vitamio.demo/libs/libvvo.9.so
05-21 20:23:15.237: E/Vitamio[4.2.1][Player](3891): FIND_NAME_SYM vvo, render_yuv
05-21 20:23:15.237: I/Vitamio[4.2.1][Player](3891): LOAD VVO END: /data/data/io.vov.vitamio.demo/libs/libvvo.9.so
05-21 20:23:15.237: I/Vitamio[4.2.1][Player](3891): LOAD VAO START: /data/data/io.vov.vitamio.demo/libs/libvao.0.so
05-21 20:23:15.237: I/Vitamio[4.2.1][Player](3891): LOAD VAO END: /data/data/io.vov.vitamio.demo/libs/libvao.0.so
05-21 20:23:15.237: I/Vitamio[4.2.1][Player](3891): LOAD FFMPEG START: /data/data/io.vov.vitamio.demo/libs/libffmpeg.so
05-21 20:23:15.247: E/Vitamio[4.2.1][Player](3891): FIND_NAME_SYM ffmpeg, ff_ass_split
05-21 20:23:15.247: E/Vitamio[4.2.1][Player](3891): FIND_NAME_SYM ffmpeg, ff_ass_split_dialog
05-21 20:23:15.247: E/Vitamio[4.2.1][Player](3891): FIND_NAME_SYM ffmpeg, ff_ass_split_free
05-21 20:23:15.247: I/Vitamio[4.2.1][Player](3891): LOAD FFMPEG END: /data/data/io.vov.vitamio.demo/libs/libffmpeg.so
...
05-21 20:25:40.823: W/dalvikvm(5266): VFY: unable to resolve static field 332 (libarm) in Lio/vov/vitamio/R$raw;
05-21 20:25:40.823: D/dalvikvm(5266): VFY: replacing opcode 0x60 at 0x0006
05-21 20:25:40.833: D/dalvikvm(5266): Trying to load lib /data/app-lib/io.vov.vitamio.demo-1/libvinit.so 0x41876ec0
05-21 20:25:40.833: D/dalvikvm(5266): Added shared lib /data/app-lib/io.vov.vitamio.demo-1/libvinit.so 0x41876ec0
05-21 20:25:40.833: I/ActivityManager(5266): Timeline: Activity_launch_request id:io.vov.vitamio.demo time:285389
...
05-21 20:25:41.143: I/ActivityManager(5266): Timeline: Activity_idle id: android.os.BinderProxy@41886620 time:285692
05-21 20:25:41.223: I/Vitamio[Init](5266): PARSE FILE: /data/data/io.vov.vitamio.demo/libs/, /data/data/io.vov.vitamio.demo/libs/libarm.so, 71
05-21 20:25:41.223: I/Vitamio[Init](5266): Extracting....
05-21 20:25:41.223: I/Vitamio[Init](5266): 71/libffmpeg.so

3.4.9.5 Setting up streaming server/service

Refer to this and this for using node. For App HLS, refer to this. Ffmpeg has option to segment the stream. Refer to this post:
ffmpeg -i input.mkv -c copy -f segment -segment_list playlist.m3u8 -segment_time 10 output%03d.ts
-c copy means 'copy all the streams'; this means no transcoding, so it saves on CPU, time, and generational data loss. -f segment tells ffmpeg to output multiple segments, -segment_list playlist.m3u8 tells it to generate a playlist file called playlist.m3u8, -segment_time 10 means 'make a segment every ten seconds'. output%03d.ts means it will output mpegts files in the pattern of: output001.ts, output002.ts, output003.ts, and so on.
Get source:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg => For build ffmpeg on Ubuntu, refer to the wiki.

0 Comments:

Post a Comment