From 1ce8097f8f0ddd970bddd45e829520dd76daaacb Mon Sep 17 00:00:00 2001 From: Frikkie Snyman <10909252+FrikkieSnyman@users.noreply.github.com> Date: Thu, 15 Oct 2026 10:19:15 +0200 Subject: [PATCH] fix(android): retry the export with a software encoder when the hardware encoder fails Some hardware encoders reject an export after opening fine: a Samsung SM-A526B (OMX.qcom.video.encoder.avc) answers the first surface frame of some clips with OMX_ErrorHardware, which Media3 reports as ERROR_CODE_ENCODING_FAILED. runTransform now runs once more with an EncoderSelector limited to non-hardware encoders when the failure comes from the video encoder, and ProcessingFailed carries Media3's error code name plus the MediaCodec.CodecException details for every attempt. MediaResult gains an optional `encoder` (":") on Android video exports. The transmux flag is gone: both branches configured the same H.264 path and the retry needs an encoder factory everywhere. Closes #11 --- README.md | 5 + .../com/mediatoolkit/HybridMediaToolkit.kt | 6 +- .../java/com/mediatoolkit/VideoProcessor.kt | 129 ++++++++++++++---- ios/HybridMediaToolkit.swift | 3 +- .../android/c++/JHybridMediaToolkitSpec.cpp | 2 +- .../generated/android/c++/JMediaResult.hpp | 11 +- .../nitro/com/mediatoolkit/MediaResult.kt | 13 +- .../ios/MediaToolkit-Swift-Cxx-Bridge.hpp | 30 ++-- .../ios/c++/HybridMediaToolkitSpecSwift.hpp | 2 +- .../generated/ios/swift/MediaResult.swift | 22 ++- nitrogen/generated/shared/c++/MediaResult.hpp | 9 +- src/MediaToolkit.nitro.ts | 5 + 12 files changed, 179 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 6701d4a..cc3191e 100644 --- a/README.md +++ b/README.md @@ -523,6 +523,7 @@ interface MediaResult { height: number; // output height in pixels duration: number; // duration in ms (0 for images) mime: string; // MIME type, e.g. 'video/mp4' + encoder?: string; // Android video exports: ':', see below } interface MediaMetadata { @@ -607,6 +608,10 @@ Standard image processing operations can cause Out-Of-Memory (OOM) exceptions wh - **Android:** Utilizes `BitmapFactory.Options.inSampleSize` to subsample the image during the hardware decoding phase, bypassing full-resolution memory allocation entirely. - **iOS:** Uses `CGImageSourceCreateThumbnailAtIndex` to instruct `ImageIO` to decode and downscale directly from the file descriptor buffer. +### Hardware encoder fallback (Android) + +Every video export tries Media3's default (hardware) encoder first. If the video encoder fails, at initialisation or mid-export (some devices reject a clip on the first frame, e.g. `OMX.qcom.video.encoder.avc` on a Samsung SM-A526B with `OMX_ErrorHardware`), the export runs once more with a software encoder before failing. `MediaResult.encoder` reports which one produced the file; a failure's message lists each attempt with Media3's error code and the `MediaCodec.CodecException` details, and logcat tag `VideoProcessor` carries the same. + ### Smart Video Compression The `compressVideo` API provides a dynamically balanced encoding strategy via the `targetSizeInMB` flag. When provided, the library will: diff --git a/android/src/main/java/com/mediatoolkit/HybridMediaToolkit.kt b/android/src/main/java/com/mediatoolkit/HybridMediaToolkit.kt index 1da9b0c..85d3867 100644 --- a/android/src/main/java/com/mediatoolkit/HybridMediaToolkit.kt +++ b/android/src/main/java/com/mediatoolkit/HybridMediaToolkit.kt @@ -276,7 +276,8 @@ class HybridMediaToolkit : HybridMediaToolkitSpec() { width = result.width, height = result.height, duration = result.duration, - mime = "audio/m4a" + mime = "audio/m4a", + encoder = result.encoder ) } } @@ -444,6 +445,7 @@ private fun Map.toMediaResult(): MediaResult { width = (this["width"] as? Number)?.toDouble() ?: 0.0, height = (this["height"] as? Number)?.toDouble() ?: 0.0, duration = (this["duration"]as? Number)?.toDouble() ?: 0.0, - mime = this["mime"] as? String ?: "" + mime = this["mime"] as? String ?: "", + encoder = this["encoder"] as? String ) } diff --git a/android/src/main/java/com/mediatoolkit/VideoProcessor.kt b/android/src/main/java/com/mediatoolkit/VideoProcessor.kt index 9f16159..263eb86 100644 --- a/android/src/main/java/com/mediatoolkit/VideoProcessor.kt +++ b/android/src/main/java/com/mediatoolkit/VideoProcessor.kt @@ -1,22 +1,29 @@ package com.margelo.nitro.com.mediatoolkit import android.content.Context +import android.media.MediaCodec import android.net.Uri +import android.util.Log import androidx.media3.common.MediaItem import androidx.media3.common.MimeTypes import androidx.media3.transformer.Composition +import androidx.media3.transformer.DefaultEncoderFactory import androidx.media3.transformer.EditedMediaItem import androidx.media3.transformer.EditedMediaItemSequence import androidx.media3.transformer.Effects +import androidx.media3.transformer.EncoderSelector +import androidx.media3.transformer.EncoderUtil import androidx.media3.transformer.ExportException import androidx.media3.transformer.ExportResult import androidx.media3.transformer.ProgressHolder import androidx.media3.transformer.Transformer +import androidx.media3.transformer.VideoEncoderSettings import androidx.media3.effect.Presentation import androidx.media3.effect.ScaleAndRotateTransformation import androidx.media3.effect.SpeedChangeEffect import androidx.media3.common.audio.SonicAudioProcessor import androidx.media3.common.util.UnstableApi +import com.google.common.collect.ImmutableList import java.io.File import java.util.UUID import java.util.concurrent.CountDownLatch @@ -27,6 +34,7 @@ import java.util.concurrent.CountDownLatch */ @UnstableApi internal object VideoProcessor { + private const val TAG = "VideoProcessor" private const val MAX_GIF_TOTAL_PIXELS = 40_000_000L // ─── TRIM ──────────────────────────────────────────────────────────────── @@ -52,7 +60,7 @@ internal object VideoProcessor { .setClippingConfiguration(clippingConfig) .build() - return runTransform(context, mediaItem, effects = Effects.EMPTY, out, onProgress, transmux = true) + return runTransform(context, mediaItem, effects = Effects.EMPTY, out, onProgress) } // ─── CROP ──────────────────────────────────────────────────────────────── @@ -120,7 +128,7 @@ internal object VideoProcessor { val effects = Effects(emptyList(), listOf(cropEffect)) // Must re-encode for crop, but only ONE pass (faster than trim then crop) - return runTransform(context, mediaItem, effects, out, onProgress, transmux = false) + return runTransform(context, mediaItem, effects, out, onProgress) } // ─── PROCESS (Trim + Crop + Flip + Rotate) ─────────────────────────────── @@ -186,11 +194,11 @@ internal object VideoProcessor { val effects = Effects(emptyList(), effectList) - // processVideo always re-encodes (transmux = false). Without an explicit bitrate, + // processVideo always re-encodes. Without an explicit bitrate, // Media3 Transformer picks a very low default, causing severe blur. // 4 Mbps balances quality vs file size — locket clips are short (2-5s) so this // keeps video sharp enough while not inflating size before compressVideo. - return runTransform(context, mediaItem, effects, out, onProgress, transmux = false, targetBitrate = 4_000_000) + return runTransform(context, mediaItem, effects, out, onProgress, targetBitrate = 4_000_000) } // ─── ROTATE ────────────────────────────────────────────────────────────── @@ -720,23 +728,69 @@ internal object VideoProcessor { // ─── Core ──────────────────────────────────────────────────────────────── + // A device whose hardware encoder rejects the export (Samsung SM-A526B, OMX.qcom.video.encoder.avc: + // OMX_ErrorHardware on the first surface frame for some clips, regardless of output size, + // orientation, colour tags or performance hints) reports the fallback through the result's + // `encoder` field and the VideoProcessor logcat lines. + private enum class EncoderAttempt { + DEFAULT, + // Media3's default selector only offers hardware encoders when the device has any. + SOFTWARE_ENCODER, + } + private fun runTransform( context: Context, mediaItem: MediaItem, effects: Effects, outputPath: String, onProgress: (Int) -> Unit, - transmux: Boolean = false, targetBitrate: Int = 0, // 0 = let Media3 decide removeAudio: Boolean = false, // true = strip audio track removeVideo: Boolean = false // true = strip video track ): Map { val outFile = File(outputPath) outFile.parentFile?.mkdirs() + + val failures = mutableListOf() + for (attempt in EncoderAttempt.values()) { + if (outFile.exists()) outFile.delete() + try { + val encoderName = export(context, mediaItem, effects, outputPath, onProgress, targetBitrate, removeAudio, removeVideo, attempt) + val encoder = "${attempt.name.lowercase()}:${encoderName ?: "none"}" + if (failures.isEmpty()) { + Log.i(TAG, "Export used $encoder") + } else { + Log.w(TAG, "Export used $encoder after: ${failures.joinToString(" || ")}") + } + return buildResult(outputPath, 0) + ("encoder" to encoder) + } catch (e: ExportException) { + failures += "${attempt.name.lowercase()}: ${describe(e)}" + if (!isVideoEncoderFailure(e)) break + Log.w(TAG, "Video encoder failed, trying the next configuration: ${failures.last()}") + } catch (e: Exception) { + failures += "${attempt.name.lowercase()}: ${e.javaClass.simpleName}: ${e.message}" + break + } + } if (outFile.exists()) outFile.delete() + throw MediaToolkitException.ProcessingFailed("Transform failed: ${failures.joinToString(" || ")}") + } + /** Runs one export and returns the name of the video encoder Media3 used, if any. */ + private fun export( + context: Context, + mediaItem: MediaItem, + effects: Effects, + outputPath: String, + onProgress: (Int) -> Unit, + targetBitrate: Int, + removeAudio: Boolean, + removeVideo: Boolean, + attempt: EncoderAttempt + ): String? { val latch = CountDownLatch(1) var exportError: Exception? = null + var videoEncoderName: String? = null val editedItemBuilder = EditedMediaItem.Builder(mediaItem) .setEffects(effects) @@ -751,6 +805,7 @@ internal object VideoProcessor { val transformerBuilder = Transformer.Builder(context) .addListener(object : Transformer.Listener { override fun onCompleted(composition: Composition, result: ExportResult) { + videoEncoderName = result.videoEncoderName latch.countDown() } override fun onError(composition: Composition, result: ExportResult, exception: ExportException) { @@ -758,26 +813,9 @@ internal object VideoProcessor { latch.countDown() } }) - - if (transmux) { - // Passthrough: remux without re-encoding — fast trim - transformerBuilder.setVideoMimeType(MimeTypes.VIDEO_H264) - } else { - if (targetBitrate > 0) { - val videoSettings = androidx.media3.transformer.VideoEncoderSettings.Builder() - .setBitrate(targetBitrate) - .build() - val encoderFactory = androidx.media3.transformer.DefaultEncoderFactory.Builder(context) - .setRequestedVideoEncoderSettings(videoSettings) - .build() - transformerBuilder.setEncoderFactory(encoderFactory) - // Use H.264: more mature encoders on Android, better bitrate compliance than HEVC. - transformerBuilder.setVideoMimeType(MimeTypes.VIDEO_H264) - } else { - transformerBuilder.setVideoMimeType(MimeTypes.VIDEO_H264) - } - } - + // Use H.264: more mature encoders on Android, better bitrate compliance than HEVC. + .setVideoMimeType(MimeTypes.VIDEO_H264) + .setEncoderFactory(buildEncoderFactory(context, targetBitrate, attempt)) val transformer = transformerBuilder.build() // Run on main thread (Media3 requirement), then wait @@ -810,9 +848,46 @@ internal object VideoProcessor { latch.await() - exportError?.let { throw MediaToolkitException.ProcessingFailed("Transform failed: ${it.message}") } + exportError?.let { throw it } + return videoEncoderName + } + + private fun buildEncoderFactory(context: Context, targetBitrate: Int, attempt: EncoderAttempt): DefaultEncoderFactory { + val settings = VideoEncoderSettings.Builder() + if (targetBitrate > 0) { + settings.setBitrate(targetBitrate) + } + val builder = DefaultEncoderFactory.Builder(context) + .setRequestedVideoEncoderSettings(settings.build()) + if (attempt == EncoderAttempt.SOFTWARE_ENCODER) { + builder.setVideoEncoderSelector(softwareVideoEncoderSelector) + } + return builder.build() + } + + private val softwareVideoEncoderSelector = EncoderSelector { mimeType -> + ImmutableList.copyOf( + EncoderUtil.getSupportedEncoders(mimeType).filterNot { EncoderUtil.isHardwareAccelerated(it, mimeType) } + ) + } + + // Covers init failures and errors MediaCodec reports asynchronously once running + // (ERROR_CODE_ENCODING_FAILED), e.g. OMX_ErrorHardware on the first input frame. + private fun isVideoEncoderFailure(e: ExportException): Boolean { + val codec = e.codecInfo ?: return false + return codec.isVideo && !codec.isDecoder + } - return buildResult(outputPath, 0) + private fun describe(e: ExportException): String { + val cause = e.cause + val causeDetails = when (cause) { + null -> null + is MediaCodec.CodecException -> + "CodecException(errorCode=${cause.errorCode}, transient=${cause.isTransient}, " + + "recoverable=${cause.isRecoverable}, diagnostic=${cause.diagnosticInfo}): ${cause.message}" + else -> "${cause.javaClass.simpleName}: ${cause.message}" + } + return listOfNotNull(ExportException.getErrorCodeName(e.errorCode), e.message, causeDetails).joinToString(" | ") } diff --git a/ios/HybridMediaToolkit.swift b/ios/HybridMediaToolkit.swift index 4c67c20..facd453 100644 --- a/ios/HybridMediaToolkit.swift +++ b/ios/HybridMediaToolkit.swift @@ -704,7 +704,8 @@ private func makeMediaResult(_ raw: [String: Any]) -> MediaResult { width: Double(raw["width"] as? Int ?? 0), height: Double(raw["height"] as? Int ?? 0), duration: Double(raw["duration"] as? Int ?? 0), - mime: raw["mime"] as? String ?? "" + mime: raw["mime"] as? String ?? "", + encoder: nil ) } diff --git a/nitrogen/generated/android/c++/JHybridMediaToolkitSpec.cpp b/nitrogen/generated/android/c++/JHybridMediaToolkitSpec.cpp index 8431532..e6e43de 100644 --- a/nitrogen/generated/android/c++/JHybridMediaToolkitSpec.cpp +++ b/nitrogen/generated/android/c++/JHybridMediaToolkitSpec.cpp @@ -53,6 +53,7 @@ namespace margelo::nitro::mediatoolkit { struct GeneratePreviewOptions; } #include #include "JMediaResult.hpp" #include +#include #include #include "ThumbnailResult.hpp" #include "JThumbnailResult.hpp" @@ -60,7 +61,6 @@ namespace margelo::nitro::mediatoolkit { struct GeneratePreviewOptions; } #include "JConcatResult.hpp" #include "MediaMetadata.hpp" #include "JMediaMetadata.hpp" -#include #include "LocationData.hpp" #include "JLocationData.hpp" #include "CropOptions.hpp" diff --git a/nitrogen/generated/android/c++/JMediaResult.hpp b/nitrogen/generated/android/c++/JMediaResult.hpp index d9781da..abb06d2 100644 --- a/nitrogen/generated/android/c++/JMediaResult.hpp +++ b/nitrogen/generated/android/c++/JMediaResult.hpp @@ -10,6 +10,7 @@ #include #include "MediaResult.hpp" +#include #include namespace margelo::nitro::mediatoolkit { @@ -43,13 +44,16 @@ namespace margelo::nitro::mediatoolkit { double duration = this->getFieldValue(fieldDuration); static const auto fieldMime = clazz->getField("mime"); jni::local_ref mime = this->getFieldValue(fieldMime); + static const auto fieldEncoder = clazz->getField("encoder"); + jni::local_ref encoder = this->getFieldValue(fieldEncoder); return MediaResult( uri->toStdString(), size, width, height, duration, - mime->toStdString() + mime->toStdString(), + encoder != nullptr ? std::make_optional(encoder->toStdString()) : std::nullopt ); } @@ -59,7 +63,7 @@ namespace margelo::nitro::mediatoolkit { */ [[maybe_unused]] static jni::local_ref fromCpp(const MediaResult& value) { - using JSignature = JMediaResult(jni::alias_ref, double, double, double, double, jni::alias_ref); + using JSignature = JMediaResult(jni::alias_ref, double, double, double, double, jni::alias_ref, jni::alias_ref); static const auto clazz = javaClassStatic(); static const auto create = clazz->getStaticMethod("fromCpp"); return create( @@ -69,7 +73,8 @@ namespace margelo::nitro::mediatoolkit { value.width, value.height, value.duration, - jni::make_jstring(value.mime) + jni::make_jstring(value.mime), + value.encoder.has_value() ? jni::make_jstring(value.encoder.value()) : nullptr ); } }; diff --git a/nitrogen/generated/android/kotlin/com/margelo/nitro/com/mediatoolkit/MediaResult.kt b/nitrogen/generated/android/kotlin/com/margelo/nitro/com/mediatoolkit/MediaResult.kt index b7e3f8a..31f7a20 100644 --- a/nitrogen/generated/android/kotlin/com/margelo/nitro/com/mediatoolkit/MediaResult.kt +++ b/nitrogen/generated/android/kotlin/com/margelo/nitro/com/mediatoolkit/MediaResult.kt @@ -35,7 +35,10 @@ data class MediaResult( val duration: Double, @DoNotStrip @Keep - val mime: String + val mime: String, + @DoNotStrip + @Keep + val encoder: String? ) { /* primary constructor */ @@ -48,6 +51,7 @@ data class MediaResult( && Objects.deepEquals(this.height, other.height) && Objects.deepEquals(this.duration, other.duration) && Objects.deepEquals(this.mime, other.mime) + && Objects.deepEquals(this.encoder, other.encoder) } override fun hashCode(): Int { @@ -57,7 +61,8 @@ data class MediaResult( width, height, duration, - mime + mime, + encoder ).contentDeepHashCode() } @@ -69,8 +74,8 @@ data class MediaResult( @Keep @Suppress("unused") @JvmStatic - private fun fromCpp(uri: String, size: Double, width: Double, height: Double, duration: Double, mime: String): MediaResult { - return MediaResult(uri, size, width, height, duration, mime) + private fun fromCpp(uri: String, size: Double, width: Double, height: Double, duration: Double, mime: String, encoder: String?): MediaResult { + return MediaResult(uri, size, width, height, duration, mime, encoder) } } } diff --git a/nitrogen/generated/ios/MediaToolkit-Swift-Cxx-Bridge.hpp b/nitrogen/generated/ios/MediaToolkit-Swift-Cxx-Bridge.hpp index daf9651..bc85f22 100644 --- a/nitrogen/generated/ios/MediaToolkit-Swift-Cxx-Bridge.hpp +++ b/nitrogen/generated/ios/MediaToolkit-Swift-Cxx-Bridge.hpp @@ -51,6 +51,21 @@ namespace MediaToolkit { class HybridMediaToolkitSpec_cxx; } */ namespace margelo::nitro::mediatoolkit::bridge::swift { + // pragma MARK: std::optional + /** + * Specialized version of `std::optional`. + */ + using std__optional_std__string_ = std::optional; + inline std::optional create_std__optional_std__string_(const std::string& value) noexcept { + return std::optional(value); + } + inline bool has_value_std__optional_std__string_(const std::optional& optional) noexcept { + return optional.has_value(); + } + inline std::string get_std__optional_std__string_(const std::optional& optional) noexcept { + return optional.value(); + } + // pragma MARK: std::shared_ptr> /** * Specialized version of `std::shared_ptr>`. @@ -107,21 +122,6 @@ namespace margelo::nitro::mediatoolkit::bridge::swift { return Func_void_std__exception_ptr_Wrapper(std::move(value)); } - // pragma MARK: std::optional - /** - * Specialized version of `std::optional`. - */ - using std__optional_std__string_ = std::optional; - inline std::optional create_std__optional_std__string_(const std::string& value) noexcept { - return std::optional(value); - } - inline bool has_value_std__optional_std__string_(const std::optional& optional) noexcept { - return optional.has_value(); - } - inline std::string get_std__optional_std__string_(const std::optional& optional) noexcept { - return optional.value(); - } - // pragma MARK: std::optional /** * Specialized version of `std::optional`. diff --git a/nitrogen/generated/ios/c++/HybridMediaToolkitSpecSwift.hpp b/nitrogen/generated/ios/c++/HybridMediaToolkitSpecSwift.hpp index 5ca053e..afb67e7 100644 --- a/nitrogen/generated/ios/c++/HybridMediaToolkitSpecSwift.hpp +++ b/nitrogen/generated/ios/c++/HybridMediaToolkitSpecSwift.hpp @@ -56,8 +56,8 @@ namespace margelo::nitro::mediatoolkit { struct LocationData; } #include "MediaResult.hpp" #include #include -#include "CropOptions.hpp" #include +#include "CropOptions.hpp" #include "CompressImageOptions.hpp" #include #include "SplitImageOptions.hpp" diff --git a/nitrogen/generated/ios/swift/MediaResult.swift b/nitrogen/generated/ios/swift/MediaResult.swift index 142241e..893b164 100644 --- a/nitrogen/generated/ios/swift/MediaResult.swift +++ b/nitrogen/generated/ios/swift/MediaResult.swift @@ -18,8 +18,14 @@ public extension MediaResult { /** * Create a new instance of `MediaResult`. */ - init(uri: String, size: Double, width: Double, height: Double, duration: Double, mime: String) { - self.init(std.string(uri), size, width, height, duration, std.string(mime)) + init(uri: String, size: Double, width: Double, height: Double, duration: Double, mime: String, encoder: String?) { + self.init(std.string(uri), size, width, height, duration, std.string(mime), { () -> bridge.std__optional_std__string_ in + if let __unwrappedValue = encoder { + return bridge.create_std__optional_std__string_(std.string(__unwrappedValue)) + } else { + return .init() + } + }()) } @inline(__always) @@ -51,4 +57,16 @@ public extension MediaResult { var mime: String { return String(self.__mime) } + + @inline(__always) + var encoder: String? { + return { () -> String? in + if bridge.has_value_std__optional_std__string_(self.__encoder) { + let __unwrapped = bridge.get_std__optional_std__string_(self.__encoder) + return String(__unwrapped) + } else { + return nil + } + }() + } } diff --git a/nitrogen/generated/shared/c++/MediaResult.hpp b/nitrogen/generated/shared/c++/MediaResult.hpp index de7b7ac..7f9d5fc 100644 --- a/nitrogen/generated/shared/c++/MediaResult.hpp +++ b/nitrogen/generated/shared/c++/MediaResult.hpp @@ -31,6 +31,7 @@ #include +#include namespace margelo::nitro::mediatoolkit { @@ -45,10 +46,11 @@ namespace margelo::nitro::mediatoolkit { double height SWIFT_PRIVATE; double duration SWIFT_PRIVATE; std::string mime SWIFT_PRIVATE; + std::optional encoder SWIFT_PRIVATE; public: MediaResult() = default; - explicit MediaResult(std::string uri, double size, double width, double height, double duration, std::string mime): uri(uri), size(size), width(width), height(height), duration(duration), mime(mime) {} + explicit MediaResult(std::string uri, double size, double width, double height, double duration, std::string mime, std::optional encoder): uri(uri), size(size), width(width), height(height), duration(duration), mime(mime), encoder(encoder) {} public: friend bool operator==(const MediaResult& lhs, const MediaResult& rhs) = default; @@ -69,7 +71,8 @@ namespace margelo::nitro { JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))), JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height"))), JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "duration"))), - JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mime"))) + JSIConverter::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mime"))), + JSIConverter>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "encoder"))) ); } static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::mediatoolkit::MediaResult& arg) { @@ -80,6 +83,7 @@ namespace margelo::nitro { obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter::toJSI(runtime, arg.height)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "duration"), JSIConverter::toJSI(runtime, arg.duration)); obj.setProperty(runtime, PropNameIDCache::get(runtime, "mime"), JSIConverter::toJSI(runtime, arg.mime)); + obj.setProperty(runtime, PropNameIDCache::get(runtime, "encoder"), JSIConverter>::toJSI(runtime, arg.encoder)); return obj; } static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) { @@ -96,6 +100,7 @@ namespace margelo::nitro { if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false; if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "duration")))) return false; if (!JSIConverter::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "mime")))) return false; + if (!JSIConverter>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "encoder")))) return false; return true; } }; diff --git a/src/MediaToolkit.nitro.ts b/src/MediaToolkit.nitro.ts index fd54163..3ff2e2c 100644 --- a/src/MediaToolkit.nitro.ts +++ b/src/MediaToolkit.nitro.ts @@ -15,6 +15,11 @@ export interface MediaResult { duration: number; /** MIME type e.g. "image/jpeg" */ mime: string; + /** + * Video encoder configuration and codec that produced the file, e.g. + * "default:OMX.qcom.video.encoder.avc" (Android video exports only) + */ + encoder?: string; } export interface LocationData {