Выдираем кадры из avi-ки

Для одного из своих сайтов мне понадобилось выдирать кадры из avi-файл, чтобы использовать при описании файлов.

Будем это делать в Linux и конечно все должно быть бесплатно.

Для этого я написал небольшой перловый скрипт. в нем задается имя входного файла, количество нужных кадров и ширину нужного нам изображения на выходе.

Для работы скрипта нужен ffmpeg и imagemagic (конечно все это у Вас уже установлено 🙂 )

Вот сам скрипт:

#!/usr/bin/perl                                                                                                                                                                    
use POSIX;                                                                                                                                                                          

$iname='1.avi';                                                                                                                                                                    
$scr_count=1;                                                                                                                                                                      
$resize='250';                                                                                                                                                                      

$dur=`ffmpeg -i $iname 2>&1`; #print $dur;                                                                                                                                         
$dur=~ /(\d{1,2})\:(\d{2})\:(\d{2})\./;                                                                                                                                            
$hout=$1; $min=$2; $sec=$3;                                                                                                                                                        
$mins=$1*60+$2; #print "mins = $mins \n";                                                                                                                                          
for($i=0;$i<$scr_count;$i++) {                                                                                                                                                     
 $mi=floor(rand($mins)); #print "mi=$mi ";                                                                                                                                      
 $h=floor($mi/60); #print "h=$h ";                                                                                                                                              
 $m=$mi-$h*60; #print "m=$m ";                                                                                                                                                  
 $s=floor(rand(60));                                                                                                                                                            
 $scr_time="$h:$m:$s";                                                                                                                                                          
 $cmd="ffmpeg -i $iname -an -ss $scr_time -an -vframes 1 -y  $i.jpg";                                                                                                           
 print `$cmd`."\n";                                                                                                                                                             
 $cmd="mogrify -resize 250 $1.jpg";                                                                                                                                             
 if ($resize ne '') {print `$cmd`."\n";}                                                                                                                                        
 }

В результате получаем изображение типа такого:

0

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *

CAPTCHA image
*