@@ -45,8 +45,8 @@ class HardwareVideoEncoder implements VideoEncoder {
45
45
private static final int MEDIA_CODEC_RELEASE_TIMEOUT_MS = 5000 ;
46
46
private static final int DEQUEUE_OUTPUT_BUFFER_TIMEOUT_US = 100000 ;
47
47
48
- // Size of the input frames should be multiple of 16 for the H/W encoder.
49
- private static final int REQUIRED_RESOLUTION_ALIGNMENT = 16 ;
48
+ // Size of the input frames should be multiple of 2 for the H/W encoder.
49
+ private static final int REQUIRED_RESOLUTION_ALIGNMENT = 2 ;
50
50
51
51
/**
52
52
* Keeps track of the number of output buffers that have been passed down the pipeline and not yet
@@ -210,6 +210,11 @@ public VideoCodecStatus initEncode(Settings settings, Callback callback) {
210
210
this .callback = callback ;
211
211
automaticResizeOn = settings .automaticResizeOn ;
212
212
213
+ if (settings .width % REQUIRED_RESOLUTION_ALIGNMENT != 0
214
+ || settings .height % REQUIRED_RESOLUTION_ALIGNMENT != 0 ) {
215
+ Logging .e (TAG , "MediaCodec requires 2x2 alignment." );
216
+ return VideoCodecStatus .ERR_SIZE ;
217
+ }
213
218
this .width = settings .width ;
214
219
this .height = settings .height ;
215
220
useSurfaceMode = canUseSurface ();
@@ -533,6 +538,12 @@ private VideoCodecStatus resetCodec(int newWidth, int newHeight, boolean newUseS
533
538
if (status != VideoCodecStatus .OK ) {
534
539
return status ;
535
540
}
541
+
542
+ if (newWidth % REQUIRED_RESOLUTION_ALIGNMENT != 0
543
+ || newHeight % REQUIRED_RESOLUTION_ALIGNMENT != 0 ) {
544
+ Logging .e (TAG , "MediaCodec requires 2x2 alignment." );
545
+ return VideoCodecStatus .ERR_SIZE ;
546
+ }
536
547
width = newWidth ;
537
548
height = newHeight ;
538
549
useSurfaceMode = newUseSurfaceMode ;
0 commit comments