Avidemux Forum

Avidemux => Main version 2.6 => Topic started by: autoCropPlease on December 30, 2020, 09:49:20 PM

Title: Auto Crop via py-scripting
Post by: autoCropPlease on December 30, 2020, 09:49:20 PM
Is there a way to auto crop videos via py-scripting? I've searched through the forum but couldn't find the answer :'(

To crop a video via scripting, I need to do this:

adm.addVideoFilter("crop", "top=0", "bottom=0", "left=240", "right=240", "rubber_is_hidden=False")

The problem is that there may be a lot of videos with bigger or lesser black borders that I need to auto crop as a batch.

It would be great to be able to do something like this:

adm.addVideoFilter("crop", "top=0", "bottom=0", "left=auto", "right=auto", "frame=2", "rubber_is_hidden=False")
Title: Re: Auto Crop via py-scripting
Post by: eumagga0x2a on December 30, 2020, 10:55:18 PM
Autocrop evaluates the currently loaded preview image in the filter preview of the "crop" filter, it is useless without human supervision and intervention.
Title: Re: Auto Crop via py-scripting
Post by: autoCropPlease on December 31, 2020, 09:48:22 AM
Quote from: eumagga0x2a on December 30, 2020, 10:55:18 PMAutocrop evaluates the currently loaded preview image in the filter preview of the "crop" filter, it is useless without human supervision and intervention.
Hi, eumagga0x2a,

Thank you for your reply.

It becomes useful in case I'm sure that each of my videos has consistent black borders across all its frames.

"The currently loaded preview image" is just a frame, right? "frame=2" in my previous post's imaginative example means "evaluate the second frame of each video and auto crop it according to that frame".
Title: Re: Auto Crop via py-scripting
Post by: eumagga0x2a on December 31, 2020, 09:58:17 AM
Quote from: autoCropPlease on December 31, 2020, 09:48:22 AMt becomes useful in case I'm sure that each of my videos has consistent black borders across all its frames.

Are you really sure? I'm not. A lot of videos start black. A lot of black bars contain noise or broadcaster's logo.

Additionally, I would generally advise against cropping for the purpose of removing black bars except of the case of converting hi-res source to standard-resolution DVD video. By all means, avoid non-standard resolutions and display aspect ratios.
Title: Re: Auto Crop via py-scripting
Post by: eumagga0x2a on December 31, 2020, 10:07:24 AM
Something like detectBlackBars(uint64_t time, uint32_t *top, uint32_t *bottom, uint32_t *left, uint32_t *right) function, exposed via internal python interface, might make sense, however. Maybe :-)
Title: Re: Auto Crop via py-scripting
Post by: autoCropPlease on December 31, 2020, 10:14:40 AM
eumagga0x2a,

My use case revolves around fullscreen recording browser games (they tend to have different aspect ratios which leads to bigger or lesser black borders). Recording while in Chrome's fullscreen mode means consistent pitch-black borders across all the frames, plus I never start with a blank black screen.

Seems like a valid use case to me ^_^

Quote from: eumagga0x2a on December 31, 2020, 10:07:24 AMSomething like detectBlackBars(uint64_t time, uint32_t *top, uint32_t *bottom, uint32_t *left, uint32_t *right) function, exposed via internal python interface, might make sense, however. Maybe :-)
This is interesting!
Title: Re: Auto Crop via py-scripting
Post by: eumagga0x2a on December 31, 2020, 10:17:50 AM
Just please don't expect it already in 2.7.7 release :-)
Title: Re: Auto Crop via py-scripting
Post by: eumagga0x2a on December 31, 2020, 10:19:16 AM
(IMHO there is nothing wrong with black bars, really)
Title: Re: Auto Crop via py-scripting
Post by: autoCropPlease on December 31, 2020, 10:20:35 AM
Quote from: eumagga0x2a on December 31, 2020, 10:17:50 AMJust please don't expect it already in 2.7.7 release :-)
2.7.8 maybe? :D

OK, I'm not pushing :)
Title: Re: Auto Crop via py-scripting
Post by: eumagga0x2a on December 31, 2020, 10:22:36 AM
For now: https://ffmpeg.org/ffmpeg-filters.html#cropdetect
Title: Re: Auto Crop via py-scripting
Post by: autoCropPlease on December 31, 2020, 01:13:39 PM
Quote from: eumagga0x2a on December 31, 2020, 10:22:36 AMFor now: https://ffmpeg.org/ffmpeg-filters.html#cropdetect
Wow, thank you, eumagga0x2a! :)