From 55999305ed914eba5220e281412bce08ac634068 Mon Sep 17 00:00:00 2001 From: "zach.liu" Date: Mon, 8 Aug 2016 16:06:56 +0800 Subject: [PATCH 01/16] Process specified device sps nal data Test in p7 phone. --- .../net/ypresto/androidtranscoder/utils/AvcCsdUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/utils/AvcCsdUtils.java b/lib/src/main/java/net/ypresto/androidtranscoder/utils/AvcCsdUtils.java index d458f66c..eb929d1b 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/utils/AvcCsdUtils.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/utils/AvcCsdUtils.java @@ -29,6 +29,8 @@ public class AvcCsdUtils { private static final byte[] AVC_START_CODE_4 = {0x00, 0x00, 0x00, 0x01}; // Refer: http://www.cardinalpeak.com/blog/the-h-264-sequence-parameter-set/ private static final byte AVC_SPS_NAL = 103; // 0<<7 + 3<<5 + 7<<0 + // https://tools.ietf.org/html/rfc6184 + private static final byte AVC2_SPS_NAL = 39; // 0<<7 + 1<<5 + 7<<0 /** * @return ByteBuffer contains SPS without NAL header. @@ -40,9 +42,12 @@ public static ByteBuffer getSpsBuffer(MediaFormat format) { prefixedSpsBuffer.flip(); skipStartCode(prefixedSpsBuffer); - if (prefixedSpsBuffer.get() != AVC_SPS_NAL) { + + byte spsNalData = prefixedSpsBuffer.get(); + if (spsNalData != AVC_SPS_NAL && spsNalData != AVC2_SPS_NAL) { throw new IllegalStateException("Got non SPS NAL data."); } + return prefixedSpsBuffer.slice(); } From 762429ebcc0b2fe18e34f3dde1f3b5153b43b818 Mon Sep 17 00:00:00 2001 From: "zach.liu" Date: Thu, 18 Aug 2016 16:18:41 +0800 Subject: [PATCH 02/16] add handle avc sps nal data --- .../net/ypresto/androidtranscoder/utils/AvcCsdUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/utils/AvcCsdUtils.java b/lib/src/main/java/net/ypresto/androidtranscoder/utils/AvcCsdUtils.java index eb929d1b..049296b9 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/utils/AvcCsdUtils.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/utils/AvcCsdUtils.java @@ -30,7 +30,8 @@ public class AvcCsdUtils { // Refer: http://www.cardinalpeak.com/blog/the-h-264-sequence-parameter-set/ private static final byte AVC_SPS_NAL = 103; // 0<<7 + 3<<5 + 7<<0 // https://tools.ietf.org/html/rfc6184 - private static final byte AVC2_SPS_NAL = 39; // 0<<7 + 1<<5 + 7<<0 + private static final byte AVC_SPS_NAL_2 = 39; // 0<<7 + 1<<5 + 7<<0 + private static final byte AVC_SPS_NAL_3 = 71; // 0<<7 + 2<<5 + 7<<0 /** * @return ByteBuffer contains SPS without NAL header. @@ -44,7 +45,7 @@ public static ByteBuffer getSpsBuffer(MediaFormat format) { skipStartCode(prefixedSpsBuffer); byte spsNalData = prefixedSpsBuffer.get(); - if (spsNalData != AVC_SPS_NAL && spsNalData != AVC2_SPS_NAL) { + if (spsNalData != AVC_SPS_NAL && spsNalData != AVC_SPS_NAL_2 && spsNalData != AVC_SPS_NAL_3) { throw new IllegalStateException("Got non SPS NAL data."); } From d3ab8766062d3326056a4be4834c68ea701a21c3 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Wed, 20 Jul 2016 17:50:21 +1000 Subject: [PATCH 03/16] Close stream before calling listener events --- .../java/net/ypresto/androidtranscoder/MediaTranscoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/MediaTranscoder.java b/lib/src/main/java/net/ypresto/androidtranscoder/MediaTranscoder.java index 3a758677..7ec32bc9 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/MediaTranscoder.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/MediaTranscoder.java @@ -123,20 +123,20 @@ public void onTranscodeProgress(double progress) { @Override public void onTranscodeCompleted() { - listener.onTranscodeCompleted(); closeStream(); + listener.onTranscodeCompleted(); } @Override public void onTranscodeCanceled() { - listener.onTranscodeCanceled(); closeStream(); + listener.onTranscodeCanceled(); } @Override public void onTranscodeFailed(Exception exception) { - listener.onTranscodeFailed(exception); closeStream(); + listener.onTranscodeFailed(exception); } private void closeStream() { From de24f3bca7e3fc6f4222f5416d690d48bde874e2 Mon Sep 17 00:00:00 2001 From: Yuya Tanaka Date: Fri, 9 Sep 2016 20:42:36 +0900 Subject: [PATCH 04/16] Bump to 0.2.0 --- CHANGELOG.md | 14 ++++++++++++++ README.md | 2 +- lib/build.gradle | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..91622669 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +## 0.2.0 +- Experimental audio transcoding support. (Thanks @aaron112) +- Fix transcode does not run on Huawei Ascend P7. (Thanks @spiritedRunning) +- Fix race condition caused by not closing output before callback. (Thanks @ryanwilliams83) + + +## 0.1.10 +- `Future` support. (Thanks @MaiKambayashi) + +## 0.1.X +- Stability updates. (Thanks @ozyozyo) + +## 0.1.0 +- First release. diff --git a/README.md b/README.md index df1bb947..fb14a1f0 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ repositories { ``` ```groovy -compile 'net.ypresto.androidtranscoder:android-transcoder:0.1.10' +compile 'net.ypresto.androidtranscoder:android-transcoder:0.2.0' ``` ## Note (PLEASE READ FIRST) diff --git a/lib/build.gradle b/lib/build.gradle index dfc02d9e..1b6e8f17 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -32,7 +32,7 @@ android { publish { groupId = 'net.ypresto.androidtranscoder' artifactId = 'android-transcoder' - version = '0.1.10-SNAPSHOT' + version = '0.2.0' licences = ['Apache-2.0'] website = 'https://github.com/ypresto/android-transcoder' autoPublish = false From 39cbb94cb03a72b57536299d7009defd4a983018 Mon Sep 17 00:00:00 2001 From: Yuya Tanaka Date: Fri, 9 Sep 2016 21:52:53 +0900 Subject: [PATCH 05/16] Add audio constants, fix javadoc error --- .../androidtranscoder/format/MediaFormatStrategyPresets.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/format/MediaFormatStrategyPresets.java b/lib/src/main/java/net/ypresto/androidtranscoder/format/MediaFormatStrategyPresets.java index 99fc9b90..30802586 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/format/MediaFormatStrategyPresets.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/format/MediaFormatStrategyPresets.java @@ -16,6 +16,9 @@ package net.ypresto.androidtranscoder.format; public class MediaFormatStrategyPresets { + public static final int AUDIO_BITRATE_AS_IS = -1; + public static final int AUDIO_CHANNELS_AS_IS = -1; + /** * @deprecated Use {@link #createExportPreset960x540Strategy()}. */ @@ -45,7 +48,7 @@ public static MediaFormatStrategy createAndroid720pStrategy(int bitrate) { /** * Preset based on Nexus 4 camera recording with 720p quality. * This preset is ensured to work on any Android >=4.3 devices by Android CTS (if codec is available). - *

+ *
* Note: audio transcoding is experimental feature. * * @param bitrate Preferred bitrate for video encoding. From bdf9db30e51aa7a8c782781f82e3cdc5e1fb216c Mon Sep 17 00:00:00 2001 From: Yuya Tanaka Date: Fri, 9 Sep 2016 22:51:09 +0900 Subject: [PATCH 06/16] Fix FileUriExposedException on Android 7.0 --- example/build.gradle | 1 + example/src/main/AndroidManifest.xml | 20 ++++++++++++++++--- .../example/TranscoderActivity.java | 12 +++++++++-- example/src/main/res/xml/file_paths.xml | 6 ++++++ lib/src/main/res/values/strings.xml | 2 -- 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 example/src/main/res/xml/file_paths.xml delete mode 100644 lib/src/main/res/values/strings.xml diff --git a/example/build.gradle b/example/build.gradle index e0179e52..3aae2cce 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -21,4 +21,5 @@ android { dependencies { compile project(':lib') + compile 'com.android.support:support-core-utils:24.2.0' } diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index 19c33591..498d9288 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -1,21 +1,35 @@ + package="net.ypresto.androidtranscoder.example"> + + + android:theme="@style/AppTheme"> + android:label="@string/app_name"> + + + + diff --git a/example/src/main/java/net/ypresto/androidtranscoder/example/TranscoderActivity.java b/example/src/main/java/net/ypresto/androidtranscoder/example/TranscoderActivity.java index f67f1543..7e08566b 100644 --- a/example/src/main/java/net/ypresto/androidtranscoder/example/TranscoderActivity.java +++ b/example/src/main/java/net/ypresto/androidtranscoder/example/TranscoderActivity.java @@ -7,6 +7,7 @@ import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.os.SystemClock; +import android.support.v4.content.FileProvider; import android.util.Log; import android.view.Menu; import android.view.MenuItem; @@ -26,6 +27,7 @@ public class TranscoderActivity extends Activity { private static final String TAG = "TranscoderActivity"; + private static final String FILE_PROVIDER_AUTHORITY = "net.ypresto.androidtranscoder.example.fileprovider"; private static final int REQUEST_CODE_PICK = 1; private static final int PROGRESS_BAR_MAX = 1000; private Future mFuture; @@ -55,7 +57,10 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { final File file; if (resultCode == RESULT_OK) { try { - file = File.createTempFile("transcode_test", ".mp4", getExternalFilesDir(null)); + File outputDir = new File(getExternalFilesDir(null), "outputs"); + //noinspection ResultOfMethodCallIgnored + outputDir.mkdir(); + file = File.createTempFile("transcode_test", ".mp4", outputDir); } catch (IOException e) { Log.e(TAG, "Failed to create temporary file.", e); Toast.makeText(this, "Failed to create temporary file.", Toast.LENGTH_LONG).show(); @@ -89,7 +94,10 @@ public void onTranscodeProgress(double progress) { public void onTranscodeCompleted() { Log.d(TAG, "transcoding took " + (SystemClock.uptimeMillis() - startTime) + "ms"); onTranscodeFinished(true, "transcoded file placed on " + file, parcelFileDescriptor); - startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(file), "video/mp4")); + Uri uri = FileProvider.getUriForFile(TranscoderActivity.this, FILE_PROVIDER_AUTHORITY, file); + startActivity(new Intent(Intent.ACTION_VIEW) + .setDataAndType(uri, "video/mp4") + .setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)); } @Override diff --git a/example/src/main/res/xml/file_paths.xml b/example/src/main/res/xml/file_paths.xml new file mode 100644 index 00000000..5b254ecc --- /dev/null +++ b/example/src/main/res/xml/file_paths.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/lib/src/main/res/values/strings.xml b/lib/src/main/res/values/strings.xml deleted file mode 100644 index 85420055..00000000 --- a/lib/src/main/res/values/strings.xml +++ /dev/null @@ -1,2 +0,0 @@ - - From f7d57123cc573adfcb57a3b8ad5be1b653de4480 Mon Sep 17 00:00:00 2001 From: Yuya Tanaka Date: Fri, 9 Sep 2016 23:51:21 +0900 Subject: [PATCH 07/16] Add reference to qiita post --- README.md | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fb14a1f0..2d72b83d 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,20 @@ Use [qtfaststart-java](https://github.com/ypresto/qtfaststart-java) to place moo - 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. + +## 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 + ## License ``` @@ -95,9 +109,3 @@ 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. ``` - -## 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 From a5ecf0a27505d3e4c297e772e5d61c2473ee260c Mon Sep 17 00:00:00 2001 From: Veneet Reddy Date: Thu, 8 Jun 2017 12:45:07 +0530 Subject: [PATCH 08/16] Updated gradle and build tools versions --- build.gradle | 2 +- example/build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 ++-- lib/build.gradle | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index e220f0b8..ea98e44f 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.2' + classpath 'com.android.tools.build:gradle:2.3.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/example/build.gradle b/example/build.gradle index 3aae2cce..8560676b 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 24 - buildToolsVersion "24.0.1" + buildToolsVersion '25.0.0' defaultConfig { applicationId "net.ypresto.androidtranscoder.example" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d14f516d..9555d195 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Mar 09 14:43:12 JST 2015 +#Thu Jun 08 12:40:11 IST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/lib/build.gradle b/lib/build.gradle index 1b6e8f17..fe6550f9 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -12,7 +12,7 @@ apply plugin: 'bintray-release' android { compileSdkVersion 24 - buildToolsVersion "24.0.1" + buildToolsVersion '25.0.2' defaultConfig { minSdkVersion 18 From ba45be5e8a2490829effad6441b87e06fe10c89d Mon Sep 17 00:00:00 2001 From: Veneet Reddy Date: Sat, 16 Sep 2017 01:22:40 +0530 Subject: [PATCH 09/16] Bump build tools version to latest --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ea98e44f..59660130 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.3.2' + 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 From cfd083ae2929ddb3589d4120abf549eee1df06fb Mon Sep 17 00:00:00 2001 From: Veneet Reddy Date: Sat, 16 Sep 2017 01:23:47 +0530 Subject: [PATCH 10/16] Remove swallowed exception in runPipelines --- .../androidtranscoder/engine/MediaTranscoderEngine.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaTranscoderEngine.java b/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaTranscoderEngine.java index 64a1edef..e56e307b 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaTranscoderEngine.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaTranscoderEngine.java @@ -180,7 +180,7 @@ public void onDetermineOutputFormat() { mExtractor.selectTrack(trackResult.mAudioTrackIndex); } - private void runPipelines() { + private void runPipelines() throws InterruptedException { long loopCount = 0; if (mDurationUs <= 0) { double progress = PROGRESS_UNKNOWN; @@ -199,11 +199,7 @@ private void runPipelines() { if (mProgressCallback != null) mProgressCallback.onProgress(progress); } if (!stepped) { - try { - Thread.sleep(SLEEP_TO_WAIT_TRACK_TRANSCODERS); - } catch (InterruptedException e) { - // nothing to do - } + Thread.sleep(SLEEP_TO_WAIT_TRACK_TRANSCODERS); } } } From bfe280795f224b16a047f389809c7150ee05d574 Mon Sep 17 00:00:00 2001 From: hkurokawa Date: Wed, 8 Aug 2018 17:09:19 +0900 Subject: [PATCH 11/16] Parse the geographic location coordinates in the video file and pass the values to the muxer. --- .../utils/ISO6709LocationParserTest.java | 35 ++++++++++++++++++ .../engine/MediaTranscoderEngine.java | 17 +++++++-- .../utils/ISO6709LocationParser.java | 37 +++++++++++++++++++ 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 lib/src/androidTest/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParserTest.java create mode 100644 lib/src/main/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParser.java diff --git a/lib/src/androidTest/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParserTest.java b/lib/src/androidTest/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParserTest.java new file mode 100644 index 00000000..a1a9caae --- /dev/null +++ b/lib/src/androidTest/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParserTest.java @@ -0,0 +1,35 @@ +package net.ypresto.androidtranscoder.utils; + +import junit.framework.TestCase; + +public class ISO6709LocationParserTest extends TestCase { + public void testParse() { + ISO6709LocationParser parser = new ISO6709LocationParser(); + assertEquals(new float[]{35.658632f, 139.745411f}, parser.parse("+35.658632+139.745411/")); + assertEquals(new float[]{40.75f, -074.00f}, parser.parse("+40.75-074.00/")); + // with Altitude + assertEquals(new float[]{-90f, +0f}, parser.parse("-90+000+2800/")); + assertEquals(new float[]{27.5916f, 086.5640f}, parser.parse("+27.5916+086.5640+8850/")); + // ranged data + assertEquals(new float[]{35.331f, 134.224f}, parser.parse("+35.331+134.224/+35.336+134.228/")); + assertEquals(new float[]{35.331f, 134.224f}, parser.parse("+35.331+134.224/+35.336+134.228/+35.333+134.229/+35.333+134.227/")); + } + + public void testParseFailure() { + ISO6709LocationParser parser = new ISO6709LocationParser(); + assertNull(parser.parse(null)); + assertNull(parser.parse("")); + assertNull(parser.parse("35 deg 65' 86.32\" N, 139 deg 74' 54.11\" E")); + assertNull(parser.parse("+35.658632")); + assertNull(parser.parse("+35.658632-")); + assertNull(parser.parse("40.75-074.00")); + assertNull(parser.parse("+40.75-074.00.00")); + } + + private static void assertEquals(float[] expected, float[] actual) { + assertEquals(expected.length, actual.length); + for (int i = 0; i < expected.length; i++) { + assertTrue(Float.compare(expected[i], actual[i]) == 0); + } + } +} \ No newline at end of file diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaTranscoderEngine.java b/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaTranscoderEngine.java index e56e307b..3abdbaf5 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaTranscoderEngine.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaTranscoderEngine.java @@ -19,9 +19,12 @@ import android.media.MediaFormat; import android.media.MediaMetadataRetriever; import android.media.MediaMuxer; +import android.os.Build; import android.util.Log; +import net.ypresto.androidtranscoder.BuildConfig; import net.ypresto.androidtranscoder.format.MediaFormatStrategy; +import net.ypresto.androidtranscoder.utils.ISO6709LocationParser; import net.ypresto.androidtranscoder.utils.MediaExtractorUtils; import java.io.FileDescriptor; @@ -137,9 +140,17 @@ private void setupMetadata() throws IOException { // skip } - // TODO: parse ISO 6709 - // String locationString = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_LOCATION); - // mMuxer.setLocation(Integer.getInteger(rotationString, 0)); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + String locationString = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_LOCATION); + if (locationString != null) { + float[] location = new ISO6709LocationParser().parse(locationString); + if (location != null) { + mMuxer.setLocation(location[0], location[1]); + } else { + Log.d(TAG, "Failed to parse the location metadata: " + locationString); + } + } + } try { mDurationUs = Long.parseLong(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)) * 1000; diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParser.java b/lib/src/main/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParser.java new file mode 100644 index 00000000..273007d3 --- /dev/null +++ b/lib/src/main/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParser.java @@ -0,0 +1,37 @@ +package net.ypresto.androidtranscoder.utils; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ISO6709LocationParser { + private final Pattern pattern; + + public ISO6709LocationParser() { + this.pattern = Pattern.compile("([+\\-][0-9.]+)([+\\-][0-9.]+)"); + } + + /** + * This method parses the given string representing a geographic point location by coordinates in ISO 6709 format + * and returns the latitude and the longitude in float. If location is not in ISO 6709 format, + * this method returns null + * + * @param location a String representing a geographic point location by coordinates in ISO 6709 format + * @return null if the given string is not as expected, an array of floats with size 2, + * where the first element represents latitude and the second represents longitude, otherwise. + */ + public float[] parse(String location) { + if (location == null) return null; + Matcher m = pattern.matcher(location); + if (m.find() && m.groupCount() == 2) { + String latstr = m.group(1); + String lonstr = m.group(2); + try { + float lat = Float.parseFloat(latstr); + float lon = Float.parseFloat(lonstr); + return new float[]{lat, lon}; + } catch (NumberFormatException ignored) { + } + } + return null; + } +} From c17dd6d500e0121bcc47812a9e3a91eb4e4cfc97 Mon Sep 17 00:00:00 2001 From: Yuya Tanaka Date: Sun, 12 Aug 2018 01:11:24 +0900 Subject: [PATCH 12/16] Add Google maven repo --- build.gradle | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 59660130..13089606 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,10 @@ buildscript { repositories { jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' @@ -15,5 +19,9 @@ buildscript { allprojects { repositories { jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } } From 012c3ab81053c17eea0ec42f2ec815cb7ad311be Mon Sep 17 00:00:00 2001 From: Yuya Tanaka Date: Sun, 12 Aug 2018 01:14:02 +0900 Subject: [PATCH 13/16] Bump to 0.3.0 --- CHANGELOG.md | 5 ++++- lib/build.gradle | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91622669..a79483bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,12 @@ +## 0.3.0 +- Fix cancel() sometimes not working. (Thanks @strayerM and @PinkFloyded) +- Geolocation support on API>=19. (Thanks @hkurokawa) + ## 0.2.0 - Experimental audio transcoding support. (Thanks @aaron112) - Fix transcode does not run on Huawei Ascend P7. (Thanks @spiritedRunning) - Fix race condition caused by not closing output before callback. (Thanks @ryanwilliams83) - ## 0.1.10 - `Future` support. (Thanks @MaiKambayashi) diff --git a/lib/build.gradle b/lib/build.gradle index fe6550f9..1ab6c7ba 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -32,7 +32,7 @@ android { publish { groupId = 'net.ypresto.androidtranscoder' artifactId = 'android-transcoder' - version = '0.2.0' + version = '0.3.0' licences = ['Apache-2.0'] website = 'https://github.com/ypresto/android-transcoder' autoPublish = false From 6261e729be8cfd164b87d60df49e97f51cec96f8 Mon Sep 17 00:00:00 2001 From: shts Date: Wed, 13 Feb 2019 13:13:49 +0900 Subject: [PATCH 14/16] Make available high profile --- .../androidtranscoder/engine/MediaFormatValidator.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaFormatValidator.java b/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaFormatValidator.java index 67ea5ba8..73136bc4 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaFormatValidator.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaFormatValidator.java @@ -26,6 +26,7 @@ class MediaFormatValidator { // Refer: http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC#Profiles private static final byte PROFILE_IDC_BASELINE = 66; + private static final byte PROFILE_IDC_HI = 100; public static void validateVideoOutputFormat(MediaFormat format) { String mime = format.getString(MediaFormat.KEY_MIME); @@ -36,7 +37,8 @@ public static void validateVideoOutputFormat(MediaFormat format) { } ByteBuffer spsBuffer = AvcCsdUtils.getSpsBuffer(format); byte profileIdc = AvcSpsUtils.getProfileIdc(spsBuffer); - if (profileIdc != PROFILE_IDC_BASELINE) { + boolean availableProfile = (profileIdc == PROFILE_IDC_BASELINE || profileIdc == PROFILE_IDC_HI); + if (!availableProfile) { throw new InvalidOutputFormatException("Non-baseline AVC video profile is not supported by Android OS, actual profile_idc: " + profileIdc); } } From df7ee275c652f18876babb8951541ec15a6037c9 Mon Sep 17 00:00:00 2001 From: shts Date: Tue, 7 May 2019 11:15:05 +0900 Subject: [PATCH 15/16] Remove profile validation --- .../engine/MediaFormatValidator.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaFormatValidator.java b/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaFormatValidator.java index 73136bc4..6182ee60 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaFormatValidator.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/engine/MediaFormatValidator.java @@ -18,15 +18,8 @@ import android.media.MediaFormat; import net.ypresto.androidtranscoder.format.MediaFormatExtraConstants; -import net.ypresto.androidtranscoder.utils.AvcCsdUtils; -import net.ypresto.androidtranscoder.utils.AvcSpsUtils; - -import java.nio.ByteBuffer; class MediaFormatValidator { - // Refer: http://en.wikipedia.org/wiki/H.264/MPEG-4_AVC#Profiles - private static final byte PROFILE_IDC_BASELINE = 66; - private static final byte PROFILE_IDC_HI = 100; public static void validateVideoOutputFormat(MediaFormat format) { String mime = format.getString(MediaFormat.KEY_MIME); @@ -35,12 +28,6 @@ public static void validateVideoOutputFormat(MediaFormat format) { if (!MediaFormatExtraConstants.MIMETYPE_VIDEO_AVC.equals(mime)) { throw new InvalidOutputFormatException("Video codecs other than AVC is not supported, actual mime type: " + mime); } - ByteBuffer spsBuffer = AvcCsdUtils.getSpsBuffer(format); - byte profileIdc = AvcSpsUtils.getProfileIdc(spsBuffer); - boolean availableProfile = (profileIdc == PROFILE_IDC_BASELINE || profileIdc == PROFILE_IDC_HI); - if (!availableProfile) { - throw new InvalidOutputFormatException("Non-baseline AVC video profile is not supported by Android OS, actual profile_idc: " + profileIdc); - } } public static void validateAudioOutputFormat(MediaFormat format) { From c5ac813c19609c0d4eeb3bc75fc607239789dc96 Mon Sep 17 00:00:00 2001 From: Ed Johnson Date: Wed, 31 Oct 2018 12:30:40 -0700 Subject: [PATCH 16/16] fix audio output validation to validate on the output format, not the input format --- .../ypresto/androidtranscoder/engine/AudioTrackTranscoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/main/java/net/ypresto/androidtranscoder/engine/AudioTrackTranscoder.java b/lib/src/main/java/net/ypresto/androidtranscoder/engine/AudioTrackTranscoder.java index 47e0a61d..99034ef0 100644 --- a/lib/src/main/java/net/ypresto/androidtranscoder/engine/AudioTrackTranscoder.java +++ b/lib/src/main/java/net/ypresto/androidtranscoder/engine/AudioTrackTranscoder.java @@ -79,7 +79,7 @@ public void setup() { @Override public MediaFormat getDeterminedFormat() { - return mInputFormat; + return mActualOutputFormat; } @Override