Skip to content

Commit ae75127

Browse files
committed
new hopefully better xvid encoding parameters
1 parent 737efe5 commit ae75127

File tree

1 file changed

+41
-47
lines changed

1 file changed

+41
-47
lines changed

trunk/export/ffmpeg/XviD.pm

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
#!/usr/bin/perl -w
21
#
3-
# $Date$
4-
# $Revision$
5-
# $Author$
2+
# ffmpeg-based XviD export module for nuvexport.
63
#
7-
# export::ffmpeg::XviD
8-
# Maintained by Chris Petersen <mythtv@forevermore.net>
4+
# @url $URL$
5+
# @date $Date$
6+
# @version $Revision$
7+
# @author $Author$
8+
# @copyright Silicon Mechanics
99
#
1010

1111
package export::ffmpeg::XviD;
@@ -61,6 +61,9 @@ package export::ffmpeg::XviD;
6161
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to xvid.\n"
6262
." (It must be compiled with the --enable-xvid option)";
6363
}
64+
if (!$self->can_encode('mp3')) {
65+
push @{$self->{'errors'}}, "Your ffmpeg installation doesn't support encoding to mp3 audio.";
66+
}
6467

6568
# Any errors? disable this function
6669
$self->{'enabled'} = 0 if ($self->{'errors'} && @{$self->{'errors'}} > 0);
@@ -131,59 +134,50 @@ package export::ffmpeg::XviD;
131134
my $episode = shift;
132135
# Make sure we have the framerate
133136
$self->{'out_fps'} = $episode->{'finfo'}{'fps'};
137+
# Embed the title
138+
my $safe_title = shell_escape($episode->{'show_name'}.' - '.$episode->{'title'});
139+
# Build the common ffmpeg string
140+
my $ffmpeg_xtra = ' -vcodec xvid'
141+
.' -b '.$self->{'v_bitrate'}
142+
.($self->{'vbr'}
143+
? ' -bt 32 -minrate 32 -maxrate '.(2*$self->{'v_bitrate'})
144+
.' -bufsize 65535'
145+
: '')
146+
.' -flags +4mv+trell+loop'
147+
.' -aic 1'
148+
.' -mbd 1'
149+
.' -cmp 2 -subcmp 2'
150+
.' -cgop 1'
151+
.' -max_b_frames 1'
152+
.' -b_quant_factor 150'
153+
.' -b_quant_offset 100'
154+
;
134155
# Dual pass?
135156
if ($self->{'multipass'}) {
136157
# Add the temporary file to the list
137158
push @tmpfiles, "/tmp/xvid.$$.log";
138-
# Back up the path and use /dev/null for the first pass
139-
my $path_bak = $self->{'path'};
140-
$self->{'path'} = '/dev/null';
141159
# First pass
142160
print "First pass...\n";
143-
$self->{'ffmpeg_xtra'} = ' -vcodec xvid'
144-
. ' -b ' . $self->{'v_bitrate'}
145-
. ' -minrate 32 -maxrate '.(2*$self->{'v_bitrate'}).' -bt 32'
146-
. ' -bufsize 65535'
147-
. ' -lumi_mask 0.05 -dark_mask 0.02 -scplx_mask 0.5'
148-
. ($self->{'ffmpeg_vers'} =~ /cvs|svn/ ? ' -mv4' : ' -4mv')
149-
. ' -part'
150-
. " -pass 1 -passlogfile '/tmp/xvid.$$.log'"
151-
. ' -f avi';
152-
$self->SUPER::export($episode, '');
153-
# Restore the path
154-
$self->{'path'} = $path_bak;
161+
$self->{'ffmpeg_xtra'} = $ffmpeg_xtra
162+
." -pass 1 -passlogfile '/tmp/xvid.$$.log'"
163+
.' -f avi';
164+
$self->SUPER::export($episode, '', 1);
155165
# Second pass
156166
print "Final pass...\n";
157-
$self->{'ffmpeg_xtra'} = ' -vcodec xvid'
158-
. ' -b ' . $self->{'v_bitrate'}
159-
. ' -minrate 32 -maxrate '.(2*$self->{'v_bitrate'}).' -bt 32'
160-
. ' -bufsize 65535'
161-
. ' -lumi_mask 0.05 -dark_mask 0.02 -scplx_mask 0.5'
162-
. ($self->{'ffmpeg_vers'} =~ /cvs|svn/ ? ' -mv4' : ' -4mv')
163-
. ' -part'
164-
. ' -acodec mp3'
165-
. ' -ab ' . $self->{'a_bitrate'}
166-
. " -pass 2 -passlogfile '/tmp/xvid.$$.log'"
167-
. ' -f avi';
167+
$self->{'ffmpeg_xtra'} = $ffmpeg_xtra
168+
. " -pass 2 -passlogfile '/tmp/xvid.$$.log'";
168169
}
169170
# Single Pass
170171
else {
171-
$self->{'ffmpeg_xtra'} = ' -vcodec xvid'
172-
. ' -b ' . $self->{'v_bitrate'}
173-
. (($self->{'vbr'})
174-
? " -qmin $self->{'quantisation'}"
175-
. ' -qmax 31 -minrate 32'
176-
. ' -maxrate '.(2*$self->{'v_bitrate'})
177-
. ' -bt 32'
178-
. ' -bufsize 65535'
179-
: '')
180-
. ' -lumi_mask 0.05 -dark_mask 0.02 -scplx_mask 0.5'
181-
. ($self->{'ffmpeg_vers'} =~ /cvs|svn/ ? ' -mv4' : ' -4mv')
182-
. ' -part'
183-
. ' -acodec mp3'
184-
. ' -ab ' . $self->{'a_bitrate'}
185-
. ' -f avi';
172+
$self->{'ffmpeg_xtra'} = $ffmpeg_xtra
173+
.($self->{'vbr'}
174+
? ' -qmax 31 -qmin '.$self->{'quantisation'}
175+
: '');
186176
}
177+
# Don't forget the audio, etc.
178+
$self->{'ffmpeg_xtra'} .= ' -acodec mp3 -async 1'
179+
.' -ab '.$self->{'a_bitrate'}
180+
.' -f avi';
187181
# Execute the (final pass) encode
188182
$self->SUPER::export($episode, '.avi');
189183
}

0 commit comments

Comments
 (0)