mpv: sample aspect ratio

This commit is contained in:
Thibault Deckers 2023-07-16 01:15:17 +02:00
parent 017264d2bc
commit 043b2c54aa
5 changed files with 44 additions and 35 deletions

View file

@ -34,9 +34,9 @@ extension ExtraAvesEntryProps on AvesEntry {
bool get isSized => width > 0 && height > 0; bool get isSized => width > 0 && height > 0;
Size videoDisplaySize(double sar) { Size videoDisplaySize(double? sar) {
final size = displaySize; final size = displaySize;
if (sar != 1) { if (sar != null && sar != 1) {
final dar = displayAspectRatio * sar; final dar = displayAspectRatio * sar;
final w = size.width; final w = size.width;
final h = size.height; final h = size.height;

View file

@ -197,7 +197,7 @@ class _EntryPageViewState extends State<EntryPageView> with SingleTickerProvider
final videoController = context.read<VideoConductor>().getController(entry); final videoController = context.read<VideoConductor>().getController(entry);
if (videoController == null) return const SizedBox(); if (videoController == null) return const SizedBox();
return ValueListenableBuilder<double>( return ValueListenableBuilder<double?>(
valueListenable: videoController.sarNotifier, valueListenable: videoController.sarNotifier,
builder: (context, sar, child) { builder: (context, sar, child) {
final videoDisplaySize = entry.videoDisplaySize(sar); final videoDisplaySize = entry.videoDisplaySize(sar);

View file

@ -102,7 +102,7 @@ abstract class AvesVideoController {
ValueNotifier<bool> get canSelectStreamNotifier; ValueNotifier<bool> get canSelectStreamNotifier;
ValueNotifier<double> get sarNotifier; ValueNotifier<double?> get sarNotifier;
bool get isMuted; bool get isMuted;

View file

@ -46,7 +46,7 @@ class IjkVideoController extends AvesVideoController {
final ValueNotifier<bool> canSelectStreamNotifier = ValueNotifier(false); final ValueNotifier<bool> canSelectStreamNotifier = ValueNotifier(false);
@override @override
final ValueNotifier<double> sarNotifier = ValueNotifier(1); final ValueNotifier<double?> sarNotifier = ValueNotifier(null);
Stream<FijkValue> get _valueStream => _valueStreamController.stream; Stream<FijkValue> get _valueStream => _valueStreamController.stream;
@ -115,7 +115,7 @@ class IjkVideoController extends AvesVideoController {
_startListening(); _startListening();
} }
sarNotifier.value = 1; sarNotifier.value = null;
streams.clear(); streams.clear();
_applyOptions(startMillis); _applyOptions(startMillis);
@ -380,12 +380,12 @@ class IjkVideoController extends AvesVideoController {
@override @override
Widget buildPlayerWidget(BuildContext context) { Widget buildPlayerWidget(BuildContext context) {
return ValueListenableBuilder<double>( return ValueListenableBuilder<double?>(
valueListenable: sarNotifier, valueListenable: sarNotifier,
builder: (context, sar, child) { builder: (context, sar, child) {
// derive DAR (Display Aspect Ratio) from SAR (Storage Aspect Ratio), if any // derive DAR (Display Aspect Ratio) from SAR (Storage Aspect Ratio), if any
// e.g. 960x536 (~16:9) with SAR 4:3 should be displayed as ~2.39:1 // e.g. 960x536 (~16:9) with SAR 4:3 should be displayed as ~2.39:1
final dar = entry.displayAspectRatio * sar; final dar = entry.displayAspectRatio * (sar ?? 1);
return FijkView( return FijkView(
player: _instance, player: _instance,
fit: FijkFit( fit: FijkFit(
@ -397,7 +397,8 @@ class IjkVideoController extends AvesVideoController {
panelBuilder: (player, data, context, viewSize, texturePos) => const SizedBox(), panelBuilder: (player, data, context, viewSize, texturePos) => const SizedBox(),
color: Colors.transparent, color: Colors.transparent,
); );
}); },
);
} }
Alignment _alignmentForRotation(int rotation) { Alignment _alignmentForRotation(int rotation) {

View file

@ -37,7 +37,7 @@ class MpvVideoController extends AvesVideoController {
final ValueNotifier<bool> canSelectStreamNotifier = ValueNotifier(false); final ValueNotifier<bool> canSelectStreamNotifier = ValueNotifier(false);
@override @override
final ValueNotifier<double> sarNotifier = ValueNotifier(1); final ValueNotifier<double?> sarNotifier = ValueNotifier(null);
MpvVideoController( MpvVideoController(
super.entry, { super.entry, {
@ -81,6 +81,7 @@ class MpvVideoController extends AvesVideoController {
if (status == VideoStatus.idle) return; if (status == VideoStatus.idle) return;
_statusStreamController.add(v ? VideoStatus.playing : VideoStatus.paused); _statusStreamController.add(v ? VideoStatus.playing : VideoStatus.paused);
})); }));
_subscriptions.add(_instance.stream.videoParams.listen((v) => sarNotifier.value = v.par));
_subscriptions.add(_instance.stream.log.listen((v) => debugPrint('libmpv log: $v'))); _subscriptions.add(_instance.stream.log.listen((v) => debugPrint('libmpv log: $v')));
_subscriptions.add(_instance.stream.error.listen((v) => debugPrint('libmpv error: $v'))); _subscriptions.add(_instance.stream.error.listen((v) => debugPrint('libmpv error: $v')));
_subscriptions.add(settings.updateStream.where((event) => event.key == SettingKeys.enableVideoHardwareAccelerationKey).listen((_) => _initController())); _subscriptions.add(settings.updateStream.where((event) => event.key == SettingKeys.enableVideoHardwareAccelerationKey).listen((_) => _initController()));
@ -203,17 +204,24 @@ class MpvVideoController extends AvesVideoController {
@override @override
Widget buildPlayerWidget(BuildContext context) { Widget buildPlayerWidget(BuildContext context) {
// TODO TLAD handle SAR / DAR (media_kit Player.stream.width/height just gives raw video size, not rendered size) return ValueListenableBuilder<double?>(
valueListenable: sarNotifier,
builder: (context, sar, child) {
// derive DAR (Display Aspect Ratio) from SAR (Storage Aspect Ratio), if any
// e.g. 960x536 (~16:9) with SAR 4:3 should be displayed as ~2.39:1
final dar = entry.displayAspectRatio * (sar ?? 1);
return Video( return Video(
controller: _controller, controller: _controller,
fit: BoxFit.cover, fill: Colors.transparent,
alignment: Alignment.center, aspectRatio: dar,
controls: NoVideoControls, controls: NoVideoControls,
wakelock: false, wakelock: false,
subtitleViewConfiguration: const SubtitleViewConfiguration( subtitleViewConfiguration: const SubtitleViewConfiguration(
style: TextStyle(color: Colors.transparent), style: TextStyle(color: Colors.transparent),
), ),
); );
},
);
} }
// streams (aka tracks) // streams (aka tracks)