From db8f5c506c3c083f059a1488635554ac4f91c05c Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Wed, 14 Jul 2021 09:13:14 +0900 Subject: [PATCH] video: keep HW acceleration for short but heavy videos --- lib/widgets/viewer/video/fijkplayer.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/widgets/viewer/video/fijkplayer.dart b/lib/widgets/viewer/video/fijkplayer.dart index 9fbbb4f99..1eea6a26f 100644 --- a/lib/widgets/viewer/video/fijkplayer.dart +++ b/lib/widgets/viewer/video/fijkplayer.dart @@ -52,6 +52,7 @@ class IjkPlayerAvesVideoController extends AvesVideoController { static const initialPlayDelay = Duration(milliseconds: 100); static const gifLikeVideoDurationThreshold = Duration(seconds: 10); + static const gifLikeBitRateThreshold = 2 << 18; // 512kB/s (4Mb/s) IjkPlayerAvesVideoController(AvesEntry entry) : super(entry) { if (!_staticInitialized) { @@ -120,7 +121,7 @@ class IjkPlayerAvesVideoController extends AvesVideoController { // playing with HW acceleration seems to skip the last frames of some videos // so HW acceleration is always disabled for GIF-like videos where the last frames may be significant - final hwAccelerationEnabled = settings.enableVideoHardwareAcceleration && (entry.durationMillis ?? 0) > gifLikeVideoDurationThreshold.inMilliseconds; + final hwAccelerationEnabled = settings.enableVideoHardwareAcceleration && !_isGifLike(); // TODO TLAD [video] flaky: HW codecs sometimes fail when seek-starting some videos, e.g. MP2TS/h264(HDPR) if (hwAccelerationEnabled) { @@ -187,6 +188,20 @@ class IjkPlayerAvesVideoController extends AvesVideoController { _instance.applyOptions(options); } + bool _isGifLike() { + // short + final durationSecs = (entry.durationMillis ?? 0) ~/ 1000; + if (durationSecs == 0) return false; + if (durationSecs > gifLikeVideoDurationThreshold.inSeconds) return false; + + // light + final sizeBytes = entry.sizeBytes; + if (sizeBytes == null) return false; + if (sizeBytes / durationSecs > gifLikeBitRateThreshold) return false; + + return true; + } + void _fetchStreams() async { final mediaInfo = await _instance.getInfo(); if (!mediaInfo.containsKey(Keys.streams)) return;