Skip to content

Commit

Permalink
[update] ffmpeg - lite 封装
Browse files Browse the repository at this point in the history
  • Loading branch information
SheTieJun committed Sep 14, 2022
1 parent 3f672cc commit e9b6058
Show file tree
Hide file tree
Showing 187 changed files with 32,468 additions and 26 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ dependencies {
implementation project(path: ':soundTouch')
implementation project(path: ':lame')
implementation project(path: ':tools')
implementation project(path: ':ffmpeg-lite-kt')
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
def version = "1.6.4"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
implementation 'androidx.fragment:fragment-ktx:1.2.5'
}
41 changes: 39 additions & 2 deletions app/src/main/java/me/shetj/sdk/ffmepg/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.shetj.ffmpeg.kt.FFmpegKit
import me.shetj.ffmpeg.kt.RunState
import me.shetj.ffmpeg.kt.buildCommand
import me.shetj.ffmpeg.kt.convertToCommand
import me.shetj.ndk.lame.LameUtils
import me.shetj.sdk.curl.CUrlKit
import me.shetj.sdk.curl.CurlHttp
Expand Down Expand Up @@ -31,8 +39,7 @@ class MainActivity : AppCompatActivity() {
// Example of a call to a native method
try {
STKit.getInstance().init(2, 44100, 1f, 10f, 1f)
LameUtils.init(44100, 1, 44100, 64, 3,3000,200)

LameUtils.init(44100, 1, 44100, 64, 3,3000,200,false)
binding.sampleText.text = stringFromJNI() +
"\nLame:" + LameUtils.version() +
"\nSoundTouch:${STKit.getInstance().getVersion()}" +
Expand All @@ -41,6 +48,8 @@ class MainActivity : AppCompatActivity() {
e.printStackTrace()
}



binding.test.setOnClickListener {
CurlHttp.setCertificate(cacert)
//TODO 需要在线程
Expand All @@ -57,6 +66,34 @@ class MainActivity : AppCompatActivity() {

JsonKit.test()
}


binding.ffmpegKit.setOnClickListener {
lifecycleScope.launch {
val command = "ffmepg -version".convertToCommand()
withContext(Dispatchers.IO){
FFmpegKit.runCommand(command).collect{
when(it){
RunState.OnCancel -> {
Log.e("FFmpegKit","OnCancel")
}
is RunState.OnError -> {
Log.e("FFmpegKit",it.message.toString())
}
RunState.OnFinish -> {
Log.e("FFmpegKit","OnFinish")
}
is RunState.OnProgress -> {
Log.e("FFmpegKit","OnProgress")
}
RunState.OnStart ->{
Log.e("FFmpegKit","OnStart")
}
}
}
}
}
}
}

/**
Expand Down
45 changes: 31 additions & 14 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,37 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<com.google.android.material.chip.ChipGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="curl_test"/>
<Button
android:id="@+id/test_json"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@+id/test"
app:layout_constraintTop_toTopOf="parent"
android:textAllCaps="false"
android:text="json_test"/>

<Button
android:id="@+id/ffmpegKit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@+id/test"
app:layout_constraintTop_toTopOf="parent"
android:textAllCaps="false"
android:text="ffmpegKit"/>
</com.google.android.material.chip.ChipGroup>


<TextView
android:id="@+id/sample_text"
android:layout_width="wrap_content"
Expand All @@ -16,18 +47,4 @@
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="CURL_test"/>
<Button
android:id="@+id/test_json"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@+id/test"
app:layout_constraintTop_toTopOf="parent"
android:text="json_test"/>
</androidx.constraintlayout.widget.ConstraintLayout>
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.31"
ext.kotlin_version = "1.7.10"

ext.sdk_version = '1.0.0'

ext.local_group_id = 'com.github.SheTieJun.Android_NDK'
ext.local_group_id = 'com.github.shetiejun.android-ndk'

repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' // Add this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand All @@ -29,4 +28,5 @@ allprojects {

task clean(type: Delete) {
delete rootProject.buildDir
}
}
apply from : "https://gist.githubusercontent.com/SheTieJun/f4cb1bd33997c2b46d9e3df40b95a02e/raw/c7b65d18aabfeccc09c37e3b2e7964cdd1f8e856/subprojects.gradle"
1 change: 1 addition & 0 deletions ffmpeg-lite-kt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions ffmpeg-lite-kt/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## FFmpegKit

FFmpeg Kotlin 协程封装

## How TO USE

```kotlin
lifecycleScope.launch {
val command = "ffmepg -version".convertToCommand()
withContext(Dispatchers.IO) {
FFmpegKit.runCommand(command).collect {
when (it) {
RunState.OnCancel -> {
Log.e("FFmpegKit", "OnCancel")
}
is RunState.OnError -> {
Log.e("FFmpegKit", it.message.toString())
}
RunState.OnFinish -> {
Log.e("FFmpegKit", "OnFinish")
}
is RunState.OnProgress -> {
Log.e("FFmpegKit", "OnProgress")
}
RunState.OnStart -> {
Log.e("FFmpegKit", "OnStart")
}
}
}
}
}
```
48 changes: 48 additions & 0 deletions ffmpeg-lite-kt/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk 31

defaultConfig {
minSdk 21
targetSdk 31

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
def version = "1.6.4"
compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"
}
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added ffmpeg-lite-kt/libs/x86/librxffmpeg-core.so
Binary file not shown.
Binary file added ffmpeg-lite-kt/libs/x86/librxffmpeg-invoke.so
Binary file not shown.
Binary file added ffmpeg-lite-kt/libs/x86/librxffmpeg-player.so
Binary file not shown.
Binary file added ffmpeg-lite-kt/libs/x86_64/librxffmpeg-core.so
Binary file not shown.
Binary file added ffmpeg-lite-kt/libs/x86_64/librxffmpeg-invoke.so
Binary file not shown.
Binary file added ffmpeg-lite-kt/libs/x86_64/librxffmpeg-player.so
Binary file not shown.
21 changes: 21 additions & 0 deletions ffmpeg-lite-kt/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package me.shetj.ffmpeg.kt

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("me.shetj.ffmpeg.kt.test", appContext.packageName)
}
}
5 changes: 5 additions & 0 deletions ffmpeg-lite-kt/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.shetj.ffmpeg.kt">

</manifest>
36 changes: 36 additions & 0 deletions ffmpeg-lite-kt/src/main/cpp/include/libavcodec/ac3_parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* AC-3 parser prototypes
* Copyright (c) 2003 Fabrice Bellard
* Copyright (c) 2003 Michael Niedermayer
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef AVCODEC_AC3_PARSER_H
#define AVCODEC_AC3_PARSER_H

#include <stddef.h>
#include <stdint.h>

/**
* Extract the bitstream ID and the frame size from AC-3 data.
*/
int av_ac3_parse_header(const uint8_t *buf, size_t size,
uint8_t *bitstream_id, uint16_t *frame_size);


#endif /* AVCODEC_AC3_PARSER_H */
37 changes: 37 additions & 0 deletions ffmpeg-lite-kt/src/main/cpp/include/libavcodec/adts_parser.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef AVCODEC_ADTS_PARSER_H
#define AVCODEC_ADTS_PARSER_H

#include <stddef.h>
#include <stdint.h>

#define AV_AAC_ADTS_HEADER_SIZE 7

/**
* Extract the number of samples and frames from AAC data.
* @param[in] buf pointer to AAC data buffer
* @param[out] samples Pointer to where number of samples is written
* @param[out] frames Pointer to where number of frames is written
* @return Returns 0 on success, error code on failure.
*/
int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
uint8_t *frames);

#endif /* AVCODEC_ADTS_PARSER_H */
Loading

0 comments on commit e9b6058

Please sign in to comment.