こちらと、
http://blog.suz-lab.com/2010/01/ffmpeg.html
こちらの、
http://blog.suz-lab.com/2010/01/theschwartz-ffmpegcommand.html
合わせ技です。
コードはこんな感じになります。
--------【Perl】--------
use strict;
use warnings;
use base qw(TheSchwartz::Worker);
use TheSchwartz::Job;
use FFmpeg::Command;
use Log::Dispatch;
use constant BASE_PATH => "/var/www/html/master";
sub work {
# ログの設定
my $log = Log::Dispatch->new(outputs => [[
"Screen",
min_level => 'debug',
stderr => 1,
newline => 1
]]);
# パラメータの取得
my $class = shift;
my TheSchwartz::Job $job = shift;
my $material_id = $job->arg->{material_id};
my $material_ext = "mp4";
# 変換元動画
my $src_file = BASE_PATH . "/" . $material_id . "." . $material_ext;
$log->debug("src_file: " . $src_file);
# 変換先動画
my $flv_file = BASE_PATH . "/" . $material_id . ".flv";
$log->debug("flv_file: " . $flv_file);
# FFmpegの設定
my $ffmpeg = FFmpeg::Command->new();
$ffmpeg->input_options({
file => $src_file,
});
$ffmpeg->output_options({
file => $flv_file,
format => "flv" # 出力フォーマットはFLV
});
$ffmpeg->options(
"-y", # FFmpegの問い合わせに自動でYesで返答
"-an", # 音声の処理はしない
"-ss" => 0, # 最初から切り取る
"-t" => 4 # 4秒間切り取る
);
# FFmpegの実行
if($ffmpeg->exec()) {
$log->debug("Completed");
$job->completed();
} else {
$log->debug("Failed: " . $ffmpeg->errstr);
$job->failed($ffmpeg->errstr);
}
}
sub max_retries { 3 }
sub retry_delay { 20 }
1;
--------
ポイントは、まさに、下記です。
> $ffmpeg->options(
> "-y", # FFmpegの問い合わせに自動でYesで返答
> "-an", # 音声の処理はしない
> "-ss" => 0, # 最初から切り取る
> "-t" => 4 # 4秒間切り取る
> );
FFmpegネタ、もう一つやったら今日は寝よう...
--------
http://www.suz-lab.com

0 コメント:
コメントを投稿