cdgriffith / FastFlix

FastFlix is a free GUI for H.264, HEVC and AV1 hardware and software encoding!
https://fastflix.org/
MIT License
1.13k stars 55 forks source link

[Feature Request] Implement auto cropping via cropdetect #81

Closed HannesJo0139 closed 3 years ago

HannesJo0139 commented 3 years ago

Hi! First of all: Thank U so much again for your great work! I just updated from v2.4 to v3 and I am really really happy. Its gettin a really awesome piece of software.

Another great feature would be an auto cropping detection. In the moment I'm doing it by hand with the command ffplay -ss 600 -i movie.mkv -t 10 -vf cropdetect What do U think about it?

cdgriffith commented 3 years ago

Honestly didn't know FFmpeg had that feature, will look into it!

loungebob commented 3 years ago

lol I load the video in handbrake, read the cropping stats and manually add them to fastflix. not very convenient but totally doable.

cdgriffith commented 3 years ago

I am working on adding this now, and initial version in develop branch. autocrop

I don't have it run on start as I am running it on a point-in-time based off what the user has entered for start time (or 10% in if start time is 0). But could be a configurable options in settings to always autocrop on load, would that be useful?

One bug I have right now is if you crop and scale the video (say from 4K to 1080p) will be stretched, so need to calculate scale properly when crop is enabled. But seems fine if not chaging the resolution.

cdgriffith commented 3 years ago

Added in 3.2.0

loungebob commented 3 years ago

Tried on 2 files and seems to work fine. Detected the proper crop. Although it did say -1 in vertical resolution, the file produced was showing the correct resolution.

cdgriffith commented 3 years ago

Glad it's working!

-1 just means "base the height off the width", aka "keep the aspect ratio", and it's only actually passed to ffmpeg if the width is changed. Need to document / make that clearer. Maybe change it to display "Auto"

HannesJo0139 commented 3 years ago

I don't have it run on start as I am running it on a point-in-time based off what the user has entered for start time (or 10% in if start time is 0). But could be a configurable options in settings to always autocrop on load, would that be useful?

Its really awesome how fast you have implemented it! I think that 10% or start time thing fits most needs out there. In very rare cases there are movies having sequences with different crop. May be possible to extend the analysis to match these cases too. But yeah, maybe it would be more of a gimmick that hardly anyone needs.

HannesJo0139 commented 3 years ago

So I have tested it several times now and sometimes I get invalid values. Eg on Star Wars Episode 1 it detects "crop=3840:1312:0:546". I have no idea how cropdetect exactly works but it seems to have problems on very dark scenes. If I change the start time to let's say 1h, it correctly detects crop=3840:1600:0:280.

Setting a very early start time larger 0, when image is still dark, croptdetect fails and throws an error due to detected image width <1.

So maybe a little more optimization, sth like collecting multiple crop values and a basic plausibility check would be a good idea.

cdgriffith commented 3 years ago

Good to know there are still some issues. I have it currently detecting across 10 frames, but could probably expand that to a few seconds worth for safety.