Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getVideoMetaData doesn't take into account video rotation #332

Open
1 of 2 tasks
andrejpavlovic opened this issue Jan 21, 2025 · 1 comment
Open
1 of 2 tasks

getVideoMetaData doesn't take into account video rotation #332

andrejpavlovic opened this issue Jan 21, 2025 · 1 comment

Comments

@andrejpavlovic
Copy link

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

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

// 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
}

Copy link

👋 @andrejpavlovic
Thanks for opening your issue here! If you find this package useful hit the star🌟!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant