Resizing method used

HandBrake for Windows support
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
VPupkin
Posts: 8
Joined: Tue Oct 16, 2018 8:12 pm

Resizing method used

Post by VPupkin » Tue Oct 16, 2018 8:20 pm

Hello!
I need to know what algorithm is used for resizing in Handbrake, it's not written in the docs. Also I want to know whether I can hand the resizing over to corresponding option of x264, thus leaving the frame size in handbrake the same as source. Won't it cause an error?
I'm using version 1.1.1 on Windows 7 and I need a precise answer, not some guesses. So answer only if you know for sure.

User avatar
JohnAStebbins
HandBrake Team
Posts: 5214
Joined: Sat Feb 09, 2008 7:21 pm

Re: Resizing method used

Post by JohnAStebbins » Tue Oct 16, 2018 9:04 pm

lanczos

If you don't want scaling, just use a preset that doesn't scale or set the "storage dimensions" to match the source. "Production Max" and "Production Standard" presets won't scale.

You may also need to disable cropping.

libx264 doesn't do scaling. HandBrake doesn't use the x264 exe, so if you were thinking you could use the exe for scaling, you can't.

VPupkin
Posts: 8
Joined: Tue Oct 16, 2018 8:12 pm

Re: Resizing method used

Post by VPupkin » Wed Oct 17, 2018 4:43 pm

Lanczos algorithm has the amount of taps as a parameter. How many does Handbrake use? And does it depend on frame size or it is fixed?
So libx264 doesn't do scaling? I didn't know there was a different version of x264 with limited capabilities. I looked up that it's part of ffmpeg, but couldn't find its full description in the docs. Could you give me a link to it, I want to know what other limitations it has?

User avatar
JohnAStebbins
HandBrake Team
Posts: 5214
Joined: Sat Feb 09, 2008 7:21 pm

Re: Resizing method used

Post by JohnAStebbins » Wed Oct 17, 2018 5:38 pm

HandBrake uses libswscale for filtering. Looking at the code, it's not clear to me which parameter is the number of taps or if it even allows direct setting of the number of taps. The parameter that affects what swscale calls the "filterSize" is called "sizeFactor" and is set to it's default value of 6. The filterSize is then computed like this when downscaling

Code: Select all

filterSize = 1 + (sizeFactor * srcW + dstW - 1) / dstW;

User avatar
JohnAStebbins
HandBrake Team
Posts: 5214
Joined: Sat Feb 09, 2008 7:21 pm

Re: Resizing method used

Post by JohnAStebbins » Wed Oct 17, 2018 5:42 pm

x264 is not part of ffmpeg. It is it's own project. They provide a command line exe called x264 that *uses* ffmpeg libraries for decoding source files, scaling, muxing, etc. They also provide libx264 that *only* does h.264 encoding. HandBrake uses both libx264 and all the various ffmpeg libraries to do what HandBrake does.

VPupkin
Posts: 8
Joined: Tue Oct 16, 2018 8:12 pm

Re: Resizing method used

Post by VPupkin » Wed Oct 17, 2018 7:13 pm

I know that x264 is it's own project, but I thought that libx264 was a part of ffmpeg that forked from the original.
So this only encoding means all options listed in x264's help except the filtering section? Or are there more options excluded?

User avatar
JohnAStebbins
HandBrake Team
Posts: 5214
Joined: Sat Feb 09, 2008 7:21 pm

Re: Resizing method used

Post by JohnAStebbins » Wed Oct 17, 2018 8:09 pm

libx264 is the library that does the actual work of generating an h.264 bitstream from a series of input frames. Anything not directly related to generation of the h.264 bitstream comes from the x264 exe. The only definitive reference I know of is the code. If it's not an option handled in x264/common/base.c then it's not an option handled by libx264.

VPupkin
Posts: 8
Joined: Tue Oct 16, 2018 8:12 pm

Re: Resizing method used

Post by VPupkin » Thu Oct 18, 2018 7:00 pm

I see. This look strange to me. As for the exe build, I can go to the developers' binaries folder on their site and download it, but there's no trace there of this dll you are talking about. If they provide this thing, it must exist somewhere on their server, doesn't it?

mduell
Veteran User
Posts: 6153
Joined: Sat Apr 21, 2007 8:54 pm

Re: Resizing method used

Post by mduell » Thu Oct 18, 2018 8:22 pm

What dll?

User avatar
JohnAStebbins
HandBrake Team
Posts: 5214
Joined: Sat Feb 09, 2008 7:21 pm

Re: Resizing method used

Post by JohnAStebbins » Thu Oct 18, 2018 8:45 pm

A dll is a dynamic library. libx264 can be built either statically or dynamically. The exe that they distribute is linked against the static version of the library, so there is no need to build or distribute the dynamic version.

I've never looked to see if the x264 project distributes a pre-built dynamic library as it's not relevant to me or HandBrake. HandBrake builds a static version of libx264 from source. There are x264 build-time configure options you can set to force it to only build the library, which HandBrake uses.

User avatar
BradleyS
Moderator
Posts: 1401
Joined: Thu Aug 09, 2007 12:16 pm

Re: Resizing method used

Post by BradleyS » Fri Oct 19, 2018 2:12 am

HandBrake uses Lanczos 3-tap aka Lanczos3.

VPupkin
Posts: 8
Joined: Tue Oct 16, 2018 8:12 pm

Re: Resizing method used

Post by VPupkin » Fri Oct 19, 2018 11:01 am

BradleyS wrote:
Fri Oct 19, 2018 2:12 am
HandBrake uses Lanczos 3-tap aka Lanczos3.
Thanks, that's what I wanted to know in first place.
JohnAStebbins wrote:
Thu Oct 18, 2018 8:45 pm
HandBrake builds a static version of libx264 from source. There are x264 build-time configure options you can set to force it to only build the library, which HandBrake uses.
So I guess compiling either as a library or as an exe is a universal option available for any software, not just x264? This would explain why there's no special mention of this library on their site. Is this correct?

mduell
Veteran User
Posts: 6153
Joined: Sat Apr 21, 2007 8:54 pm

Re: Resizing method used

Post by mduell » Fri Oct 19, 2018 4:20 pm

No, that's nowhere near correct.

While they have developers in common, libx264 and x264cli are separate things. x264cli uses libx264 plus other software, much like HB uses libx264 and other software.

User avatar
JohnAStebbins
HandBrake Team
Posts: 5214
Joined: Sat Feb 09, 2008 7:21 pm

Re: Resizing method used

Post by JohnAStebbins » Fri Oct 19, 2018 5:38 pm

It's completely up to the developers how they structure their code. But it's a common development practice to have a core library or set of libraries for a project that one or more tools are built around. A project will often, but not always, have a core library or libraries that they build things around.

For x264, libx264 is the core library and x264.exe is the tool. For ffmpeg, libavcodec, libavformat, libavutil, libavfilter, libswscale, etc (there are several more) are the core libraries. ffmpeg, ffprobe, and ffplay are the tools built around these libraries. For HandBrake, the core library is libhandbrake and the tools are HandBrakeCLI and the 3 different GUIs for windows, osx, and linux.

Projects also use external libraries (i.e. libraries of code not developed or maintained by that project). x264 uses libavcodec, libavformat, libavutil, libswscale, etc from the ffmpeg project as external libraries when building x264.exe, but these libraries are not included as part of the functionality that is provided by libx264. ffmpeg project uses libx264 as an external library when building libavcodec. So libavcodec (when configured to do so at build time) includes support for h.264 encoding through the use of libx264 external library.

As you can see there is a lot sharing of libraries that goes every which way.

VPupkin
Posts: 8
Joined: Tue Oct 16, 2018 8:12 pm

Re: Resizing method used

Post by VPupkin » Fri Oct 19, 2018 6:27 pm

That's a good comprehensive explanation, thank you. These peculiarities are often mentioned, but almost never explained, thus making an impression that developers are deliberately confusing the users.

Post Reply