Skip to content

Commit b91b27d

Browse files
committed
crop support for ffmpeg (Gavin)
1 parent 2e495c9 commit b91b27d

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

trunk/export/WMV.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ package export::WMV;
3030
# ffmpeg-related settings
3131
'noise_reduction' => 1,
3232
'deinterlace' => 1,
33+
'crop' => 1,
3334
# WMV-specific settings
3435
'a_bitrate' => 64,
3536
'v_bitrate' => 256,

trunk/export/ffmpeg.pm

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ package export::ffmpeg;
2020
use mythtv::recordings;
2121

2222
# Load the following extra parameters from the commandline
23-
$cli_args{'cutlist|use_cutlist'} = 1; # Use the myth cutlist
24-
$cli_args{'deinterlace:s'} = 1; # Deinterlace video
25-
$cli_args{'denoise|noise_reduction:s'} = 1; # Enable noise reduction
23+
$cli_args{'deinterlace:s'} = 1; # Deinterlace video
24+
$cli_args{'denoise|noise_reduction:s'} = 1; # Enable noise reduction
25+
$cli_args{'crop'} = 1; # Crop out broadcast overscan
2626

2727
# This superclass defines several object variables:
2828
#
29-
# use_cutlist
30-
# noise_reduction
29+
# path (defined by generic)
30+
# use_cutlist (defined by generic)
31+
# denoise
3132
# deinterlace
3233
# crop
3334
#
@@ -60,10 +61,16 @@ package export::ffmpeg;
6061
$self->{'deinterlace'} = query_text('Enable deinterlacing?',
6162
'yesno',
6263
$self->{'deinterlace'} ? 'Yes' : 'No');
64+
6365
# Crop video to get rid of broadcast padding
64-
# $self->{'crop'} = query_text('Crop ',
65-
# 'yesno',
66-
# $self->{'crop'} ? 'Yes' : 'No');
66+
if ($Args{'crop'}) {
67+
$self->{'crop'} = 1;
68+
}
69+
else {
70+
$self->{'crop'} = query_text('Crop broadcast overscan (2% border)?',
71+
'yesno',
72+
$self->{'crop'} ? 'Yes' : 'No');
73+
}
6774
}
6875

6976
sub export {
@@ -88,12 +95,16 @@ package export::ffmpeg;
8895

8996
my $videofifo = "/tmp/fifodir_$$/vidout";
9097
my $videotype = 'rawvideo';
91-
92-
# # Crop?
93-
# if (1 || $self->{'crop'}) {
94-
# my $cropw = sprintf('%.0f', .02 * $episode->{'finfo'}{'width'});
95-
# my $croph = sprintf('%.0f', .02 * $episode->{'finfo'}{'height'});
96-
# }
98+
my $crop_w;
99+
my $crop_h;
100+
101+
if ($self->{'crop'}) {
102+
$crop_w = sprintf('%.0f', .02 * $episode->{'finfo'}{'width'});
103+
$crop_h = sprintf('%.0f', .02 * $episode->{'finfo'}{'height'});
104+
# keep crop numbers even
105+
$crop_w-- if ($crop_w > 0 && $crop_w % 2);
106+
$crop_h-- if ($crop_h > 0 && $crop_h % 2);
107+
}
97108

98109
if ($self->{'audioonly'}) {
99110
$ffmpeg .= "cat /tmp/fifodir_$$/vidout > /dev/null | ";
@@ -107,7 +118,9 @@ package export::ffmpeg;
107118
$ffmpeg .= " -i /tmp/fifodir_$$/vidout -f yuv4mpegpipe -";
108119
$ffmpeg .= " 2> /dev/null | ";
109120
$ffmpeg .= "nice -n $Args{'nice'} yuvdenoise -F -r 16";
110-
# $ffmpeg .= " -b $cropw,$croph,-$cropw,-$croph" if( $cropw || $croph );
121+
if ($self->{'crop'}) {
122+
$ffmpeg .= " -b $crop_w,$crop_h,-$crop_w,-$crop_h";
123+
}
111124
$ffmpeg .= " 2> /dev/null | ";
112125
$videofifo = "-";
113126
$videotype = "yuv4mpegpipe";
@@ -129,6 +142,12 @@ package export::ffmpeg;
129142
if ($self->{'deinterlace'}) {
130143
$ffmpeg .= " -deinterlace";
131144
}
145+
146+
if ($self->{'crop'}) {
147+
148+
$ffmpeg .= " -croptop $crop_h -cropbottom $crop_h";
149+
$ffmpeg .= " -cropleft $crop_w -cropright $crop_w";
150+
}
132151
}
133152

134153
# Add any additional settings from the child module

trunk/export/transcode.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ package export::transcode;
2121
# Load the following extra parameters from the commandline
2222
$cli_args{'deinterlace:s'} = 1; # Deinterlace video
2323
$cli_args{'denoise|noise_reduction:s'} = 1; # Enable noise reduction
24-
$cli_args{'deinterlace:s'} = 1; # Transcode-related settings
2524
$cli_args{'zoom_filter:s'} = 1; # Which zoom filter to use
2625
$cli_args{'crop'} = 1; # Crop out broadcast overscan
2726

2827
# This superclass defines several object variables:
2928
#
30-
# use_cutlist
29+
# path (defined by generic)
30+
# use_cutlist (defined by generic)
3131
# denoise
3232
# deinterlace
3333
# crop
34+
# zoom_filter
3435
#
3536

3637
# Check for transcode

0 commit comments

Comments
 (0)