Skip to content

Commit f247fd7

Browse files
Constant bitrate video encoding.
1 parent 4f96cb7 commit f247fd7

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

video/lib/src/main/java/org/thoughtcrime/securesms/video/videoconverter/VideoTrackConverter.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright 2024 Signal Messenger, LLC
3+
* SPDX-License-Identifier: AGPL-3.0-only
4+
*/
5+
16
package org.thoughtcrime.securesms.video.videoconverter;
27

38
import android.media.MediaCodec;
@@ -21,7 +26,6 @@
2126
import java.io.FileNotFoundException;
2227
import java.io.IOException;
2328
import java.nio.ByteBuffer;
24-
import java.util.Locale;
2529
import java.util.concurrent.atomic.AtomicReference;
2630

2731
import kotlin.Pair;
@@ -157,6 +161,7 @@ private VideoTrackConverter(
157161
// configure() call to throw an unhelpful exception.
158162
outputVideoFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
159163
outputVideoFormat.setInteger(MediaFormat.KEY_BIT_RATE, videoBitrate);
164+
outputVideoFormat.setInteger(MediaFormat.KEY_BITRATE_MODE, MediaCodecInfo.EncoderCapabilities.BITRATE_MODE_CBR);
160165
outputVideoFormat.setInteger(MediaFormat.KEY_FRAME_RATE, OUTPUT_VIDEO_FRAME_RATE);
161166
outputVideoFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, OUTPUT_VIDEO_IFRAME_INTERVAL);
162167
if (Build.VERSION.SDK_INT >= 31 && isHdr(inputVideoFormat)) {
@@ -476,15 +481,15 @@ private static String createFragmentShader(
476481
}
477482
}
478483
shader =
479-
"#extension GL_OES_EGL_image_external : require\n" +
480-
"precision mediump float;\n" + // highp here doesn't seem to matter
481-
"varying vec2 vTextureCoord;\n" +
482-
"uniform samplerExternalOES sTexture;\n" +
483-
"void main() {\n" +
484-
" gl_FragColor = (texture2D(sTexture, vTextureCoord)\n" +
485-
colorLoop.toString() +
486-
" ) / " + sum + ";\n" +
487-
"}\n";
484+
"#extension GL_OES_EGL_image_external : require\n" +
485+
"precision mediump float;\n" + // highp here doesn't seem to matter
486+
"varying vec2 vTextureCoord;\n" +
487+
"uniform samplerExternalOES sTexture;\n" +
488+
"void main() {\n" +
489+
" gl_FragColor = (texture2D(sTexture, vTextureCoord)\n" +
490+
colorLoop +
491+
" ) / " + sum + ";\n" +
492+
"}\n";
488493
}
489494
Log.i(TAG, shader);
490495
return shader;

0 commit comments

Comments
 (0)