-
-
Notifications
You must be signed in to change notification settings - Fork 115
Open
Description
Current behavior
On Android, getVideoMetaData
does not take into account video orientation. A portrait video has the same width and height as a landscape one.
Expected behavior
Width and height should be reversed for portrait images vs landscape ones.
Platform
- Android
- iOS
React Native Version
0.76.6
React Native Compressor Version
1.10.3
Reproducible Steps And Demo
Looking at the code here
react-native-compressor/android/src/main/java/com/reactnativecompressor/Video/VideoMain.kt
Lines 59 to 86 in 0e316b3
fun getVideoMetaData(filePath: String, promise: Promise) { | |
var filePath: String? = filePath | |
try { | |
filePath = Utils.getRealPath(filePath, reactContext) | |
val uri = Uri.parse(filePath) | |
val srcPath = uri.path | |
val metaRetriever = MediaMetadataRetriever() | |
metaRetriever.setDataSource(srcPath) | |
val file = File(srcPath) | |
val sizeInBytes = (file.length()).toDouble() | |
val actualHeight = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)!!.toInt() | |
val actualWidth = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)!!.toInt() | |
val duration = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)!!.toDouble() | |
val creationTime = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE) | |
val extension = filePath!!.substring(filePath.lastIndexOf(".") + 1) | |
val params = Arguments.createMap() | |
params.putDouble("size", sizeInBytes) | |
params.putInt("width", actualWidth) | |
params.putInt("height", actualHeight) | |
params.putDouble("duration", duration / 1000) | |
params.putString("extension", extension) | |
params.putString("creationTime", creationTime.toString()) | |
promise.resolve(params) | |
} catch (e: Exception) { | |
promise.reject(e) | |
} | |
} | |
} |
It seems that use of METADATA_KEY_VIDEO_ROTATION
in there somewhere is necessary, similar to
Lines 107 to 117 in 0e316b3
// Handle rotation values and swapping height and width if needed | |
rotation = when (rotation) { | |
90, 270 -> { | |
val tempHeight = newHeight | |
newHeight = newWidth | |
newWidth = tempHeight | |
0 | |
} | |
180 -> 0 | |
else -> rotation | |
} |
Metadata
Metadata
Assignees
Labels
No labels