Skip to content

Commit dc30692

Browse files
committed
rewrite the crop code to allow for 16:9 cropping (to pull 16:9 stuff out of a 4:3 recording), along with an out_aspect override setting to force the output aspect ratio (for codecs that support it).
1 parent e0bccb6 commit dc30692

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

nuvexport/export/ffmpeg.pm

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,10 @@ package export::ffmpeg;
264264
# The output is actually a stretched/anamorphic aspect ratio
265265
# (like 480x480 for SVCD, which is 4:3)
266266
if ($self->{'aspect_stretched'}) {
267-
# Stretch the width to the full aspect ratio for calculating
268-
$width = int($self->{'height'} * $self->{'out_aspect'} + 0.5);
269-
# Calculate the height required to keep the source in aspect
270-
$height = $width / $episode->{'finfo'}{'aspect_f'};
271-
# Round to nearest even number
272-
$height = int(($height + 2) / 4) * 4;
273-
# Calculate how much to pad the height (both top & bottom)
274-
$pad_h = int(($self->{'height'} - $height) / 2);
275-
# Set the real width again
276-
$width = $self->{'width'};
277-
# No padding on the width
278-
$pad_w = 0;
267+
$width = $self->{'width'};
268+
$height = $self->{'height'};
269+
$pad_h = 0;
270+
$pad_w = 0;
279271
}
280272
# The output will need letter/pillarboxing
281273
else {

nuvexport/export/generic.pm

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ package export::generic;
4141
add_arg('fast_denoise|fast-denoise!', 'Use fast noise reduction instead of standard.');
4242
add_arg('nocrop', 'Do not crop out broadcast overscan.');
4343
add_arg('crop_pct=f', 'Percentage of overscan to crop (0-5%, defaults to 2%).');
44-
add_arg('crop_top=f', 'Percentage of overscan to crop from the top.');
44+
add_arg('crop_top=f', 'Percentage of overscan to crop from the top. (0-20%)');
4545
add_arg('crop_right=f', 'Percentage of overscan to crop from the right.');
46-
add_arg('crop_bottom=f', 'Percentage of overscan to crop from the top.');
46+
add_arg('crop_bottom=f', 'Percentage of overscan to crop from the bottom. (0-20%)');
4747
add_arg('crop_left=f', 'Percentage of overscan to crop from the left.');
48+
add_arg('out_aspect=s', 'Force output aspect ratio.');
4849

4950
# Load defaults
5051
sub load_defaults {
@@ -85,14 +86,14 @@ package export::generic;
8586
if ($self->val('crop_pct') < 0 || $self->val('crop_pct') > 5) {
8687
die "crop_pct must be a number between 0 and 5.\n";
8788
}
88-
if ($self->val('crop_top') < 0 || $self->val('crop_top') > 5) {
89-
die "crop_top must be a number between 0 and 5.\n";
89+
if ($self->val('crop_top') < 0 || $self->val('crop_top') > 20) {
90+
die "crop_top must be a number between 0 and 20.\n";
9091
}
9192
if ($self->val('crop_right') < 0 || $self->val('crop_right') > 5) {
9293
die "crop_right must be a number between 0 and 5.\n";
9394
}
94-
if ($self->val('crop_bottom') < 0 || $self->val('crop_bottom') > 5) {
95-
die "crop_bottom must be a number between 0 and 5.\n";
95+
if ($self->val('crop_bottom') < 0 || $self->val('crop_bottom') > 20) {
96+
die "crop_bottom must be a number between 0 and 20.\n";
9697
}
9798
if ($self->val('crop_left') < 0 || $self->val('crop_left') > 5) {
9899
die "crop_left must be a number between 0 and 5.\n";
@@ -104,6 +105,23 @@ package export::generic;
104105
$self->{'crop'} = 1;
105106
}
106107
}
108+
# Clean up the aspect override, if one was passed in
109+
if ($self->val('out_aspect')) {
110+
$self->{'aspect_stretched'} = 1;
111+
my $aspect = $self->{'out_aspect'};
112+
# European decimals...
113+
$aspect =~ s/\,/\./;
114+
# In ratio format -- do the math
115+
if ($aspect =~ /^\d+:\d+$/) {
116+
my ($w, $h) = split /:/, $aspect;
117+
$aspect = $w / $h;
118+
}
119+
# Parse out decimal formats
120+
elsif ($aspect eq '1') { $aspect = 1; }
121+
elsif ($aspect =~ m/^1.3/) { $aspect = 4 / 3; }
122+
elsif ($aspect =~ m/^1.7/) { $aspect = 16 / 9; }
123+
$self->{'out_aspect'} = $aspect;
124+
}
107125
}
108126

109127
# Gather settings from the user
@@ -157,11 +175,12 @@ package export::generic;
157175
else {
158176
foreach my $side ('top', 'right', 'bottom', 'left') {
159177
while (1) {
178+
my $max = ($side eq 'top' || $side eq 'bottom') ? 20 : 5;
160179
my $pct = query_text("Crop broadcast overscan $side border (0-5\%) ?",
161180
'float',
162181
$self->val("crop_$side"));
163-
if ($pct < 0 || $pct > 5) {
164-
print "Crop percentage must be between 0 and 5 percent.\n";
182+
if ($pct < 0 || $pct > $max) {
183+
print "Crop percentage must be between 0 and $max percent.\n";
165184
}
166185
else {
167186
$self->{"crop_$side"} = $pct;

0 commit comments

Comments
 (0)