iphone用に動画をffmpegでエンコードする/その3

とりあえずコマンド打つのがめんどくさいのでスクリプト組んでみた。画面サイズの最適化も入れてみた。 何をやっているのか俺は。 #!/usr/bin/perl -w use strict; my $infile; my $outfile; my $defwidth = 480; my $defheight = 272; my $owidth; my $oheight; $infile = $ARGV[0]; if(!($infile)) { print “USAGE: $0 \n”; exit(1); }elsif($infile eq “”){ print “USAGE: $0 \n”; exit(1); }else{ chomp($infile); $outfile = $infile . “.mp4”; } system("/usr/bin/ffmpeg -i "$infile" 2¥> "$infile.info""); my $ssize; my $swidth; my $sheight; open(FH, “$infile.info”); while(){ my $line = $_; chomp($line); my @buf = split(/\s+/, $line); if($buf[3] eq “Video:”) { $ssize = $buf[6]; $swidth = substr($ssize, 0, index($ssize,“x”)); $sheight = substr($ssize, index($ssize,“x”)+1); chop($sheight); my $ratio = $swidth / $defwidth; $owidth = 480; $oheight = int($sheight / $ratio); } } close(FH); if(!($oheight)) { print “Source image doesnot recognized. Exitting.\n”; unlink("$infile.info"); exit(1); } system("/usr/bin/ffmpeg -threads 4 -i "$infile" -r 29.97 -vcodec libx264 -s ${owidth}x${oheight} -flags +loop -cmp +chroma -deblockalpha 0 -deblockbeta 0 -crf 24 -bt 256k -refs 1 -coder 0 -me umh -me_range 16 -subq 5 -partitions +parti4x4+parti8x8+partp8x8 -g 250 -keyint_min 25 -level 30 -qmin 10 -qmax 51 -trellis 2 -sc_threshold 40 -i_qfactor 0.71 -acodec libfaac -ab 128k -ar 48000 -ac 2 "$outfile""); unlink("$infile.info"); exit(0);

comments powered by Disqus