CUFP
strredwolf
<P>If you're in the furry fandom, more often than not you heard of the videos of a certain Big Blue Fox by the name of BBF TV HD. They're by a German video editor who works at RTL, and of when he and the Eurofurance crew visits a furry convention. It's a great way to get an idea of what a con is, or if you missed it, what happened.</P>
<P>I pulled most of the videos from his site, and every so often I tweak the encode settings to mencoder to do it... except mencoder doesn't do bframes right. I switched over to ffmpeg (not avconvert from the rogue libav gang; the original ffmpeg)... which doesn't have a nice status line.</P>
<P>Thankfully ffmpeg hit 1.0 and got a -progress option, which gives a nice status readout. Too bad my build outputs to a file, md5 code, or a pipe.. aka an opened file descriptor. Forget named pipes, it'll recreate 'em as a file.</p>
<P>After some hacking around... I have this! The settings in the ffmpeg command match that for a 2nd Gen AppleTV, but I also have info for the 3rd Gen/iPhone 5/iPad 4. I name this version atv-enc.pl. It takes two arguments: atv-enc.pl input output</P>
<p><B>EDIT:</b> Whoops, a few bugs crept in with the bar. Fixed, and enhanced a bit.</p>
<P>
<readmore>
<code>#!/usr/bin/perl
use POSIX qw(mkfifo);
use Fcntl;
use IO::Handle;
use strict;
$|=1;
print "############\n";
my %prog;
my $infile=$ARGV[0];
my $outfile=$ARGV[1];
# get some stats
my $frametotal,$fwide,$fhigh;
open(IN,"ffprobe -show_streams '$infile' 2>/dev/null |") ||
die "$infile: $!";
while(<IN>) {
chomp;
$frametotal=$1 if(/^nb_frames=(\d+)/);
$fwide=$1 if(/^width=(\d+)/);
$fhigh=$1 if(/^height=(\d+)/);
last if(/^\[\/STREAM\]/);
}
close(IN);
my @acmd;
@acmd=("-acodec","libfaac","-ac","2","-ab","160k");
my @vcmd=qw/-c:v libx264 -vprofile main -preset slow -tune film -level 3.1 -crf 28 -threads 0/;
if($fwide > 1280 || $fhigh > 720) {
@vcmd=(@vcmd,"-vf","scale=min(1280\\,iw):-1");
}
pipe(IN, OUT); # We read from IN, ffmpeg writes to OUT.
OUT->autoflush(1); # Autoflush on, close-on-exec off
my $val=fcntl(OUT,F_GETFD,0) || die "Error: fcntl GET: $!";
$val &= ~FD_CLOEXEC;
fcntl(OUT,F_SETFD,$val) || die "Error: fcntl SET: $!";
my $fd=fileno OUT;
my @cmd=("ffmpeg","-progress","pipe:$fd","-v","panic",
"-i",$infile, @acmd,@vcmd,@metadata,$outfile);
my $pid=fork(); # Fork the kid
unless($pid) {
die "Can't fork! $!" unless defined $pid;
close(IN);
exec @cmd or die "Can't exec! $!";
}
# parent.
close(OUT);
while(<IN>) {
chomp;
my ($a,$b)=split /=/;
$prog{$a}=$b;
if($a eq "progress") {
my $pcent=$prog{"frame"}/$frametotal*100;
my $hcent=int($pcent/2);
my $bar="[".("#" x $hcent).(" " x (50-$hcent))." ] ";
$bar .=sprintf("%.2f",$pcent)."% fps=".$prog{"fps"};
print "\r$bar";
}
}
print "\nWaiting for finish...\n";
waitpid($pid,0);
</code>
</readmore>
</p>
<div class="pmsig"><div class="pmsig-13922">
<I>Information doesn't want to be free. It wants to be <b>feline</b>.</I>
</div></div>