OpenShot / openshot-qt

OpenShot Video Editor is an award-winning free and open-source video editor for Linux, Mac, and Windows, and is dedicated to delivering high quality video editing and animation solutions to the world.
http://www.openshot.org
Other
4.25k stars 531 forks source link

Crop and Mask / Adding mask to the cropped video #4543

Open senoalvrtsyan opened 2 years ago

senoalvrtsyan commented 2 years ago

Question: When I'm cropping part of video, then applying mask onto the video, it's being added to the whole video including the cropped part). How can I apply mask to only visible part of video (not on whole video including cropped part)? I want mask to be scaled only in visible part of video.

Note: If I understood correctly, openshot's crop effect did not actually crops the video, but it just makes the cropped part transparent and that's the reason that mask applied to the whole area of clip ( event on cropped part ). If I'm correct, is it possible to achieve to that result ? Or maybe there is a real cropping functionality in openshot ?

System Details:

JacksonRG commented 2 years ago

Could you include a screen shot and if possible small example project (Just enough to reproduce the bug) As I'm having trouble reproducing this.

senoalvrtsyan commented 2 years ago

@JacksonRG okay, so in the first screenshot you can see my cropped video. On the second one as you can see I applied a mask (for debugging purposes I enabled "Replace Imange" toggle). As you can see mask applied to the whole area of clip, even on cropped part, but what I want is mask to be applied only visible part of the video(I expected it to be scaled to only visible part).

1

2

JacksonRG commented 2 years ago

Interesting.. Could you confirm your version? Should be in Help->About Openshot

I noticed you said 2.6.2 I guessed that was a typo, as our current stable release is 2.6.1

Also, thanks for the images. They do clear some things up. For one thing I was confused when you said mask as that's the name of an effect we have. But I see that the whirlpool isn't fitting onto the scaled video. I'm asking around if we currently have a way to do that.

If not, It'll make a nice addition

JacksonRG commented 2 years ago

@senoalvrtsyan A partial solution: change the Scale X property of the cropped video so it centers in the frame, and then the whirlpool will be in a more correct position on that clip.

Still looking into cropping transitions.

senoalvrtsyan commented 2 years ago

@JacksonRG thanks for the response. So my version is 2.0.6-dev. You were correct, it was typo.

Also I'm using libopenshot for some video editing and using the openshot-qt for investigating the features we have in openshot at all.

And my use case is following: I have for example 4 videos and I just want to get composite video from that 4 videos and also I have requirement according which videos should have specific sizes. So I'm changing it's location, scaling it and also cropping. After doing all that I want to make final videos' corners rounded and here is why I'm using mask ( created by me ).

senoalvrtsyan commented 2 years ago

Here is the example video I'm talking about. To be more clear, I just want to make corners of videos rounded. Applied following mask, but as I have already mentioned, when I'm applying crop effect, the mask is not being scaled accordingly.

Custom mask created by me: maskk

Example video:

https://user-images.githubusercontent.com/22573172/142661592-ce9d325c-ed34-4acd-8973-512610290c8c.mp4

senoalvrtsyan commented 2 years ago

@JacksonRG I have prepared small example which demonstrates above mentioned issue. It works for any kind of input video.

What I'm doing:

  1. Applying crop effect to clip
  2. Applying mask for making video's corners rounded (I have posted mask in my previous comment) As a result, I didn't get what I wanted.

After some investigation, I understood, what cropping just replaced cropped part with transparent pixels, but the videos dimensions remain the same and mask is being scaled and applied to the original size, not the cropped part.

Can you suggest any solution for this scenario ?

int main()
{
    openshot::Timeline timeLine(1280, 1024, openshot::Fraction(30, 1), kSampleRate, kNumChannels, openshot::ChannelLayout::LAYOUT_STEREO);
    timeLine.Open();

    auto* clip = new openshot::Clip("videos/vertical-1.mp4");

    auto* crop = new Crop(0, 0.3, 0, 0.3);
    crop->Layer(1);
    crop->Order(1);

    auto* mask = new openshot::Mask(new openshot::ImageReader("videos/maskk.png"), 0, 3);
    mask->Layer(2);
    mask->Order(2);

    clip->AddEffect(crop);
    clip->AddEffect(mask);

    timeLine.AddClip(clip);

    openshot::FFmpegWriter w("videos/output.mp4");
    w.SetAudioOptions(true, "libvorbis", kSampleRate, kNumChannels, openshot::ChannelLayout::LAYOUT_STEREO, 128000);
    w.SetVideoOptions(true, "libx264" , openshot::Fraction(30, 1),  1280, 1024, openshot::Fraction(1,1), false, false, 1600000);
    w.Open();
    w.WriteFrame(&timeLine, 0, 5 * 30);

    // Close the reader & writer
    timeLine.Close();
    w.Close();
    return 0;
}
JacksonRG commented 2 years ago

Still looking into it. But you might try cropping, and exporting the video at either a vertical resolution, or rotated 90 degrees. That way the clip you're dealing with will have the right dimensions for applying a mask to

senoalvrtsyan commented 2 years ago

@JacksonRG that might be solution, but I don't want to go with that way for some reasons. First one is that I'll have huge performance loss if I export all videos after cropping, then create a composite videos from that. Second reason is that during whole video, I might need to crop with different params using keyframes, so I have to create as much videos as much crop keyframes I have (with appropriate start and end). Also I'll lose the animations between keyframes.

What if instead of getting the frame size in GetFrame function, we get frameSize * cropFactor if there is cropping effect ? If we do that way, Mask will be scaled with correct frame size.

senoalvrtsyan commented 2 years ago

@JacksonRG any updates on this ?

jonoomph commented 1 year ago

Sorry for the delay in responding to this issue. I agree that the Crop effect needs to be modified to actually modify the frame's pixel size... instead of the current transparent pixel approach. Effects are processed in order, so if the crop effect was applied first (and actually reduced the # of pixels in the frame's image), then the remaining pixels would be send to subsequent effects, and so on. We will track this feature request in our Trello board, and will hopefully get to it shortly. Thx!