[mythtv-users] [PATCH] add avi support to
Brian J. Murrell
brian at interlinx.bc.ca
Thu Feb 11 13:49:01 UTC 2010
This patch adds AVI "file_info" support to the mythtv perl library. I
hope you will consider adding this to your library.
b.
--- /usr/share/perl5/MythTV/Recording.pm.dist 2010-02-11 07:54:22.000000000 -0500
+++ /usr/share/perl5/MythTV/Recording.pm 2010-02-11 07:59:24.000000000 -0500
@@ -143,6 +143,8 @@
# Extract the info -- detect mpg from the filename
if ($self->{'local_path'} =~ /\.mpe?g$/) {
$self->{'finfo'} = $self->_mpeg_info();
+ } elsif ($self->{'local_path'} =~ /\.avi$/) {
+ $self->{'finfo'} = $self->_avi_info();
}
# Probably nupplevideo, but fall back to mpeg just in case
else {
@@ -294,6 +296,67 @@
return \%info;
}
+ sub _avi_info {
+ my $self = shift;
+ my $file = $self->{'local_path'};
+ $file =~ s/'/'\\''/sg;
+ my %info;
+ # First, we check for the existence of an mpeg info program
+ my $program = find_program('mplayer');
+ # Nothing found? Die
+ die "You need mplayer to use this script on mpeg-based files.\n\n" unless ($program);
+ # Set the is_mpeg flag
+ $info{'is_mpeg'} = 1;
+ # Grab the info we want from mplayer (go uber-verbose to override --really-quiet)
+ my $data = `$program -v -nolirc -nojoystick -vo null -ao null -frames 0 -identify '$file' 2>/dev/null`;
+ study $data;
+ ($info{'video_type'}) = $data =~ m/^VIDEO:\s*\[(XVID)\]/m;
+ ($info{'width'}) = $data =~ m/^ID_VIDEO_WIDTH=0*([1-9]\d*)/m;
+ ($info{'height'}) = $data =~ m/^ID_VIDEO_HEIGHT=0*([1-9]\d*)/m;
+ ($info{'fps'}) = $data =~ m/^ID_VIDEO_FPS=0*([1-9]\d*(?:\.\d+)?)/m;
+ ($info{'audio_sample_rate'}) = $data =~ m/^ID_AUDIO_RATE=0*([1-9]\d*)/m;
+ ($info{'audio_bitrate'}) = $data =~ m/^ID_AUDIO_BITRATE=0*([1-9]\d*)/m;
+ ($info{'audio_bits_per_sample'}) = $data =~ m/^AUDIO:.+?ch,\s*[su](8|16)/mi;
+ ($info{'audio_channels'}) = $data =~ m/^ID_AUDIO_NCH=0*([1-9]\d*)/m;
+ ($info{'fps'}) = $data =~ m/^ID_VIDEO_FPS=0*([1-9]\d*(?:\.\d+)?)/m;
+ ($info{'aspect'}) = $data =~ m/^ID_VIDEO_ASPECT=0*([1-9]\d*(?:[\.\,]\d+)?)/m;
+ ($info{'audio_type'}) = $data =~ m/^ID_AUDIO_CODEC=0*([1-9]\d*(?:\.\d+)?)/m;
+ ($info{'avi_stream_type'}) = $data =~ m/^ID_DEMUXER=(\w+)/mi;
+ # Stream type
+ $info{'avi_stream_type'} = lc($info{'avi_stream_type'});
+ if ($info{'avi_stream_type'} && $info{'avi_stream_type'} !~ /^avi/) {
+ die "Stream type '$info{'avi_stream_type'}' is not an avi, and will\n"
+ ."not work with this program.\n";
+ }
+ # No matches on stream type?
+ if (!$info{'avi_stream_type'}) {
+ die "Unrecognized stream type. Please execute the following and see if you\n"
+ ."notice errors (make sure that you don't have the \"really quiet\" option\n"
+ ."set in your mplayer config). If not, create a ticket at\n"
+ ."http://svn.mythtv.org/trac/newticket and attach the output from:\n\n"
+ ." $program -v -nolirc -nojoystick -vo null -ao null \\\n"
+ ." -frames 0 -identify '$file'\n\n";
+ }
+ # HD fix
+ if ($info{'height'} == 1080) {
+ $info{'height'} = 1088;
+ }
+ # mplayer is confused and we need to detect the aspect on our own
+ if (!$info{'aspect'}) {
+ if ($info{'height'} == 1088 || $info{'height'} == 720) {
+ $info{'aspect'} = 16 / 9;
+ }
+ else {
+ $info{'aspect'} = 4 / 3;
+ }
+ }
+ # Cleanup
+ $info{'aspect'} = aspect_str($info{'aspect'});
+ $info{'aspect_f'} = aspect_float($info{'aspect'});
+ # Return
+ return \%info;
+ }
+
# Uses one of two mpeg info programs to load data about mpeg-based nuv files
sub _mpeg_info {
my $self = shift;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://mythtv.org/pipermail/mythtv-users/attachments/20100211/3a5cddb2/attachment.pgp>
More information about the mythtv-users
mailing list