Android plays H265 RTSP from LibVLC-android to self-compiled ijkplayer

overview

     ijkplayer: Android/iOS video player based on FFmpeg n3.4, with MediaCodec, VideoToolbox support. The
official description is such a simple sentence, but it does not affect its power at all.

From LibVLC to ijkplayer

As of 2023.7.20,
the biggest problem with LibVLC-Android is OOM . After testing multiple versions, I finally choose to give up:
3.1.0/3.2.5/3.3.5/3.5.0/3.6.0/4.0.0-eap1 Up to 4.0.0-eap11, the memory increases with the number of playbacks, and finally OOM
4.0.0-eap12 : OOMsolved, setVolume doesn't work anymore...

PS
4.0.0-eap12: OOM is also related to the bound playback window, and the memory leak problem still exists when passing in SurfaceView/TextureView; it was not resolved until org.videolan.libvlc.util.VLCVideoLayout
was used . Another problem is that org.videolan.libvlc.util.VLCVideoLayout will have problems such as residue and screen ratio imbalance when the screen is switched or overlaid.

Downloaded the source code to compile
vlc-android

export ANDROID_NDK=/home/anson/Android/Sdk/ndk/android-ndk-r14b
export ANDROID_SDK=/home/anson/Android/Sdk
buildsystem/compile.sh -l -a arm 

To generate an AAR, you only need to add the -r parameter

The OOM problem is still there~ There is still a difference with 4.0.0-eap12


Of course, other playback plug-ins such as
ExoPlayer have also been considered. Without H265, the android exoplayer rtsp example
insert image description here
has been migrated to AndroidX Media3 1.1.0 release.

This is the last planned release of the com.google.android.exoplayer2 artifacts. 
This project is now deprecated. All users should migrate to androidx.media3 (which contains the same ExoPlayer code). 
See the migration guide for more details, including a script to help with the migration

SmarterStreaming ,

PS : I haven’t tried the mobile terminal of Shiwo Technology-Daniu Live before, and then I downloaded it and tried it. Even the DEMO APK can’t run, huh, huh, it’s not free

insert image description here

GSYVideoPlayer
Android–GSYVideoPlayer framework realizes video playback
How to say it, this is a big collection, EXO, IJK... can't solve RTSP + H265


There are some compatibility issues with rtsp-client-android , so there is no picture.

use ijkplayer

Description of ijkplayer access method

  1. The ijkplayer imported from gradle iscannotPlay RTSP
implementation "tv.danmaku.ijk.media:ijkplayer-java:0.8.8"
implementation "tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8"
  1. ijkplayer has been stopped for several years, and NDK still uses NDK10-NDK14
export ANDROID_NDK=/home/anson/Android/Sdk/ndk/android-ndk-r14b
export ANDROID_SDK=/home/anson/Android/Sdk

ARCH=armv7a

echo ">> INIT "
git checkout -B latest k0.8.8
./init-android.sh
./init-android-openssl.sh

cd android/contrib


echo ">> BUILD OPENSSL"
./compile-openssl.sh clean
./compile-openssl.sh ${ARCH}

echo ">> BUILD FFMPEG"
./compile-ffmpeg.sh clean
./compile-ffmpeg.sh ${ARCH}

echo ">> BUILD IJKPLAYER"
cd ..
./compile-ijk.sh clean
./compile-ijk.sh ${ARCH}

Some modifications to the source code:

git diff config/module-lite.sh android/contrib/tools/do-compile-ffmpeg.sh
diff --git a/android/contrib/tools/do-compile-ffmpeg.sh b/android/contrib/tools/do-compile-ffmpeg.sh
index d6b3ba63..633b89f6 100755
--- a/android/contrib/tools/do-compile-ffmpeg.sh
+++ b/android/contrib/tools/do-compile-ffmpeg.sh
@@ -267,7 +267,7 @@ FF_CFG_FLAGS="$FF_CFG_FLAGS --prefix=$FF_PREFIX"
 # Advanced options (experts only):
 FF_CFG_FLAGS="$FF_CFG_FLAGS --cross-prefix=${FF_CROSS_PREFIX}-"
 FF_CFG_FLAGS="$FF_CFG_FLAGS --enable-cross-compile"
-FF_CFG_FLAGS="$FF_CFG_FLAGS --target-os=linux"
+FF_CFG_FLAGS="$FF_CFG_FLAGS --target-os=android"
 FF_CFG_FLAGS="$FF_CFG_FLAGS --enable-pic"
 # FF_CFG_FLAGS="$FF_CFG_FLAGS --disable-symver"
 
@@ -292,6 +292,8 @@ case "$FF_BUILD_OPT" in
     ;;
 esac
 
+
+
 #--------------------
 echo ""
 echo "--------------------"
diff --git a/config/module-lite.sh b/config/module-lite.sh
index d5ba3d0f..64c4b05a 100755
--- a/config/module-lite.sh
+++ b/config/module-lite.sh
@@ -42,7 +42,10 @@ export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-swscale"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-postproc"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-avfilter"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-avresample"
-# export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-pthreads"
+export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-pthreads"
+export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-mediacodec"
+export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-jni"
+
 # export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-w32threads"
 # export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-os2threads"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-network"
@@ -146,7 +149,8 @@ export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-protocol=mmst"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-protocol=rtmp*"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-protocol=rtmp"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-protocol=rtmpt"
-export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-protocol=rtp"
+export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-protocol=rtp"
+export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --enable-demuxer=rtsp"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-protocol=sctp"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-protocol=srtp"
 export COMMON_FF_CFG_FLAGS="$COMMON_FF_CFG_FLAGS --disable-protocol=subfile"

After compiling:

JAVA

android/ijkplayer/ijkplayer-java/src/main/java/tv/danmaku/ijk/media/player/
├── AbstractMediaPlayer.java
├── AndroidMediaPlayer.java
├── annotations
│   ├── AccessedByNative.java
│   └── CalledByNative.java
├── exceptions
│   └── IjkMediaException.java
├── ffmpeg
│   └── FFmpegApi.java
├── IjkLibLoader.java
├── IjkMediaCodecInfo.java
├── IjkMediaMeta.java
├── IjkMediaPlayer.java
├── IjkTimedText.java
├── IMediaPlayer.java
├── ISurfaceTextureHolder.java
├── ISurfaceTextureHost.java
├── MediaInfo.java
├── MediaPlayerProxy.java
├── misc
│   ├── AndroidMediaFormat.java
│   ├── AndroidTrackInfo.java
│   ├── IAndroidIO.java
│   ├── IjkMediaFormat.java
│   ├── IjkTrackInfo.java
│   ├── IMediaDataSource.java
│   ├── IMediaFormat.java
│   └── ITrackInfo.java
├── pragma
│   ├── DebugLog.java
│   └── Pragma.java
└── TextureMediaPlayer.java

SO library

android/ijkplayer/ijkplayer-armv7a/src/main/libs/armeabi-v7a/
├── libijkffmpeg.so
├── libijkplayer.so
└── libijksdl.so

Be lazy here, just use the so library, build.gradle:

implementation "tv.danmaku.ijk.media:ijkplayer-java:0.8.8"
//这个不要,直接使用编译出来的so库
//implementation "tv.danmaku.ijk.media:ijkplayer-armv7a:0.8.8"

some problems

After the compilation is complete, you can try to open the ijkplayer sample project in AndroidStudio. AndroidStudio and gradle have changed, using some configuration information that needs to be modified to some compatible versions.

android/ijkplayer/build.gradle

--- a/android/ijkplayer/build.gradle
+++ b/android/ijkplayer/build.gradle
@@ -3,9 +3,11 @@
 buildscript {
    
    
     repositories {
    
    
         jcenter()
+        maven {
    
     url 'https://maven.google.com/'}
+        maven {
    
     url 'https://maven.aliyun.com/repository/jcenter' }
     }
     dependencies {
    
    
-        classpath 'com.android.tools.build:gradle:2.1.3'
+        classpath 'com.android.tools.build:gradle:4.0.1'
 
         classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
         classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
@@ -17,6 +19,8 @@ buildscript {
    
    
 allprojects {
    
    
     repositories {
    
    
         jcenter()
+        maven {
    
     url 'https://maven.google.com/'}
+        maven {
    
     url 'https://maven.aliyun.com/repository/jcenter' }
     }
 }

android/ijkplayer/gradle/wrapper/gradle-wrapper.properties

@@ -1,6 +1,6 @@
-#Wed Aug 24 16:26:25 CST 2016
+#Wed Jul 19 10:32:59 CST 2023
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

android/ijkplayer/ijkplayer-example/build.gradle

--- a/android/ijkplayer/ijkplayer-example/build.gradle
+++ b/android/ijkplayer/ijkplayer-example/build.gradle
@@ -16,6 +16,12 @@ android {
    
    
         targetSdkVersion rootProject.ext.targetSdkVersion
         versionCode rootProject.ext.versionCode
         versionName rootProject.ext.versionName
+
+        externalNativeBuild{
    
    
+            ndk{
    
    
+                abiFilters  'armeabi-v7a'
+            }
+        }
     }
     buildTypes {
    
    
         release {
    
    
@@ -23,36 +29,35 @@ android {
    
    
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
     }
-    productFlavors {
    
    
+    /*productFlavors {
    
    
         all32 {
    
     minSdkVersion 9 }
         all64 {
    
     minSdkVersion 21 }
         // armv5 {
    
    }
         // armv7a {
    
    }
         // arm64 {
    
     minSdkVersion 21 }
         // x86 {
    
    }
-    }
+    }*/
 }
 
 dependencies {
    
    
-    compile fileTree(include: ['*.jar'], dir: 'libs')
-    compile 'com.android.support:appcompat-v7:23.0.1'
-    compile 'com.android.support:preference-v7:23.0.1'
-    compile 'com.android.support:support-annotations:23.0.1'
-
+            }
+        }
     }
     buildTypes {
    
    
         release {
    
    
@@ -23,36 +29,35 @@ android {
    
    
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
         }
     }
-    productFlavors {
    
    
+    /*productFlavors {
    
    
         all32 {
    
     minSdkVersion 9 }
         all64 {
    
     minSdkVersion 21 }
         // armv5 {
    
    }
         // armv7a {
    
    }
         // arm64 {
    
     minSdkVersion 21 }
         // x86 {
    
    }
-    }
+    }*/
 }
 
 dependencies {
    
    
-    compile fileTree(include: ['*.jar'], dir: 'libs')
-    compile 'com.android.support:appcompat-v7:23.0.1'
-    compile 'com.android.support:preference-v7:23.0.1'
-    compile 'com.android.support:support-annotations:23.0.1'
-
-    compile 'com.squareup:otto:1.3.8'
+    implementation fileTree(include: ['*.jar'], dir: 'libs')
+    implementation 'com.android.support:appcompat-v7:23.0.1'
+    implementation 'com.android.support:preference-v7:23.0.1'
+    implementation 'com.android.support:support-annotations:23.0.1'
 
-    compile project(':ijkplayer-java')
-    compile project(':ijkplayer-exo')
+    implementation 'com.squareup:otto:1.3.8'
 
-    all32Compile project(':ijkplayer-armv5')
-    all32Compile project(':ijkplayer-armv7a')
-    all32Compile project(':ijkplayer-x86')
+    implementation project(':ijkplayer-java')
+    implementation project(':ijkplayer-exo')
 
-    all64Compile project(':ijkplayer-armv5')
-    all64Compile project(':ijkplayer-armv7a')
-    all64Compile project(':ijkplayer-arm64')
-    all64Compile project(':ijkplayer-x86')
-    all64Compile project(':ijkplayer-x86_64')
+    //all32Compile project(':ijkplayer-armv5')
+    implementation project(':ijkplayer-armv7a')
+    //all32Compile project(':ijkplayer-x86')
+    //all64Compile project(':ijkplayer-armv5')
+    //all64Implementation project(':ijkplayer-armv7a')
+    //all64Compile project(':ijkplayer-arm64')
+    //all64Compile project(':ijkplayer-x86')
+    //all64Compile project(':ijkplayer-x86_64')
 
     // compile 'tv.danmaku.ijk.media:ijkplayer-java:0.8.8'
     // compile 'tv.danmaku.ijk.media:ijkplayer-exo:0.8.8'

android/ijkplayer/settings.gradle

--- a/android/ijkplayer/settings.gradle
+++ b/android/ijkplayer/settings.gradle
@@ -1,7 +1,7 @@
-include ':ijkplayer-armv5', ':ijkplayer-x86_64'
+//include ':ijkplayer-armv5', ':ijkplayer-x86_64'
 include ':ijkplayer-armv7a'
-include ':ijkplayer-arm64'
-include ':ijkplayer-x86'
+//include ':ijkplayer-arm64'
+//include ':ijkplayer-x86'
 
 include ':ijkplayer-java'
 include ':ijkplayer-exo'
    defaultConfig {
        applicationId "tv.danmaku.ijk.media.example"
        minSdkVersion 9
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode rootProject.ext.versionCode
        versionName rootProject.ext.versionName

        externalNativeBuild{
            ndk{
                abiFilters  'armeabi-v7a'
            }
        }
    }

|–/home/anson/work/importProjs/ijkplayer/android/contrib/build/ffmpeg-armv7a/toolchain/bin//arm-linux-androideabi-gcc
ERROR: jni not found

Play H265 RTSP

  • If you can't play, try to check the configuration of the player:
 ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-all-videos", 1);
 ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "mediacodec-hevc", 1);
 ijkMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_transport", "tcp");

In general, the use of ijkplayer is very similar to the system's MediaPlayer. Some optimizations and delays can refer to the link at the end of the article.

PS: If you need to switch playback sources frequently, especially some online videos, don't be stingy to create several more ijkplayer instances . The multiplexing of instances may not save much resources, but will bring many unexpected problems.

reference

Guess you like

Origin blog.csdn.net/ansondroider/article/details/131822521