root/trunk/install/perl/ipodtranscode.pl

リビジョン 70, 4.7 kB (コミッタ: sorshi, コミット時期: 16 年 前)

環境ポリシー機能搭載

  • svn:executable 属性の設定値: *
Line 
1 #!/usr/bin/perl
2 #usage ipodtranscode.pl /path/to/mpeg2.m2p mp4filenamestring /path/to/mpeg2/tid.localized/mp4/ PID [aspect]
3 #
4 # Anime recording system foltia
5 # http://www.dcc-jpl.com/soft/foltia/
6 #
7 #
8 # iPod MPEG4/H.264トラコン
9 # ffmpegを呼び出して変換
10 # ffmpegはiPodパッチあて版を想定している
11 # ffmpegの作り方は
12 # http://www.dcc-jpl.com/diary/ddata2006/02A.html#20060215-00
13 #
14 # DCC-JPL Japan/foltia project
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 #DB初期化
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         #EPG
72                 $movietitle = " -title \"$programtitle[2]\" ";
73                 $movietitleeuc = " -t \"$programtitle[2]\" ";
74         }else{# 0
75         #空白
76         $movietitle = "";
77         $movietitleeuc = "";
78         }
79 #Jcode::convert(\$movietitle,'utf8');# Title入れるとiTunes7.0.2がクラッシュする
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)){#sample:src 106.6sec encode 82sec x0.77 382kbps @Celeron2.6GHz
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){ #sample:src 106.6sec encode 117sec x1.1 597kbps @Celeron2.6GHz
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){ #sample:src 106.6sec encode 364sec x3.4 528kbps @Celeron2.6GHz
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 }elsif($trconqty == 4){ #sample:src 106.6sec encode 239sec x2.24 1036kbps @Celeron2.6GHz
107
108 $encodeoption = "-y -i $inputmpeg2  -target ipod -profile 51 -level 30 $cropopt -s 480x360 -b 400 -r 24 -acodec aac -ar 32000 -ac 2 $movietitle ${mp4outdir}MAQ${mp4filenamestring}.MP4";
109 $mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4";
110
111 }elsif($trconqty == 5){ #sample:src 106.6sec encode 1012sec x9.49 727kbps @Celeron2.6GHz
112
113 $encodeoption = "-y -i $inputmpeg2  -target ipod -profile 51 -level 30 $cropopt  -acodec aac -ab 96 -vcodec h264  -maxrate 700 -minrate 0 -deinterlace -b 400 -ar 32000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 480x360 -r 30000/1001  -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 $movietitle ${mp4outdir}MAQ${mp4filenamestring}.MP4";
114 $mp4file = "${mp4outdir}MAQ${mp4filenamestring}.MP4";
115 }
116
117
118
119 $encodeoptionlog = $encodeoption;
120 Jcode::convert(\$encodeoptionlog,'euc');
121
122 &writelog("ipodtranscode START QTY=$trconqty $encodeoptionlog");
123 #print "ffmpeg $encodeoptionlog \n";
124 system ("/usr/local/bin/ffmpeg  $encodeoption ");
125 &writelog("ipodtranscode FFEND $inputmpeg2");
126
127 &writelog("ipodtranscode mp4psp -p $mp4file $movietitleeuc");
128 system("/usr/local/bin/mp4psp -p $mp4file '$movietitleeuc' ");
129 &writelog("ipodtranscode mp4psp COMPLETE  $mp4file ");
130
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed