@@ -13,12 +13,12 @@ implementation 'com.otaliastudios:transcoder:0.4.0'
1313Using Transcoder in the most basic form is pretty simple:
1414
1515``` java
16- MediaTranscoder . into(filePath)
16+ Transcoder . into(filePath)
1717 .setDataSource(context, uri) // or...
1818 .setDataSource(filePath) // or...
1919 .setDataSource(fileDescriptor) // or...
2020 .setDataSource(dataSource)
21- .setListener(new MediaTranscoder . Listener () {
21+ .setListener(new TranscoderListener () {
2222 public void onTranscodeProgress (double progress ) {}
2323 public void onTranscodeCompleted (int successCode ) {}
2424 public void onTranscodeCanceled () {}
@@ -32,6 +32,7 @@ Take a look at the demo app for a real example or keep reading below for documen
3232It features a lot of improvements over the original project, including:*
3333
3434- * Multithreading support*
35+ - * Crop to any aspect ratio*
3536- * Various bugs fixed*
3637- * [ Input] ( #data-sources ) : Accept content Uris and other types*
3738- * [ Real error handling] ( #listening-for-events ) instead of errors being thrown*
@@ -83,9 +84,9 @@ Transcoding will happen on a background thread, but we will send updates through
8384interface, which can be applied when building the request:
8485
8586``` java
86- MediaTranscoder . into(filePath)
87+ Transcoder . into(filePath)
8788 .setListenerHandler(handler)
88- .setListener(new MediaTranscoder . Listener () {
89+ .setListener(new TranscoderListener () {
8990 public void onTranscodeProgress (double progress ) {}
9091 public void onTranscodeCompleted (int successCode ) {}
9192 public void onTranscodeCanceled () {}
@@ -137,7 +138,7 @@ Validators tell the engine whether the transcoding process should start or not b
137138of the audio and video track.
138139
139140``` java
140- MediaTranscoder . into(filePath)
141+ Transcoder . into(filePath)
141142 .setValidator(validator)
142143 // ...
143144```
@@ -184,7 +185,7 @@ Output strategies return options for each track (audio or video) for the engine
184185and ** if** this track should be transcoded, and whether the whole process should be aborted.
185186
186187``` java
187- MediaTranscoder . into(filePath)
188+ Transcoder . into(filePath)
188189 .setVideoOutputStrategy(videoStrategy)
189190 .setAudioOutputStrategy(audioStrategy)
190191 // ...
@@ -217,7 +218,7 @@ The default internal strategy for audio is a `DefaultAudioStrategy`, which conve
217218audio stream to AAC format with the specified number of channels.
218219
219220``` java
220- MediaTranscoder . into(filePath)
221+ Transcoder . into(filePath)
221222 .setAudioOutputStrategy(DefaultAudioStrategy(1 )) // or..
222223 .setAudioOutputStrategy(DefaultAudioStrategy(2 )) // or..
223224 .setAudioOutputStrategy(DefaultAudioStrategy(DefaultAudioStrategy . AUDIO_CHANNELS_AS_IS ))
@@ -229,8 +230,9 @@ Take a look at the source code to understand how to manage the `android.media.Me
229230## Video Strategies
230231
231232The default internal strategy for video is a ` DefaultVideoStrategy ` , which converts the
232- video stream to AVC format and is very configurable. The class helps in defining an output size
233- that matches the aspect ratio of the input stream size, which is a basic requirement for video strategies.
233+ video stream to AVC format and is very configurable. The class helps in defining an output size.
234+ If the output size does not match the aspect ratio of the input stream size, ` Transcoder ` will
235+ crop part of the input so it matches the final ratio.
234236
235237### Video Size
236238
@@ -239,7 +241,7 @@ We provide helpers for common tasks:
239241``` java
240242DefaultVideoStrategy strategy;
241243
242- // Sets an exact size. Of course this is risky if you don't read the input size first .
244+ // Sets an exact size. If aspect ratio does not match, cropping will take place .
243245strategy = DefaultVideoStrategy . exact(1080 , 720 ). build()
244246
245247// Keeps the aspect ratio, but scales down the input size with the given fraction.
@@ -257,7 +259,8 @@ resizer. We offer handy resizers:
257259
258260| Name| Description|
259261| ----| -----------|
260- | ` ExactResizer ` | Returns the dimensions passed to the constructor. Throws if aspect ratio does not match.|
262+ | ` ExactResizer ` | Returns the exact dimensions passed to the constructor.|
263+ | ` AspectRatioResizer ` | Crops the input size to match the given aspect ratio.|
261264| ` FractionResizer ` | Reduces the input size by the given fraction (0..1).|
262265| ` AtMostResizer ` | If needed, reduces the input size so that the "at most" constraints are matched. Aspect ratio is kept.|
263266| ` PassThroughResizer ` | Returns the input size unchanged.|
@@ -269,12 +272,18 @@ You can also group resizers through `MultiResizer`, which applies resizers in ch
269272Resizer resizer = new MultiResizer ()
270273resizer. addResizer(new FractionResizer (0.5F ))
271274resizer. addResizer(new AtMostResizer (1000 ))
275+
276+ // First makes it 16:9, then ensures size is at most 1000. Order matters!
277+ Resizer resizer = new MultiResizer ()
278+ resizer. addResizer(new AspectRatioResizer (16F / 9F ))
279+ resizer. addResizer(new AtMostResizer (1000 ))
272280```
273281
274282This option is already available through the DefaultVideoStrategy builder, so you can do:
275283
276284``` java
277285DefaultVideoStrategy strategy = new DefaultVideoStrategy .Builder ()
286+ .addResizer(new AspectRatioResizer (16F / 9F ))
278287 .addResizer(new FractionResizer (0.5F ))
279288 .addResizer(new AtMostResizer (1000 ))
280289 .build()
@@ -305,7 +314,7 @@ Only a few codecs and sizes are strictly required to work.
305314We collect common presets in the ` DefaultVideoStrategies ` class:
306315
307316``` java
308- MediaTranscoder . into(filePath)
317+ Transcoder . into(filePath)
309318 .setVideoOutputStrategy(DefaultVideoStrategies . for720x1280()) // 16:9
310319 .setVideoOutputStrategy(DefaultVideoStrategies . for360x480()) // 4:3
311320 // ...
0 commit comments