|
43 | 43 | import static io.appium.settings.recorder.RecorderConstant.NO_TIMESTAMP_SET; |
44 | 44 | import static io.appium.settings.recorder.RecorderConstant.NO_TRACK_INDEX_SET; |
45 | 45 | import static io.appium.settings.recorder.RecorderConstant.RECORDING_DEFAULT_VIDEO_MIME_TYPE; |
| 46 | +import static io.appium.settings.recorder.RecorderConstant.VIDEO_CODEC_DEFAULT_FRAME_RATE; |
46 | 47 |
|
47 | 48 | public class RecorderThread implements Runnable { |
48 | 49 |
|
@@ -115,14 +116,14 @@ public boolean isRecordingRunning() { |
115 | 116 |
|
116 | 117 | @RequiresApi(api = Build.VERSION_CODES.KITKAT) |
117 | 118 | private MediaFormat initVideoEncoderFormat(String videoMime, int videoWidth, |
118 | | - int videoHeight, int videoBitrate) { |
| 119 | + int videoHeight, int videoBitrate, |
| 120 | + int videoFrameRate) { |
119 | 121 | MediaFormat encoderFormat = MediaFormat.createVideoFormat(videoMime, videoWidth, |
120 | 122 | videoHeight); |
121 | 123 | encoderFormat.setInteger(MediaFormat.KEY_COLOR_FORMAT, |
122 | 124 | MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface); |
123 | 125 | encoderFormat.setInteger(MediaFormat.KEY_BIT_RATE, videoBitrate); |
124 | | - encoderFormat.setInteger(MediaFormat.KEY_FRAME_RATE, |
125 | | - RecorderConstant.VIDEO_CODEC_FRAME_RATE); |
| 126 | + encoderFormat.setInteger(MediaFormat.KEY_FRAME_RATE, videoFrameRate); |
126 | 127 | encoderFormat.setInteger(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER, |
127 | 128 | RecorderConstant.AUDIO_CODEC_REPEAT_PREV_FRAME_AFTER_MS); |
128 | 129 | encoderFormat.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, |
@@ -240,9 +241,9 @@ private long getPresentationTimeUs() { |
240 | 241 | - startTimestampUs); |
241 | 242 | } |
242 | 243 |
|
243 | | - private int calculateBitRate(int width, int height) { |
| 244 | + private int calculateBitRate(int width, int height, int frameRate) { |
244 | 245 | final int bitrate = (int) (RecorderConstant.BITRATE_MULTIPLIER * |
245 | | - RecorderConstant.VIDEO_CODEC_FRAME_RATE * width * height); |
| 246 | + frameRate * width * height); |
246 | 247 | Log.i(TAG, String.format("Recording starting with bitrate=%5.2f[Mbps]", |
247 | 248 | bitrate / 1024f / 1024f)); |
248 | 249 | return bitrate; |
@@ -354,12 +355,15 @@ public void run() { |
354 | 355 | .getCodecInfo().getCapabilitiesForType(RECORDING_DEFAULT_VIDEO_MIME_TYPE) |
355 | 356 | .getVideoCapabilities(); |
356 | 357 |
|
| 358 | + int videoFrameRate = Math.min(VIDEO_CODEC_DEFAULT_FRAME_RATE, |
| 359 | + videoEncoderCapabilities.getSupportedFrameRates().getUpper()); |
| 360 | + |
357 | 361 | int videoBitrate = videoEncoderCapabilities.getBitrateRange() |
358 | | - .clamp(calculateBitRate(this.videoWidth, this.videoHeight)); |
| 362 | + .clamp(calculateBitRate(this.videoWidth, this.videoHeight, videoFrameRate)); |
359 | 363 |
|
360 | 364 | MediaFormat videoEncoderFormat = |
361 | 365 | initVideoEncoderFormat(RECORDING_DEFAULT_VIDEO_MIME_TYPE, |
362 | | - this.videoWidth, this.videoHeight, videoBitrate); |
| 366 | + this.videoWidth, this.videoHeight, videoBitrate, videoFrameRate); |
363 | 367 |
|
364 | 368 | videoEncoder.configure(videoEncoderFormat, null, null, |
365 | 369 | MediaCodec.CONFIGURE_FLAG_ENCODE); |
|
0 commit comments