What is the logic for determining the standard format with {vf} ?

All about user-defined episode / movie / file name format expressions
Post Reply
Rick7C2
Posts: 12
Joined: 22 Nov 2013, 23:04

What is the logic for determining the standard format with {vf} ?

Post by Rick7C2 »

I'm wondering what is the logic for determining the standard format with {vf} binding?

I'm working on an unrelated python script that I need to be able to parse the video resolution but I need the standard resolutions, not the actual resolutions in the case that the video has black bars cropped out, etc.

I know filebot handles this perfectly!

If you don't mind, could you share the logic and conditions so that I can recreate this feature for my script?

My script is only for personal use, but I understand if you don't want to share.

Thanks for maintaining filebot! No other renamer compares to it!
User avatar
rednoah
The Source
Posts: 22923
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: What is the logic for determining the standard format with {vf} ?

Post by rednoah »

e.g.

Code: Select all

resolution.steps.w: 15360 7680 3840 2040 1920  1280 1024 854 720 640 640 512 320 160
resolution.steps.h:  8640 4320 2160 1080 1080   720  576 576 480 480 360 240 240 120

Code: Select all

private final int[] ws;
private final int[] hs;

public VideoFormat() {
	this.ws = getIntArrayProperty("resolution.steps.w");
	this.hs = getIntArrayProperty("resolution.steps.h");
}

public int guessFormat(int width, int height) {
	int ns = 0;

	for (int i = 0; i < ws.length - 1; i++) {
		if ((width >= ws[i] || height >= hs[i]) || (width > ws[i + 1] && height > hs[i + 1])) {
			ns = hs[i];
			break;
		}
	}

	if (ns > 0) {
		return ns;
	}

	throw new IllegalArgumentException(String.format("Illegal resolution: [%d, %d]", width, height));
}
:idea: Please read the FAQ and How to Request Help.
kim
Power User
Posts: 1251
Joined: 15 May 2014, 16:17

Re: What is the logic for determining the standard format with {vf} ?

Post by kim »

Code: Select all

365        @Define("vf")
366        public String getVideoFormat() {
367                int w = Integer.parseInt(getMediaInfo(StreamKind.Video, 0, "Width"));
368                int h = Integer.parseInt(getMediaInfo(StreamKind.Video, 0, "Height"));
369
370                // e.g. 720p, nobody actually wants files to be tagged as interlaced, e.g. 720i
371                return String.format("%dp", VideoFormat.DEFAULT_GROUPS.guessFormat(w, h));
372        }
Docs (MediaBindingBean)
[DOCS] FileBot Groovy Expression References
Post Reply