blib/lib/Video/DVDRip/Cluster/Title.pm untested

filter: Statementstmt 0.0% 0 / 137 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 31 Podpod 0.0% 0 / 26 totaltotal 0.0% 0 / 245 CC 19 SCAR 26.4
CC
19
Cov
0%
get_merge_video_audio_command
42.0
get_merge_psu_command
42.0
get_merge_audio_command
20.0
CRAP 14.1
1 # $Id: Title.pm 2397 2010-03-06 13:06:33Z joern $
2  
3 #-----------------------------------------------------------------------
4 # Copyright (C) 2001-2006 Jörn Reder <joern AT zyn.de>.
5 # All Rights Reserved. See file COPYRIGHT for details.
6 #
7 # This program is part of Video::DVDRip, which is free software; you can
8 # redistribute it and/or modify it under the same terms as Perl itself.
9 #-----------------------------------------------------------------------
10  
11 package Video::DVDRip::Cluster::Title;
12 use Locale::TextDomain qw (video.dvdrip);
13  
14 use base Video::DVDRip::Title;
15  
16 use Carp;
17 use strict;
18  
19 use File::Basename;
20  
21 sub frames_finished { shift->{frames_finished} }
22 sub with_cleanup { shift->{with_cleanup} }
23 sub with_vob_remove { shift->{with_vob_remove} }
24 sub frames_per_chunk { shift->{frames_per_chunk} }
25  
26 sub set_frames_finished { shift->{frames_finished} = $_[1] }
27 sub set_with_cleanup { shift->{with_cleanup} = $_[1] }
28 sub set_with_vob_remove { shift->{with_vob_remove} = $_[1] }
29 sub set_frames_per_chunk { shift->{frames_per_chunk} = $_[1] }
30  
31 sub info {
32 my $self = shift;
33 return $self->project->name . " (#" . $self->nr . ")";
34 }
35  
36 sub create_vob_dir {
37 my $self = shift;
38  
39 # no vob_dir creating here. This is done just before we
40 # start transcoding to prevent from too much ssh remote
41 # communication.
42  
43 return 1;
44 }
45  
46 sub create_avi_dir {
47 my $self = shift;
48  
49 # no avi_dir creating here. This is done just before we
50 # start transcoding to prevent from too much ssh remote
51 # communication.
52  
53 return 1;
54 }
55  
56 sub is_ripped {
57 return 1;
58 }
59  
60 #-----------------------------------------------------------------------
61 # Filenames of all stages
62 #-----------------------------------------------------------------------
63  
64 sub multipass_log_dir { # directory for multipass logs
65 my $self = shift;
66  
67 my $job = $Event::ExecFlow::JOB;
68  
69 return sprintf (
70 "%s/%s/cluster/%03d-%02d-%05d",
71 $job->get_node->data_base_dir,
72 $self->project->name,
73 $self->nr,
74 $job->get_stash->{psu},
75 $job->get_stash->{chunk},
76 );
77 }
78  
79 sub avi_chunks_dir { # directory for avi chunks
80 my $self = shift;
81  
82 my $job = $Event::ExecFlow::JOB;
83  
84 return sprintf (
85 "%s/%03d/chunks-psu-%02d",
86 $self->project->final_avi_dir,
87 $self->nr,
88 $job->get_stash->{psu},
89 );
90 }
91  
92 sub avi_file { # transcode output file
93 my $self = shift;
94  
95 my $job = $Event::ExecFlow::JOB;
96  
97 return sprintf (
98 "%s/%s-%03d-%05d.avi",
99 $self->avi_chunks_dir,
100 $self->project->name,
101 $self->nr,
102 $job->get_stash->{chunk},
103 );
104 }
105  
106 sub target_avi_audio_file {
107 my $self = shift;
108  
109 my $ext = $self->is_ogg ? $self->config('ogg_file_ext') : 'avi';
110 my $job = $Event::ExecFlow::JOB;
111  
112 return sprintf (
113 "%s/%03d/audio-psu-%02d/%s-%03d-audio-psu-%02d-%02d.$ext",
114 $self->project->final_avi_dir,
115 $self->nr,
116 $job->get_stash->{psu},
117 $self->project->name,
118 $self->nr,
119 $job->get_stash->{psu},
120 $job->get_stash->{avi_nr},
121 );
122 }
123  
124 sub audio_video_psu_dir {
125 my $self = shift;
126  
127 return sprintf (
128 "%s/%03d/audio-video-psu",
129 $self->project->final_avi_dir,
130 $self->nr,
131 );
132 }
133  
134 sub audio_video_psu_file {
135 my $self = shift;
136  
137 my $ext = $self->is_ogg ? $self->config('ogg_file_ext') : 'avi';
138 my $job = $Event::ExecFlow::JOB;
139  
140 return sprintf (
141 "%s/%s-%03d-av-psu-%02d.$ext",
142 $self->audio_video_psu_dir,
143 $self->project->name,
144 $self->nr,
145 $job->get_stash->{psu},
146 );
147 }
148  
149 sub target_avi_file { # final avi, merged PSUs + audio
150 my $self = shift;
151  
152 my $ext = $self->is_ogg ? $self->config('ogg_file_ext') : 'avi';
153  
154 return sprintf(
155 "%s/%03d/%s-%03d.$ext",
156 $self->project->final_avi_dir,
157 $self->nr,
158 $self->project->name,
159 $self->nr
160 );
161 }
162  
163 #-----------------------------------------------------------------------
164 # Commands for all Jobs
165 #-----------------------------------------------------------------------
166  
167 sub get_transcode_command {
168 my $self = shift;
169  
170 my $psu = "DVDRIP_JOB_PSU";
171 my $chunk = "DVDRIP_JOB_CHUNK";
172 my $chunk_cnt = "DVDRIP_JOB_CHUNK_CNT";
173  
174 my $nav_file = $self->vob_nav_file;
175  
176 my $command = $self->SUPER::get_transcode_command(
177 no_audio => 1,
178 @_
179 );
180  
181 # remove EXECFLOW_OK
182 $command =~ s/&&\s+echo\s+EXECFLOW_OK//;
183  
184 # no audio options
185 $command =~ s/\s-[baN]\s+[^\s]+//;
186  
187 # no -c in cluster mode
188 $command =~ s/ -c \d+-\d+//;
189  
190 # no preview in cluster mode
191 $command =~ s/-J\s+preview=[^\s]+//;
192  
193 # add -S and -W options for chunk selection (dont' just append,
194 # because the transcode command probably got appended some
195 # additional shell commands - e.g. h264 log copy stuff)
196 $command =~
197 s{ (execflow.*?transcode) }
198 { $1 -S $psu -W $chunk,$chunk_cnt,$nav_file };
199  
200 # sorry, can't remember why I do that...
201 $command =~ s/-M 2//;
202  
203 # add directory creation code
204 my $avi_dir = dirname $self->avi_file;
205 $command = "mkdir -m 0775 -p '$avi_dir' && $command";
206  
207 # add EXECFLOW_OK
208 $command .= " && echo EXECFLOW_OK";
209  
210 return $command;
211 }
212  
213 sub get_transcode_audio_command {
214 my $self = shift;
215 my %par = @_;
216 my ( $vob_nr, $target_nr ) = @par{ 'vob_nr', 'target_nr' };
217  
218 my $command = $self->SUPER::get_transcode_audio_command(@_);
219 $command =~ s/\s+&& echo EXECFLOW_OK//;
220  
221 if ( $self->version("transcode") >= 10100 ) {
222 $command .=
223 " --psu_mode --no_split"
224 . " --psu_chunks DVDRIP_JOB_PSU-DVDRIP_JOB_ADD_ONE_PSU"
225 . " --nav_seek ".$self->vob_nav_file;
226 }
227 else {
228 $command .=
229 " -S DVDRIP_JOB_PSU"
230 . " -W DVDRIP_JOB_CHUNK_CNT,DVDRIP_JOB_CHUNK_CNT,"
231 . $self->vob_nav_file;
232 }
233  
234 $command .= " && echo EXECFLOW_OK";
235  
236 return $command;
237 }
238  
239 sub get_merge_audio_command {
240 my $self = shift;
241 my %par = @_;
242 my ( $vob_nr, $target_nr ) = @par{ 'vob_nr', 'target_nr' };
243  
244 my $avi_file = $self->audio_video_psu_file;
245 my $audio_file = $self->target_avi_audio_file;
246 my $target_file = $avi_file;
247  
248 my $command;
249 my $nice;
250 $nice = "`which nice` -n " . $self->tc_nice . " "
251 if $self->tc_nice =~ /\S/;
252  
253 $command = $nice;
254  
255 # operate on final avi file if no PSU merging is necessary
256 # if ( @{$self->program_stream_units} == 1 ) {
257 # $avi_file = $self->target_avi_file;
258 # $target_file = $self->target_avi_file;
259 # }
260  
261 if ( $self->is_ogg ) {
262 # remove audio_video_psu file here, because
263 # this isn't done in get_merge_video_audio_command,
264 # because audio merging is done here with ogg.
265 my $audio_video_psu_file;
266 $audio_video_psu_file = $self->audio_video_psu_file
267 if $self->with_cleanup
268 and $self->audio_video_psu_file ne $target_file;
269  
270 $command .= "execflow ogmmerge -o $avi_file.merged "
271 . " $avi_file"
272 . " $audio_file &&"
273 . " mv $avi_file.merged $target_file &&"
274 . " rm -f $audio_file $audio_video_psu_file &&"
275 . " echo EXECFLOW_OK";
276  
277 }
278 else {
279 $command .= "execflow avimerge"
280 . " -p $audio_file"
281 . " -a $target_nr"
282 . " -o $avi_file.merged"
283 . " -i $avi_file &&"
284 . " mv $avi_file.merged $target_file &&"
285 . " rm $audio_file &&"
286 . " echo EXECFLOW_OK";
287 }
288  
289 return $command;
290 }
291  
292 sub get_merge_video_audio_command {
293 my $self = shift;
294  
295 #-- with one PSU and AVI processing this avimerge file
296 #-- creates the final file
297 my $move_final = 0;
298 # @{$self->program_stream_units} == 1 && !$self->is_ogg;
299
300 my $avi_chunks_dir = $self->avi_chunks_dir;
301 my $audio_video_psu_file = $self->audio_video_psu_file;
302 $audio_video_psu_file = $self->target_avi_file
303 if $move_final;
304  
305 my $audio_video_psu_dir = dirname($audio_video_psu_file);
306 my $audio_psu_file = $self->target_avi_audio_file;
307  
308 my $chunks_mask = sprintf( "%s/%03d/chunks-psu-??/*",
309 $self->project->final_avi_dir, $self->nr );
310  
311 my $nice;
312 $nice = "`which nice` -n " . $self->tc_nice . " "
313 if $self->tc_nice =~ /\S/;
314  
315 my $command = "mkdir -m 0775 -p '$audio_video_psu_dir' && "
316 . "${nice}execflow avimerge -o $audio_video_psu_file";
317  
318 $command .= " -p $audio_psu_file " if !$self->is_ogg;
319  
320 #-- -i *always* at the end! At some time avimerge's cmd line
321 #-- parser was messed up...
322 $command .= " -i $avi_chunks_dir/*";
323  
324 $command .= " && rm $avi_chunks_dir/*"
325 if $self->with_cleanup;
326  
327 $command .= " '$audio_psu_file'"
328 if $self->with_cleanup
329 and not $self->is_ogg;
330  
331 $command .= " && echo EXECFLOW_OK";
332  
333 return $command;
334 }
335  
336 sub get_merge_psu_command {
337 my $self = shift;
338 my %par = @_;
339 my ($psu) = @par{'psu'};
340  
341 my $target_avi_file = $self->target_avi_file;
342 my $target_avi_dir = dirname($target_avi_file);
343 my $audio_video_psu_dir = $self->audio_video_psu_dir;
344  
345 my $ext = $self->is_ogg ? $self->config('ogg_file_ext') : 'avi';
346 my $nice;
347 $nice = "`which nice` -n " . $self->tc_nice . " "
348 if $self->tc_nice =~ /\S/;
349  
350 my $command
351 = "mkdir -m 0775 -p '$target_avi_dir' && " . "${nice}execflow ";
352  
353 if ( $self->is_ogg ) {
354 $command .= "ogmcat -v -v "; # -v -v to prevent timeouts
355 }
356 else {
357 $command .= "avimerge ";
358 }
359  
360 $command .= "-o '$target_avi_file' ";
361 $command .= "-i " if not $self->is_ogg;
362 $command .= "$audio_video_psu_dir/*.$ext";
363  
364 $command .= " && echo EXECFLOW_OK";
365 $command .= " && rm $audio_video_psu_dir/*.$ext"
366 if $self->with_cleanup;
367  
368 return $command;
369 }
370  
371 sub get_split_command {
372 my $self = shift;
373  
374 my $target_avi_file = $self->target_avi_file;
375  
376 my $command = $self->SUPER::get_split_command;
377  
378 $command .= " && rm '$target_avi_file'"
379 if $self->with_cleanup
380 and $command =~ /avisplit|ogmsplit/;
381  
382 return $command;
383 }
384  
385 sub save {
386 my $self = shift;
387  
388 $self->project->save;
389  
390 1;
391 }
392  
393 1;