Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh project + new features #71

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9eee346
Update dependencies, refresh project
natario1 Dec 13, 2018
881d8d3
Fix audio format bug
natario1 Dec 13, 2018
1afc57c
Add logger class
natario1 Dec 13, 2018
399ecf1
Replace Log calls with logger calls
natario1 Dec 13, 2018
7a90ccc
Use root project ext variables
natario1 Dec 13, 2018
0cbdb91
Move to androidX
natario1 Dec 13, 2018
0479083
Nullability annotations in strategies
natario1 Dec 13, 2018
e0bc9ef
Support for Context/Uri input, create DataSource interface
natario1 Dec 13, 2018
2f7a2a7
Accept files with no audio track
natario1 Dec 13, 2018
ccf71c0
Use UriDataSource in demo app
natario1 Dec 14, 2018
22ed044
Multithreading support
natario1 Dec 14, 2018
199c27e
Fix missing file provider, annotations
natario1 Dec 14, 2018
7133c9e
Builder pattern - deprecate old transcodeVideo calls - add listenerHa…
natario1 Dec 14, 2018
cab3662
Breaking change - remove all MediaFormatStrategy package, create Outp…
natario1 Dec 14, 2018
6b0e428
Add Validator interface to block unneeded transcodings
natario1 Dec 14, 2018
d7b3123
Add useful WriteVideoValidator
natario1 Dec 14, 2018
6979461
Better strategies, estimate bit rate
natario1 Dec 15, 2018
8031eb5
Comments
natario1 Dec 15, 2018
8f257ce
Use buffer utility in video track transcoder
natario1 Dec 15, 2018
186711b
Frame dropping support, frame rate in defaultvideostrategy, builder f…
natario1 Dec 15, 2018
774e729
Refactor packages
natario1 Dec 15, 2018
412233b
Create Size and Sizer classes for sizing strategy
natario1 Dec 15, 2018
143017e
Fix bug in QueuedMuxer
natario1 Dec 15, 2018
0315406
Create AtMost sizer
natario1 Dec 15, 2018
c42cf98
Fix progress
natario1 Dec 15, 2018
385aa88
Use throwable in listener signature
natario1 Dec 15, 2018
a824cf9
Rename to Resizer, add MultiResizer to merge resizers (useful for cro…
natario1 Dec 16, 2018
98c176e
Create ExactSize which knows about width and height
natario1 Dec 16, 2018
c41cff7
Comments
natario1 Dec 16, 2018
cf5990f
Do not throw for non baseline profiles
natario1 Dec 18, 2018
81ae917
Fix logs
natario1 Jan 15, 2019
38c01e1
Update README
natario1 Jan 15, 2019
92c2adc
Refactor package name and prepare to publish
natario1 Mar 3, 2019
c5ab239
Fix javadoc build
natario1 Mar 3, 2019
3ab5341
License info
natario1 Mar 3, 2019
6dede8d
Bump version to 0.4.0
natario1 Mar 4, 2019
6927bc2
Fix travis
natario1 Mar 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
language: android

branches:
only:
- master
- /^v\d+\.\d+\.\d+$/

sudo: false

jdk:
- oraclejdk8

android:
components:
- tools
- platform-tools
- build-tools-28.0.3
- android-28
- doc-28

script:
- ./gradlew build

cache:
directories:
- $HOME/.gradle
- $HOME/.m2/repository

deploy:
provider: script
script: ./gradlew bintrayUpload
skip_cleanup: true
on:
branch: master
tags: true
17 changes: 0 additions & 17 deletions CHANGELOG.md

This file was deleted.

103 changes: 18 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,99 +1,32 @@
android-transcoder
=================
# Transcoder

Hardware accelerated transcoder for Android, written in pure Java.

## Why?

Android does not offer straight forward way to transcode video.

FFmpeg is the most famous solution for transcoding. But using [FFmpeg binary on Android](https://github.com/WritingMinds/ffmpeg-android) can cause GPL and/or patent issues. Also using native code for Android development can be troublesome because of cross-compiling, architecture compatibility, build time and binary size.

To transcode without any hassle written above, I created this library to provide hardware accelerated transcoding of H.264 (mp4) video without ffmpeg by using [MediaCodec](https://developer.android.com/intl/ja/reference/android/media/MediaCodec.html).

## Requirements

API Level 18 (Android 4.3, JELLY_BEAN_MR2) or later.
If your app targets older Android, you should add below line to AndroidManifest.xml:

```xml
<!-- Only supports API >= 18 -->
<uses-sdk tools:overrideLibrary="net.ypresto.androidtranscoder" />
```

Please ensure checking Build.VERSION by your self.

## Usage

```java
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
ParcelFileDescriptor parcelFileDescriptor = resolver.openFileDescriptor(data.getData(), "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
MediaTranscoder.Listener listener = new MediaTranscoder.Listener() {
@Override
public void onTranscodeProgress(double progress) {
...
}

@Override
public void onTranscodeCompleted() {
startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(file), "video/mp4"));
...
}

@Override
public void onTranscodeFailed(Exception exception) {
...
}
};
MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(),
MediaFormatStrategyPresets.createAndroid720pStrategy(), listener); // or createAndroid720pStrategy([your bitrate here])
}
```

See `TranscoderActivity.java` in example directory for ready-made transcoder app.

## Quick Setup

### Gradle

Available from [JCenter](https://bintray.com/bintray/jcenter), which is default repo of gradle script generated by recent android studio.

```groovy
repositories {
jcenter()
}
```
This project is an improved fork of [ypresto/android-transcoder](https://github.com/ypresto/android-transcoder).
Lots of changes were made, so the documentation must be rewritten. You can, however, take a look at the
demo app which provides a working example of the new API.

```groovy
compile 'net.ypresto.androidtranscoder:android-transcoder:0.2.0'
implementation 'com.otaliastudios:transcoder:0.4.0'
```

## Note (PLEASE READ FIRST)
## Setup

- This library raises `RuntimeException`s (like `IlleagalStateException`) in various situations. Please catch it and provide alternate logics. I know this is bad design according to Effective Java; just is TODO.
- Currently this library does not generate streaming-aware mp4 file.
Use [qtfaststart-java](https://github.com/ypresto/qtfaststart-java) to place moov atom at beginning of file.
- Android does not gurantees that all devices have bug-free codecs/accelerators for your codec parameters (especially, resolution). Refer [supported media formats](http://developer.android.com/guide/appendix/media-formats.html) for parameters guaranteed by [CTS](https://source.android.com/compatibility/cts-intro.html).
- This library does not support video files recorded by other device like digital cameras, iOS (mov files, including non-baseline profile h.264), etc.
This library requires API level 18 (Android 4.3, JELLY_BEAN_MR2) or later.
If your app targets older versions, you can override the minSdkVersion by
adding this line to your manifest file:

```xml
<uses-sdk tools:overrideLibrary="com.otaliastudios.transcoder" />
```

## More information about internals

There is a blog post about this library written in Japanese.
http://qiita.com/yuya_presto/items/d48e29c89109b746d000

While it is Japanese, diagrams would be useful for understanding internals of this library.

## References for Android Low-Level Media APIs

- http://bigflake.com/mediacodec/
- https://github.com/google/grafika
- https://android.googlesource.com/platform/frameworks/av/+/lollipop-release/media/libstagefright
In this case you should check at runtime that API level is at least 18, before
calling any method here.

## License

This project is licensed under Apache 2.0. It consists of improvements over
the [ypresto/android-transcoder](https://github.com/ypresto/android-transcoder)
project which was licensed under Apache 2.0 as well:

```
Copyright (C) 2014-2016 Yuya Tanaka

Expand Down
31 changes: 17 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
}
}

allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}

ext {
compileSdkVersion = 28
minSdkVersion = 18
targetSdkVersion = 28
}

task clean(type: Delete) {
delete rootProject.buildDir
}
File renamed without changes.
13 changes: 6 additions & 7 deletions example/build.gradle → demo/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
compileSdkVersion rootProject.ext.compileSdkVersion

defaultConfig {
applicationId "net.ypresto.androidtranscoder.example"
minSdkVersion 18
targetSdkVersion 24
applicationId "com.otaliastudios.transcoder.demo"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
Expand All @@ -20,6 +19,6 @@ android {
}

dependencies {
compile project(':lib')
compile 'com.android.support:support-core-utils:24.2.0'
api project(':lib')
api "androidx.core:core:1.0.1"
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.ypresto.androidtranscoder.example">
xmlns:tools="http://schemas.android.com/tools"
package="com.otaliastudios.transcoder.demo">

<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
Expand All @@ -10,7 +11,8 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity
android:name=".TranscoderActivity"
android:label="@string/app_name">
Expand All @@ -22,8 +24,8 @@
</activity>

<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="net.ypresto.androidtranscoder.example.fileprovider"
android:name="androidx.core.content.FileProvider"
android:authorities="com.otaliastudios.transcoder.demo.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
Expand Down
Loading