mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 12:07:28 +00:00
Use variable bitrate mode when transcoding to ensure compatibility with old devices (#5223)
* Use variable bitrate mode when transcoding This should be compatible with more devices that may lack the needed codecs to properly encode using constant bitrate mode (CBR). * Fix video output size (again)
This commit is contained in:
committed by
GitHub
parent
2535b08004
commit
fa755e5b75
+1
-1
@@ -123,8 +123,8 @@ class ThumbnailFactory @Inject constructor(
|
||||
val thumbnailResult = ThumbnailResult(
|
||||
file = thumbnailFile,
|
||||
info = ThumbnailInfo(
|
||||
height = bitmapThumbnail.height.toLong(),
|
||||
width = bitmapThumbnail.width.toLong(),
|
||||
height = bitmapThumbnail.height.toLong(),
|
||||
mimetype = mimeTypeToThumbnailMimeType(mimeType),
|
||||
size = thumbnailFile.length()
|
||||
),
|
||||
|
||||
+5
-10
@@ -61,8 +61,8 @@ class VideoCompressor @Inject constructor(
|
||||
val width = metadata?.width ?: Int.MAX_VALUE
|
||||
val height = metadata?.height ?: Int.MAX_VALUE
|
||||
|
||||
val videoResizeEffect = videoCompressorConfig.videoCompressorHelper?.let {
|
||||
val outputSize = it.getOutputSize(Size(width, height))
|
||||
val videoResizeEffect = run {
|
||||
val outputSize = videoCompressorConfig.videoCompressorHelper.getOutputSize(Size(width, height))
|
||||
if (metadata?.rotation == 90 || metadata?.rotation == 270) {
|
||||
// If the video is rotated, we need to swap width and height
|
||||
Presentation.createForWidthAndHeight(
|
||||
@@ -89,19 +89,14 @@ class VideoCompressor @Inject constructor(
|
||||
val inputMediaItem = MediaItem.fromUri(uri)
|
||||
val outputMediaItem = EditedMediaItem.Builder(inputMediaItem)
|
||||
.setFrameRate(newFrameRate)
|
||||
.run {
|
||||
if (videoResizeEffect != null) {
|
||||
setEffects(Effects(emptyList(), listOf(videoResizeEffect)))
|
||||
} else {
|
||||
this
|
||||
}
|
||||
}
|
||||
.setEffects(Effects(emptyList(), listOf(videoResizeEffect)))
|
||||
.build()
|
||||
|
||||
val encoderFactory = DefaultEncoderFactory.Builder(context)
|
||||
.setRequestedVideoEncoderSettings(
|
||||
VideoEncoderSettings.Builder()
|
||||
.setBitrateMode(MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_CBR)
|
||||
// Use VBR which is generally better for quality and compatibility, although slightly worse for file size
|
||||
.setBitrateMode(MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_VBR)
|
||||
.setBitrate(newBitrate)
|
||||
.build()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user