|
1 |
| -# Note |
| 1 | +# Transcoder |
2 | 2 |
|
3 |
| -This project was forked recently from great [ypresto/android-transcoder](https://github.com/ypresto/android-transcoder). |
4 |
| -Lots of changes were made, so the information in this README is mostly false at the moment. |
| 3 | +This project is an improved fork of [ypresto/android-transcoder](https://github.com/ypresto/android-transcoder). |
| 4 | +Lots of changes were made, so the documentation must be rewritten. You can, however, take a look at the |
| 5 | +demo app which provides a working example of the new API. |
5 | 6 |
|
| 7 | +```groovy |
| 8 | +implementation 'com.otaliastudios:transcoder:0.1.0' |
| 9 | +``` |
6 | 10 |
|
7 |
| -android-transcoder |
8 |
| -================= |
9 |
| - |
10 |
| -Hardware accelerated transcoder for Android, written in pure Java. |
11 |
| - |
12 |
| -## Why? |
13 |
| - |
14 |
| -Android does not offer straight forward way to transcode video. |
15 |
| - |
16 |
| -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. |
17 |
| - |
18 |
| -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). |
19 |
| - |
20 |
| -## Requirements |
| 11 | +## Setup |
21 | 12 |
|
22 |
| -API Level 18 (Android 4.3, JELLY_BEAN_MR2) or later. |
23 |
| -If your app targets older Android, you should add below line to AndroidManifest.xml: |
| 13 | +This library requires API level 18 (Android 4.3, JELLY_BEAN_MR2) or later. |
| 14 | +If your app targets older versions, you can override the minSdkVersion by |
| 15 | +adding this line to your manifest file: |
24 | 16 |
|
25 | 17 | ```xml
|
26 |
| -<!-- Only supports API >= 18 --> |
27 | 18 | <uses-sdk tools:overrideLibrary="com.otaliastudios.transcoder" />
|
28 | 19 | ```
|
29 | 20 |
|
30 |
| -Please ensure checking Build.VERSION by your self. |
31 |
| - |
32 |
| -## Usage |
33 |
| - |
34 |
| -```java |
35 |
| -@Override |
36 |
| -protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
37 |
| - ParcelFileDescriptor parcelFileDescriptor = resolver.openFileDescriptor(data.getData(), "r"); |
38 |
| - FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); |
39 |
| - MediaTranscoder.Listener listener = new MediaTranscoder.Listener() { |
40 |
| - @Override |
41 |
| - public void onTranscodeProgress(double progress) { |
42 |
| - ... |
43 |
| - } |
44 |
| - |
45 |
| - @Override |
46 |
| - public void onTranscodeCompleted() { |
47 |
| - startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(file), "video/mp4")); |
48 |
| - ... |
49 |
| - } |
50 |
| - |
51 |
| - @Override |
52 |
| - public void onTranscodeFailed(Exception exception) { |
53 |
| - ... |
54 |
| - } |
55 |
| - }; |
56 |
| - MediaTranscoder.getInstance().transcodeVideo(fileDescriptor, file.getAbsolutePath(), |
57 |
| - MediaFormatStrategyPresets.createAndroid720pStrategy(), listener); // or createAndroid720pStrategy([your bitrate here]) |
58 |
| -} |
59 |
| -``` |
60 |
| - |
61 |
| -See `TranscoderActivity.java` in example directory for ready-made transcoder app. |
62 |
| - |
63 |
| -## Quick Setup |
64 |
| - |
65 |
| -### Gradle |
66 |
| - |
67 |
| -Available from [JCenter](https://bintray.com/bintray/jcenter), which is default repo of gradle script generated by recent android studio. |
68 |
| - |
69 |
| -```groovy |
70 |
| -repositories { |
71 |
| - jcenter() |
72 |
| -} |
73 |
| -``` |
74 |
| - |
75 |
| -```groovy |
76 |
| -compile 'net.ypresto.androidtranscoder:android-transcoder:0.2.0' |
77 |
| -``` |
78 |
| - |
79 |
| -## Note (PLEASE READ FIRST) |
80 |
| - |
81 |
| -- 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. |
82 |
| -- Currently this library does not generate streaming-aware mp4 file. |
83 |
| -Use [qtfaststart-java](https://github.com/ypresto/qtfaststart-java) to place moov atom at beginning of file. |
84 |
| -- 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). |
85 |
| -- This library does not support video files recorded by other device like digital cameras, iOS (mov files, including non-baseline profile h.264), etc. |
86 |
| - |
87 |
| - |
88 |
| -## More information about internals |
89 |
| - |
90 |
| -There is a blog post about this library written in Japanese. |
91 |
| -http://qiita.com/yuya_presto/items/d48e29c89109b746d000 |
92 |
| - |
93 |
| -While it is Japanese, diagrams would be useful for understanding internals of this library. |
94 |
| - |
95 |
| -## References for Android Low-Level Media APIs |
96 |
| - |
97 |
| -- http://bigflake.com/mediacodec/ |
98 |
| -- https://github.com/google/grafika |
99 |
| -- https://android.googlesource.com/platform/frameworks/av/+/lollipop-release/media/libstagefright |
| 21 | +In this case you should check at runtime that API level is at least 18, before |
| 22 | +calling any method here. |
100 | 23 |
|
101 | 24 | ## License
|
102 | 25 |
|
|
0 commit comments