Skip to content

Commit 2856fd5

Browse files
committed
new way of handling commandline arguments -- should make adding a help
section easier, as well as checking to see if/which arguments were passed in on the command line. update ffmpeg exporter so that it actually checks with ffmpeg for supported formats (hopefully no more random "unknown codec" errors now)
1 parent 7b1acec commit 2856fd5

File tree

18 files changed

+197
-129
lines changed

18 files changed

+197
-129
lines changed

trunk/export/ffmpeg.pm

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl -w
2-
#Last Updated: 2005.02.12 (xris)
2+
#Last Updated: 2005.02.15 (xris)
33
#
44
# ffmpeg.pm
55
#
@@ -19,11 +19,6 @@ package export::ffmpeg;
1919
use nuv_export::ui;
2020
use mythtv::recordings;
2121

22-
# Load the following extra parameters from the commandline
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
26-
2722
# This superclass defines several object variables:
2823
#
2924
# path (defined by generic)
@@ -35,42 +30,39 @@ package export::ffmpeg;
3530

3631
# Check for ffmpeg
3732
sub init_ffmpeg {
38-
my $self = shift;
33+
my $self = shift;
3934
my $audioonly = (shift or 0);
4035
# Make sure we have ffmpeg
4136
$Prog{'ffmpeg'} = find_program('ffmpeg');
4237
push @{$self->{'errors'}}, 'You need ffmpeg to use this exporter.' unless ($Prog{'ffmpeg'});
38+
# Audio only?
4339
$self->{'audioonly'} = $audioonly;
40+
# Gather the supported codecs
41+
my $formats = `$Prog{'ffmpeg'} -formats`;
42+
$formats =~ s/^.+?\n\s*Codecs:\s*\n(.+?\n)\s*\n.*?$/$1/s;
43+
while ($formats =~ /^\s(.{6})\s(\S+)\s*$/mg) {
44+
$self->{'codecs'}{$2} = $1;
45+
}
46+
}
47+
48+
# Returns true or false for the requested codec
49+
sub can_decode {
50+
my $self = shift;
51+
my $codec = shift;
52+
return ($self->{'codecs'}{$codec} && $self->{'codecs'}{$codec} =~ /^D/) ? 1 : 0;
53+
}
54+
sub can_encode {
55+
my $self = shift;
56+
my $codec = shift;
57+
return ($self->{'codecs'}{$codec} && $self->{'codecs'}{$codec} =~ /^.E/) ? 1 : 0;
4458
}
4559

4660
# Gather data for ffmpeg
4761
sub gather_settings {
4862
my $self = shift;
4963
my $skip = shift;
5064
# Gather generic settings
51-
$self->SUPER::gather_settings($skip ? $skip - 1 : 0);
52-
return if ($skip);
53-
# Defaults?
54-
$Args{'noise_reduction'} = '' if (defined $Args{'noise_reduction'} && $Args{'noise_reduction'} eq '');
55-
$Args{'deinterlace'} = '' if (defined $Args{'deinterlace'} && $Args{'deinterlace'} eq '');
56-
# Noise reduction?
57-
$self->{'noise_reduction'} = query_text('Enable noise reduction (slower, but better results)?',
58-
'yesno',
59-
$self->{'noise_reduction'} ? 'Yes' : 'No');
60-
# Deinterlace video?
61-
$self->{'deinterlace'} = query_text('Enable deinterlacing?',
62-
'yesno',
63-
$self->{'deinterlace'} ? 'Yes' : 'No');
64-
65-
# Crop video to get rid of broadcast padding
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-
}
65+
$self->SUPER::gather_settings();
7466
}
7567

7668
sub export {

trunk/export/ffmpeg/ASF.pm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Last Updated: 2005.01.26 (xris)
1+
#Last Updated: 2005.02.15 (xris)
22
#
33
# export::ffmpeg::ASF
44
# Maintained by Gavin Hurlbut <gjhurlbu@gmail.com>
@@ -14,8 +14,8 @@ package export::ffmpeg::ASF;
1414
use mythtv::recordings;
1515

1616
# Load the following extra parameters from the commandline
17-
$cli_args{'a_bitrate|a=i'} = 1; # Audio bitrate
18-
$cli_args{'v_bitrate|v=i'} = 1; # Video bitrate
17+
add_arg('a_bitrate|a=i', 'Audio bitrate');
18+
add_arg('v_bitrate|v=i', 'Video bitrate');
1919

2020
sub new {
2121
my $class = shift;
@@ -38,7 +38,13 @@ package export::ffmpeg::ASF;
3838

3939
# Initialize and check for ffmpeg
4040
$self->init_ffmpeg();
41-
41+
# Can we even encode asf?
42+
if (!$self->can_encode('msmpeg4')) {
43+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to msmpeg4.";
44+
}
45+
if (!$self->can_encode('mp3')) {
46+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mp3 audio.";
47+
}
4248
# Any errors? disable this function
4349
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
4450
# Return

trunk/export/ffmpeg/DVCD.pm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl -w
2-
#Last Updated: 2005.01.26 (gjhurlbu)
2+
#Last Updated: 2005.02.15 (xris)
33
#
44
# export::ffmpeg::DVCD
55
# Maintained by Gavin Hurlbut <gjhurlbu@gmail.com>
@@ -32,6 +32,13 @@ package export::ffmpeg::DVCD;
3232

3333
# Initialize and check for ffmpeg
3434
$self->init_ffmpeg();
35+
# Can we even encode vcd?
36+
if (!$self->can_encode('mpeg1video')) {
37+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mpeg1video.";
38+
}
39+
if (!$self->can_encode('mp2')) {
40+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mp2 audio.";
41+
}
3542
# Any errors? disable this function
3643
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
3744
# Return

trunk/export/ffmpeg/DVD.pm

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl -w
2-
#Last Updated: 2005.01.26 (xris)
2+
#Last Updated: 2005.02.15 (xris)
33
#
44
# export::ffmpeg::DVD
55
# Maintained by Gavin Hurlbut <gjhurlbu@gmail.com>
@@ -15,9 +15,9 @@ package export::ffmpeg::DVD;
1515
use mythtv::recordings;
1616

1717
# Load the following extra parameters from the commandline
18-
$cli_args{'quantisation|q=i'} = 1; # Quantisation
19-
$cli_args{'a_bitrate|a=i'} = 1; # Audio bitrate
20-
$cli_args{'v_bitrate|v=i'} = 1; # Video bitrate
18+
add_arg('quantisation|q=i', 'Quantisation');
19+
add_arg('a_bitrate|a=i', 'Audio bitrate');
20+
add_arg('v_bitrate|v=i', 'Video bitrate');
2121

2222
sub new {
2323
my $class = shift;
@@ -39,7 +39,13 @@ package export::ffmpeg::DVD;
3939

4040
# Initialize and check for ffmpeg
4141
$self->init_ffmpeg();
42-
42+
# Can we even encode dvd?
43+
if (!$self->can_encode('mpeg2video')) {
44+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mpeg2video.";
45+
}
46+
if (!$self->can_encode('mp2')) {
47+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mp2 audio.";
48+
}
4349
# Any errors? disable this function
4450
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
4551
# Return

trunk/export/ffmpeg/DivX.pm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#Last Updated: 2005.01.26 (xris)
1+
#Last Updated: 2005.02.15 (xris)
22
#
33
# export::ffmpeg::DivX
44
# Maintained by Gavin Hurlbut <gjhurlbu@gmail.com>
@@ -14,8 +14,8 @@ package export::ffmpeg::DivX;
1414
use mythtv::recordings;
1515

1616
# Load the following extra parameters from the commandline
17-
$cli_args{'a_bitrate|a=i'} = 1; # Audio bitrate
18-
$cli_args{'v_bitrate|v=i'} = 1; # Video bitrate
17+
add_arg('a_bitrate|a=i', 'Audio bitrate');
18+
add_arg('v_bitrate|v=i', 'Video bitrate');
1919

2020
sub new {
2121
my $class = shift;
@@ -38,7 +38,13 @@ package export::ffmpeg::DivX;
3838

3939
# Initialize and check for ffmpeg
4040
$self->init_ffmpeg();
41-
41+
# Can we even encode divx?
42+
if (!$self->can_encode('mpeg4')) {
43+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mpeg4.";
44+
}
45+
if (!$self->can_encode('mp3')) {
46+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mp3 audio.";
47+
}
4248
# Any errors? disable this function
4349
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
4450
# Return

trunk/export/ffmpeg/MP3.pm

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl -w
2-
#Last Updated: 2005.01.26 (xris)
2+
#Last Updated: 2005.02.15 (xris)
33
#
44
# export::ffmpeg::MP3
55
# Maintained by Chris Petersen <mythtv@forevermore.net>
@@ -15,7 +15,7 @@ package export::ffmpeg::MP3;
1515
use mythtv::recordings;
1616

1717
# Load the following extra parameters from the commandline
18-
$cli_args{'bitrate=i'} = 1; # Audio bitrate
18+
add_arg('bitrate=i', 'Audio bitrate');
1919

2020
sub new {
2121
my $class = shift;
@@ -31,11 +31,13 @@ package export::ffmpeg::MP3;
3131

3232
# Initialize and check for transcode
3333
$self->init_ffmpeg(1);
34-
3534
# Make sure that we have an mplexer
3635
$Prog{'id3tag'} = find_program('id3tag');
3736
push @{$self->{'errors'}}, 'You need id3tag to export an mp3.' unless ($Prog{'id3tag'});
38-
37+
# Can we even encode vcd?
38+
if (!$self->can_encode('mp3')) {
39+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mp3 audio.";
40+
}
3941
# Any errors? disable this function
4042
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
4143
# Return

trunk/export/ffmpeg/SVCD.pm

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl -w
2-
#Last Updated: 2005.02.06 (xris)
2+
#Last Updated: 2005.02.15 (xris)
33
#
44
# export::ffmpeg::SVCD
55
# Maintained by Chris Petersen <mythtv@forevermore.net>
@@ -15,9 +15,9 @@ package export::ffmpeg::SVCD;
1515
use mythtv::recordings;
1616

1717
# Load the following extra parameters from the commandline
18-
$cli_args{'quantisation|q=i'} = 1; # Quantisation
19-
$cli_args{'a_bitrate|a=i'} = 1; # Audio bitrate
20-
$cli_args{'v_bitrate|v=i'} = 1; # Video bitrate
18+
add_arg('quantisation|q=i', 'Quantisation');
19+
add_arg('a_bitrate|a=i', 'Audio bitrate');
20+
add_arg('v_bitrate|v=i', 'Video bitrate');
2121

2222
sub new {
2323
my $class = shift;
@@ -39,7 +39,13 @@ package export::ffmpeg::SVCD;
3939

4040
# Initialize and check for ffmpeg
4141
$self->init_ffmpeg();
42-
42+
# Can we even encode svcd?
43+
if (!$self->can_encode('mpeg2video')) {
44+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mpeg2video.";
45+
}
46+
if (!$self->can_encode('mp2')) {
47+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mp2 audio.";
48+
}
4349
# Any errors? disable this function
4450
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
4551
# Return

trunk/export/ffmpeg/VCD.pm

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl -w
2-
#Last Updated: 2005.02.06 (xris)
2+
#Last Updated: 2005.02.15 (xris)
33
#
44
# export::ffmpeg::VCD
55
# Maintained by Gavin Hurlbut <gjhurlbu@gmail.com>
@@ -32,6 +32,13 @@ package export::ffmpeg::VCD;
3232

3333
# Initialize and check for ffmpeg
3434
$self->init_ffmpeg();
35+
# Can we even encode vcd?
36+
if (!$self->can_encode('mpeg1video')) {
37+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mpeg1video.";
38+
}
39+
if (!$self->can_encode('mp2')) {
40+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mp2 audio.";
41+
}
3542
# Any errors? disable this function
3643
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
3744
# Return

trunk/export/ffmpeg/XviD.pm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl -w
2-
#Last Updated: 2005.02.06 (xris)
2+
#Last Updated: 2005.02.15 (xris)
33
#
44
# export::ffmpeg::XviD
55
# Maintained by Chris Petersen <mythtv@forevermore.net>
@@ -15,10 +15,10 @@ package export::ffmpeg::XviD;
1515
use mythtv::recordings;
1616

1717
# Load the following extra parameters from the commandline
18-
$cli_args{'quantisation|q=i'} = 1; # Quantisation
19-
$cli_args{'a_bitrate|a=i'} = 1; # Audio bitrate
20-
$cli_args{'v_bitrate|v=i'} = 1; # Video bitrate
21-
$cli_args{'multipass'} = 1; # Two-pass encoding
18+
add_arg('quantisation|q=i', 'Quantisation');
19+
add_arg('a_bitrate|a=i', 'Audio bitrate');
20+
add_arg('v_bitrate|v=i', 'Video bitrate');
21+
add_arg('multipass!', 'Enably two-pass encoding.');
2222

2323
sub new {
2424
my $class = shift;
@@ -44,6 +44,11 @@ package export::ffmpeg::XviD;
4444
# Initialize and check for ffmpeg
4545
$self->init_ffmpeg();
4646

47+
# Can we even encode xvid?
48+
if (!$self->can_encode('xvid')) {
49+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to xvid.\n"
50+
." (It must be compiled with the --enable-xvid option)";
51+
}
4752
# Any errors? disable this function
4853
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
4954
# Return

trunk/export/generic.pm

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/perl -w
2-
#Last Updated: 2004.12.26 (xris)
2+
#Last Updated: 2005.02.13 (xris)
33
#
44
# generic.pm
55
#
@@ -23,12 +23,15 @@ package export::generic;
2323
}
2424

2525
# Load the following extra parameters from the commandline
26-
$cli_args{'path:s'} = 1; # Save path (only used with the noserver option)
27-
$cli_args{'cutlist|use_cutlist'} = 1; # Use the myth cutlist
26+
add_arg('path:s', 'Save path (only used with the noserver option)');
27+
add_arg('cutlist|use_cutlist!', 'Use the myth cutlist (or not)');
2828

2929
# These aren't used by all modules, but the routine to define them is here, so here they live
30-
$cli_args{'height|v_res|h=i'} = 1; # Height
31-
$cli_args{'width|h_res|w=i'} = 1; # Width
30+
add_arg('height|v_res|h=i', 'Output height.');
31+
add_arg('width|h_res|w=i', 'Output width.');
32+
add_arg('deinterlace:s!', 'Deinterlace video.');
33+
add_arg('noise_reduction|denoise|nr:s!', 'Enable noise reduction.');
34+
add_arg('crop!', 'Crop out broadcast overscan.');
3235

3336
# Gather generic export settings
3437
sub gather_settings {
@@ -38,7 +41,30 @@ package export::generic;
3841
# Ask the user if he/she wants to use the cutlist
3942
$self->{'use_cutlist'} = query_text('Enable Myth cutlist?',
4043
'yesno',
41-
'Yes');
44+
(defined($Args{'cutlist'}) && $Args{'cutlist'} == 0) ? 'No' : 'Yes');
45+
# Video settings
46+
if (!$self->{'audioonly'}) {
47+
# Defaults?
48+
$Args{'denoise'} = '' if (defined $Args{'denoise'} && $Args{'denoise'} eq '');
49+
$Args{'deinterlace'} = 1 if (defined $Args{'deinterlace'} && $Args{'deinterlace'} eq '');
50+
# Noise reduction?
51+
$self->{'denoise'} = query_text('Enable noise reduction (slower, but better results)?',
52+
'yesno',
53+
$self->{'denoise'} ? 'Yes' : 'No');
54+
# Deinterlace video?
55+
$self->{'deinterlace'} = query_text('Enable deinterlacing?',
56+
'yesno',
57+
$self->{'deinterlace'} ? 'Yes' : 'No');
58+
# Crop video to get rid of broadcast padding
59+
if ($Args{'crop'}) {
60+
$self->{'crop'} = 1;
61+
}
62+
else {
63+
$self->{'crop'} = query_text('Crop broadcast overscan (2% border)?',
64+
'yesno',
65+
$self->{'crop'} ? 'Yes' : 'No');
66+
}
67+
}
4268
}
4369

4470
# Check for a duplicate filename, and return a full path to the output filename

0 commit comments

Comments
 (0)