donmelton/video_transcoding

Proposal to no longer constrain detected crop results

donmelton opened this issue ยท 20 comments

Proposal to no longer constrain detected crop results

In the past, I've been adamant that cropping video for transcoding is not about making the edges of the output look pretty. My rationale was that those "black" edges are not visible anyway when viewed full screen. For me, cropping was about improving performance, not aesthetics.

So, I designed the detect-crop tool and the --crop detect function of transcode-video to determine what I believed to be the "optimal" shape for a crop. The algorithm for this shape would only crop a minimum number of pixels, and always from either the top and bottom or from the left and right, never from both axes.

But I now believe it's a much better practice to remove all the "black" edges around the video when transcoding. Of course, there are a few exceptions for irregularly cropped movies like "The Dark Knight (2008)" and "The Grand Budapest Hotel (2014)."

Why did I change my mind? After transcoding thousands of videos, I can identify more than just a few where leaving "black" edges causes annoying artifacts as x264 tries to encode the actual boundary of the content next to the remaining edge. This can be both noticeable and distracting, lowering the perceived quality of the output.

Currently, both the detect-crop tool and the --crop detect function of transcode-video can be configured to ignore the "optimal" shape algorithm. This is done via the --no-constrain and --no-constrain-crop options. So, I propose to make that the default behavior. However, I would still allow access to that "optimal" shape algorithm via new --constrain and --constrain-crop options.

The --help output of detect-crop would change to:

    --constrain     constrain crop to optimal shape

And the --help output of transcode-video would change to:

    --crop T:B:L:R  set video crop values (default: 0:0:0:0)
                      (use `--crop detect` for `detect-crop` behavior)
                      (use `--crop auto` for `HandBrakeCLI` behavior)
    --constrain-crop
                    constrain `--crop detect` to optimal shape

Of course, the old --no-constrain and --no-constrain-crop options would continue to be allowed, undocumented, until the next major revision. But they wouldn't actually do anything since that would be the default behavior anyway.

So, I'm asking for feedback. Let me know what you think. Soon. Because I'm liable to implement this as early as next week since the change is trivial due to the way I've architected the code. Basically, it's just flipping a boolean and changing the documentation. The hardest work will be re-writing the README document.

Thanks.

BTW, there is a downside to changing the default behavior. Unambiguous crop values are less likely since any disagreements between HandBrakeCLI and mplayer will no longer be obscured by the "optimal" shape algorithm.

JMoVS commented

Well, I always transcoded thismway and was very happy and weclome this change.

Does this mean that the detect-crop auto behavior option of transcode-video would also reflect that change?

@JMoVS Yes, the --crop detect option in transcode-video would also no longer constrain to the optimal shape by default. And you would have to use a new --constrain-crop option to get the old behavior. Hopefully that's exactly what you want.

JMoVS commented

Yes indeed, I want to always use the unconstrained crop. So this sounds like a very welcome change to me! ๐Ÿ‘

As one of your less technical and, as a result, possibly even more grateful, followers, is it possible to automatically chose the most conservative crop option in the cases where one runs into differing results from the two programs?

That's what I've been doing manually whenever there are differing crop values.

No matter what you choose to implement, thanks again for doing the heavy lifting.

Best,
Plato

Get Outlook for iOShttps://aka.ms/o0ukef


From: JMoVS <notifications@github.commailto:notifications@github.com>
Sent: Sunday, September 11, 2016 8:50 PM
Subject: Re: [donmelton/video_transcoding] Proposal to no longer constrain detected crop results (#81)
To: donmelton/video_transcoding <video_transcoding@noreply.github.commailto:video_transcoding@noreply.github.com>

Yes indeed, I want to always use the unconstrained crop. So this sounds like a very welcome change to me! ?

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com//issues/81#issuecomment-246237600, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AOepbe4LaxaPVW66pMdr5GC0P4t3Re8Jks5qpMwGgaJpZM4J6EMf.

t089 commented

Fully agree, I also think it is better to always remove all the black lines from the video. In the end, the black lines are no content, an "implementation detail", the encoder should not be bothered with.

JMoVS commented

Platonium: this can sometimes still lead to more being cropped than should be. I had movies where both mplayer and handbrake cropped too much, just in different directions. So I guess this is something that should at least be discussed on how this is handled.

@platonium The problem with automatically picking the most conservative crop between the two choices provided by HandBrakeCLI and mplayer is that sometimes mplayer returns a result of 0:0:0:0, or no crop at all. And it's impossible to tell programmatically whether it's being prudent, as is the case with "The Dark Knight (2008)," or just being stupid, as is the case with dozens of other movies.

That's why I never use any of the automatic cropping behaviors myself, even though I provide them for my users. I always manually review the choices provided by HandBrakeCLI and mplayer before I transcode. I've learned over the years that you just can't trust either one of them all the time.

And, BTW, you are very welcome! It's my pleasure to do the heavy lifting. I'm glad the software is working for you.

@t089 Glad to hear it. Thanks. Yeah, I suspected there were many users like yourself and @JMoVS who were, it turns out, smartly ignoring my orginal advice and cropping away the black edges. :)

I've been using --no-constrain-crop every time I use detect-crop, so Im find with it being the default.

@cameronks Cool. That's yet another vote for the change. Thanks! :)

I crop away all black edges also.

@gingerbeardman Great! Thanks for the feedback. This is starting to look unanimous. :)

The only other thing I try to do is maintain the correct aspect ratio.

@gingerbeardman Maintaining aspect ratio shouldn't be a problem as long as you're not using the --720p option or otherwise changing the size of the output.

This is a welcome change from my perspective. Thumbs up!

@RodBrown1988 Thanks and you are very welcome! The code is done and now I'm just writing the documentation. I'll probably release it tonight.

Makes sense. Thanks for all your work and thanks for asking.

@dennya You are very welcome, sir!

OK, folks. I released version 0.11.0 with this change. Just gem update to get it.

Thank you all!