Skip to content
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

Set crop programmatically #10

Closed
LeGoffMael opened this issue Feb 23, 2021 · 21 comments
Closed

Set crop programmatically #10

LeGoffMael opened this issue Feb 23, 2021 · 21 comments

Comments

@LeGoffMael
Copy link
Owner

First, thank you for this well-build library.

Could it be possible to define the crop of the video programmatically (without user interaction) by providing a Rect object to the CropGrid for example ?

For example, I'm looking to have all my videos cropped to a square format and I would like to do this without user interaction.

Is there anyway to implements that kind of feature ?
Thank you!

@seel-channel
Copy link
Collaborator

Yes, you can. You are going to use the VideoEditorController.

final controller = VideoEditorController();

//Without notifyListeners()
controller.maxCrop = Offset(0.75, 0.75);
controller.minCrop = Offset(0.25, 0.25);

//With notifyListeners()
controller.updateCrop(Offset(0.25, 0.25), Offset(0.75, 0.75));

@LeGoffMael
Copy link
Owner Author

Indeed, the crop work nicely, I hadn't noticed that the offsets had to be between 0 and 1.

_controller = VideoEditorController.file(widget.file, trimStyle: trimStyle, cropStyle: cropStyle);

_controller.updateCrop(Offset(0.0, 0.1), Offset(1.0, 0.9));

_controller.initialize().then((_) {
  setState(() {});
});

But it looks like that the Rect size is not updated either in the CropGrid or in the TrimSlider. So the painted area is shown anyway. Like in below example the painted area is in blue.

IMG_2338

Is there a way to hide those rectangles without having to set the same background color to the rectangles and the app ?
Thank you again!

@seel-channel
Copy link
Collaborator

seel-channel commented Feb 24, 2021

The .updateCrop() has a notifyListeners(). The nofitfy is like a setState() then the widget needs to be mounted.

Exactly, the minCrop and maxCrop need to be in range between 0 and 1.0, because the view size always change. For example, the TrimSlider thumbnails view size don't the same on ScreenCrop view size also the Original Video has a other size.

//initState's using notifyListeners()
@override
void initState() {
    _controller = VideoEditorController.file(widget.file);
    _controller.initialize().then((_) {
      _controller.updateCrop(Offset(0.0, 0.1), Offset(1.0, 0.9));
      setState(() {});
    });
  }
});

//initState is not using notifyListeners()
@override
void initState() {
  _controller = VideoEditorController.file(widget.file);
  _controller.minCrop = Offset(0.0, 0.1);
  _controller.maxCrop = Offset(1.0, 0.9);
  _controller.initialize().then((_) => setState(() {}));
}

@seel-channel seel-channel reopened this Feb 24, 2021
@shamnex
Copy link

shamnex commented Feb 25, 2021

Hello @seel-channel , excellent work and it has absolutely saved my life on a project I'm working on.

I have a similar question, how do I go about making the CropGrid static with a predefined aspectRatio but enable the scale and pan gestures on the video. I'm try to achieve an effect similar to that of Instagram picker or this imagePlugin.

@seel-channel
Copy link
Collaborator

Hello @seel-channel , excellent work and it has absolutely saved my life on a project I'm working on.

I have a similar question, how do I go about making the CropGrid static with a predefined aspectRatio but enable the scale and pan gestures on the video. I'm try to achieve an effect similar to that of Instagram picker or this imagePlugin.

It don't has a way to set a preferredWidth or preferredHeight like aspectRatio. In the next update I will add this feature

@LeGoffMael
Copy link
Owner Author

The .updateCrop() has a notifyListeners(). The nofitfy is like a setState() then the widget needs to be mounted.

Exactly, the minCrop and maxCrop need to be in range between 0 and 1.0, because the view size always change. For example, the TrimSlider thumbnails view size don't the same on ScreenCrop view size also the Original Video has a other size.

//initState's using notifyListeners()
@override
void initState() {
    _controller = VideoEditorController.file(widget.file);
    _controller.initialize().then((_) {
      _controller.updateCrop(Offset(0.0, 0.1), Offset(1.0, 0.9));
      setState(() {});
    });
  }
});

//initState is not using notifyListeners()
@override
void initState() {
  _controller = VideoEditorController.file(widget.file);
  _controller.minCrop = Offset(0.0, 0.1);
  _controller.maxCrop = Offset(1.0, 0.9);
  _controller.initialize().then((_) => setState(() {}));
}

Yes and what i meant is that the video and the thumbnails are indeed cropped correctly but the extra spaces (in blue in my example) which come from the previous video size should not be displayed.

and i can't access to

_controller.minCrop = Offset(0.0, 0.1);
_controller.maxCrop = Offset(1.0, 0.9);

because there is no setters for those references.

Do you think it is something that could be fix in the next update ?
Thank you again

@shamnex
Copy link

shamnex commented Feb 25, 2021

Hello @seel-channel , excellent work and it has absolutely saved my life on a project I'm working on.
I have a similar question, how do I go about making the CropGrid static with a predefined aspectRatio but enable the scale and pan gestures on the video. I'm try to achieve an effect similar to that of Instagram picker or this imagePlugin.

It don't has a way to set a preferredWidth or preferredHeight like aspectRatio. In the next update I will add this feature

Thanks a lot man. I look forward to the next update. Would also be nice to enable gestures on the actual video as well.

Thanks for a great plugin.

@Niko-by
Copy link

Niko-by commented Mar 9, 2021

Hello @seel-channel , excellent work and it has absolutely saved my life on a project I'm working on.
I have a similar question, how do I go about making the CropGrid static with a predefined aspectRatio but enable the scale and pan gestures on the video. I'm try to achieve an effect similar to that of Instagram picker or this imagePlugin.

It don't has a way to set a preferredWidth or preferredHeight like aspectRatio. In the next update I will add this feature

Hi friend. Tell me, how soon is the update coming out with this feature? We really need the ability to set a preferredWidth or preferredHeight like aspectRatio like of this plugin image_crop This is a very cool plugin. I'm really looking forward to the update)

@seel-channel
Copy link
Collaborator

In 2 days

@Niko-by
Copy link

Niko-by commented Mar 10, 2021

In 2 days

Thank you 🙏. We count on you very much!

@seel-channel
Copy link
Collaborator

I need more time. The package crash lol

@seel-channel
Copy link
Collaborator

Yes I also have this same issue sometimes. I'll add validations for this error and I think will solve it

@GelidGeorge
Copy link

May I know the reason for this issue... though... Maybe I can fix it and send a code snippet...

@seel-channel
Copy link
Collaborator

May I know the reason for this issue... though... Maybe I can fix it and send a code snippet...

Please send me your code. I would like a lot :)

@seel-channel
Copy link
Collaborator

The FFMPEG make me crash the app. I think is a incompatible with Flutter 2.0.1. For this problem I couldn't release the new crop features

@GelidGeorge
Copy link

what if we created a native libary based on this and expose...

@GelidGeorge
Copy link

dart code...

@seel-channel
Copy link
Collaborator

Sounds really funny! But I don't have any knowledge about native libraries

@Niko-by
Copy link

Niko-by commented Mar 14, 2021

The FFMPEG make me crash the app. I think is a incompatible with Flutter 2.0.1. For this problem I couldn't release the new crop features

Can't you use the old version of FFMPEG and temporarily not switch to nullsafity? So that we can take advantage of your new functions))

By the way, yesterday the flutter_ffmpeg library was updated to version 0.4.0. Maybe they fixed the mistake, what do you think? Haven't checked it yet?

@Niko-by
Copy link

Niko-by commented Mar 17, 2021

I need more time. The package crash lol

Hi friend. Do you have news for us?

@seel-channel
Copy link
Collaborator

Done! Check the new release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants