Skip to content

Linux review #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: cropping on LInux
  • Loading branch information
bdlukaa committed Nov 18, 2023
commit 056d8fb738f7c4c228fc9c7655a6c61355f51b2e
1 change: 1 addition & 0 deletions linux/build/.last_build_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c940b8f00ebd22e24987f560b6caa906
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
library unity_video_player_main;

import 'dart:async';
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -331,11 +332,22 @@ class UnityVideoPlayerMediaKit extends UnityVideoPlayer {
@override
Future<void> resetCrop() => crop(-1, -1, -1);

/// Crops the current video into a box at the given row and column
@override
Future<void> crop(int row, int col, int size) async {
final player = mkPlayer.platform as NativePlayer;
if (row == -1 && col == -1 && size == -1) {
player.setProperty('video-crop', '0x0+0+0');
// On linux, the mpv binaries used come from the distros (sudo apt install mpv ...)
// As of now (18 nov 2023), the "video-crop" parameter is not supported on
// most distros. In this case, there is the "vf=crop" parameter that does
// the same thing. "video-crop" is preferred on the other platforms because
// of its performance.

if (row == -1 || col == -1 || size == -1) {
if (Platform.isLinux) {
player.setProperty('vf', 'crop=0:0:0:0');
} else {
player.setProperty('video-crop', '0x0+0+0');
}
_isCropped = false;
} else if (width != null && height != null) {
final tileWidth = maxSize.width / size;
Expand All @@ -348,15 +360,28 @@ class UnityVideoPlayerMediaKit extends UnityVideoPlayer {
tileHeight,
);

debugPrint('Index | row=$row | col=$col | viewport=$viewportRect');

player.setProperty(
'video-crop',
'${viewportRect.width.toInt()}x'
'${viewportRect.height.toInt()}+'
'${viewportRect.left.toInt()}+'
'${viewportRect.top.toInt()}',
debugPrint(
'Cropping | row=$row | col=$col | size=$maxSize | viewport=$viewportRect',
);

if (Platform.isLinux) {
player.setProperty(
'vf',
'crop='
'${viewportRect.width.toInt()}:'
'${viewportRect.height.toInt()}:'
'${viewportRect.left.toInt()}:'
'${viewportRect.top.toInt()}',
);
} else {
player.setProperty(
'video-crop',
'${viewportRect.width.toInt()}x'
'${viewportRect.height.toInt()}+'
'${viewportRect.left.toInt()}+'
'${viewportRect.top.toInt()}',
);
}
_isCropped = true;
}
}
Expand Down