1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
use DBI; |
---|
18 |
use DBD::Pg; |
---|
19 |
use Jcode; |
---|
20 |
|
---|
21 |
|
---|
22 |
$path = $0; |
---|
23 |
$path =~ s/ipodtranscode.pl$//i; |
---|
24 |
if ($pwd ne "./"){ |
---|
25 |
push( @INC, "$path"); |
---|
26 |
} |
---|
27 |
|
---|
28 |
require "foltialib.pl"; |
---|
29 |
|
---|
30 |
$recch = $ARGV[0] ; |
---|
31 |
if ($recch eq "" ){ |
---|
32 |
|
---|
33 |
print "usage ipodtranscode.pl /path/to/mpeg2.m2p mp4filenamestring /path/to/mpeg2/tid.localized/mp4/ PID [aspect]\n"; |
---|
34 |
exit; |
---|
35 |
} |
---|
36 |
|
---|
37 |
$inputmpeg2 = $ARGV[0]; |
---|
38 |
$mp4filenamestring = $ARGV[1]; |
---|
39 |
$mp4outdir = $ARGV[2]; |
---|
40 |
$pid = $ARGV[3]; |
---|
41 |
$aspect = $ARGV[4]; |
---|
42 |
|
---|
43 |
|
---|
44 |
my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", |
---|
45 |
$DBDriv,$DBName,$DBHost,$DBPort); |
---|
46 |
$dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; |
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 |
if ($pid ne ""){ |
---|
51 |
|
---|
52 |
$DBQuery = "SELECT title , countno , subtitle |
---|
53 |
FROM foltia_program, foltia_subtitle |
---|
54 |
WHERE foltia_program.tid = foltia_subtitle.tid |
---|
55 |
AND foltia_subtitle.pid = $pid "; |
---|
56 |
$sth = $dbh->prepare($DBQuery); |
---|
57 |
$sth->execute(); |
---|
58 |
@programtitle = $sth->fetchrow_array; |
---|
59 |
$programtitle[0] =~ s/\"/\\"/gi; |
---|
60 |
$programtitle[2] =~ s/\"/\\"/gi; |
---|
61 |
|
---|
62 |
if ($pid > 0){ |
---|
63 |
if ($programtitle[1] ne ""){ |
---|
64 |
$movietitle = " -title \"$programtitle[0] 第$programtitle[1]話 $programtitle[2]\" "; |
---|
65 |
$movietitleeuc = " -t \"$programtitle[0] 第$programtitle[1]話 $programtitle[2]\" "; |
---|
66 |
}else{ |
---|
67 |
$movietitle = " -title \"$programtitle[0] $programtitle[2]\" "; |
---|
68 |
$movietitleeuc = " -t \"$programtitle[0] $programtitle[2]\" "; |
---|
69 |
} |
---|
70 |
}elsif($pid < 0){ |
---|
71 |
|
---|
72 |
$movietitle = " -title \"$programtitle[2]\" "; |
---|
73 |
$movietitleeuc = " -t \"$programtitle[2]\" "; |
---|
74 |
}else{ |
---|
75 |
|
---|
76 |
$movietitle = ""; |
---|
77 |
$movietitleeuc = ""; |
---|
78 |
} |
---|
79 |
|
---|
80 |
$movietitle = ""; |
---|
81 |
$movietitleeuc = ""; |
---|
82 |
|
---|
83 |
} |
---|
84 |
|
---|
85 |
if ($aspect == 16){ |
---|
86 |
$cropopt = " -croptop 70 -cropbottom 60 -cropleft 8 -cropright 14 -aspect 1.7777 "; |
---|
87 |
}else{ |
---|
88 |
$cropopt = " -croptop 8 -cropbottom 8 -cropleft 8 -cropright 14 "; |
---|
89 |
} |
---|
90 |
|
---|
91 |
if (($trconqty eq "")||($trconqty == 1)){ |
---|
92 |
|
---|
93 |
$encodeoption = "-y -i $inputmpeg2 -vcodec xvid $cropopt -s 320x240 -b 300 -bt 128 -r 14.985 -bufsize 192 -maxrate 512 -minrate 0 -deinterlace -acodec aac -ab 128 -ar 24000 -ac 2 $movietitle ${mp4outdir}M4V${mp4filenamestring}.MP4"; |
---|
94 |
$mp4file = "${mp4outdir}M4V${mp4filenamestring}.MP4"; |
---|
95 |
|
---|
96 |
}elsif($trconqty == 2){ |
---|
97 |
|
---|
98 |
$encodeoption = "-y -i $inputmpeg2 -target ipod -profile 51 -level 30 $cropopt -s 320x240 -b 300 -r 24 -acodec aac -ar 32000 -ac 2 $movietitle ${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
99 |
$mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
100 |
|
---|
101 |
}elsif($trconqty == 3){ |
---|
102 |
|
---|
103 |
$encodeoption = "-y -i $inputmpeg2 -target ipod -profile 51 -level 30 $cropopt -acodec aac -ab 96 -vcodec h264 -maxrate 700 -minrate 0 -deinterlace -b 300 -ar 32000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 320x240 -r 30000/1001 -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 $movietitle ${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
104 |
$mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4"; |
---|
105 |
} |
---|
106 |
|
---|
107 |
$encodeoptionlog = $encodeoption; |
---|
108 |
Jcode::convert(\$encodeoptionlog,'euc'); |
---|
109 |
|
---|
110 |
&writelog("ipodtranscode START QTY=$trconqty $encodeoptionlog"); |
---|
111 |
|
---|
112 |
system ("/usr/local/bin/ffmpeg $encodeoption "); |
---|
113 |
&writelog("ipodtranscode FFEND $inputmpeg2"); |
---|
114 |
|
---|
115 |
&writelog("ipodtranscode mp4psp -p $mp4file $movietitleeuc"); |
---|
116 |
system("/usr/local/bin/mp4psp -p $mp4file '$movietitleeuc' "); |
---|
117 |
&writelog("ipodtranscode mp4psp COMPLETE $mp4file "); |
---|
118 |
|
---|