moviebarcode

http://moviebarcode.tumblr.com/

header中的图片就是用到上面的方法,写了段代码生成的EVA破剧场版的moviebarcode,效果还不错,不过方法和网站中所说的有点区别,校正一下。

整理完毕,效果有所提高。主要方法如下,使用mediainfo读取视频文件信息,主要读长宽和视频时长。然后使用mplayer截取图片,然后把图片压到1px宽,然后全叠起来。代码如下:

#!/usr/bin/perl

use strict;
use warnings;
use Image::Magick;

my $movie_name = shift @ARGV;
my @media_info = mediainfo $movie_name;
my ($hours, $minus, $secs, $height, $width);
my $image_width = 1000;
my $image_height = 288;
foreach (@media_info) {
    if(/Duration\s+:\s?(?:(\d+)h)?\s?(?:(\d+)mn)?\s?(?:(\d+)s)?/) {
        $hours = $1 ? $1 : 0;
        $minus = $2 ? $2 : 0;
        $secs  = $3 ? $3 : 0;
    }
    if(/^Width\s+:\s(\d?\s?\d+)\spixels/) {
        $width = $1;
        $width =~ s/\s//g;
    }
    if(/^Height\s+:\s(\d?\s?\d+)\spixels/) {
        $height = $1;
        $height =~ s/\s//g;
    }
}
$secs = $hours * 3600 + $minus * 60 + $secs;
my $per_secs = $secs / $width;
my $image = new Image::Magick;
my $size = $width."x".$height;
$image->Set(size => $size);
$image->Read('NULL:blank');
my $finish_percent = 0;
print "finish:$finish_percent%\n";
foreach (1..$width) {
    my $sec = $per_secs * $_;
    my $cur_per = int($_/$width*100);
    mplayer -ss $sec -noframedrop -nosound -vo png -frames 1 $movie_name 2>/dev/null;
    my $img = new Image::Magick;
    $img->Read("00000001.png");
    $img->Scale(width => 1, height => $height);
    $image->Composite(image => $img, compose => 'Over', x => $_, y => 0);
    if($cur_per > $finish_percent) {
        $finish_percent = $cur_per;
        print "finish:$finish_percent%\n";
    }
}
$image->Write("pic.png");

1 Comment

Leave a Comment

邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据