android-transcoder


Source link: https://github.com/ypresto/android-transcoder

android-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 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.

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:

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

Please ensure checking Build.VERSION by your self.

Usage

@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, which is default repo of gradle script generated by recent android studio.

repositories {

 jcenter() 
}
compile 'net.ypresto.androidtranscoder:android-transcoder:0.2.0'

Note (PLEASE READ FIRST)

  • This library raises RuntimeExceptions (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 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 for parameters guaranteed by CTS.
  • This library does not support video files recorded by other device like digital cameras, iOS (mov files, including non-baseline profile h.264), etc.

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

License

Copyright (C) 2014-2016 Yuya Tanaka  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

ToolTips is an Open Source Android library that allows developers to easily display tooltips for views.

A bottom sheet component for Android.

PermissionsDispatcher provides simple annotation-based API to handle runtime permissions in Android M.

Reactive SharedPreferences for Android.

FilterSelectorListView is useful for making multiple selection with see selection on the top of ListView.

Beautify your RecyclerViews with a great parallax effect !

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes