«

»

Ago 02 2009

Convertir MP4 y FLV a AVI con Avidemux

Con el lector electrónico, resolví el problema que tenía para leer todos los libros y artículos que me interesaban en Internet sin tener que estar delante del ordenador.

Sin embargo, los vídeos se me resistían: al descargar vídeos de YouTube (con el Flash Video Downloader), Miro (los vídeos descargados se guardan en ~/.miro/Movies) o cualquier otro sistema parecido, acababa con archivos Flash (FLV) o MP4 usando el códec H264 que ni la PDA ni el reproductor multimedia del salón eran capaces de reproducir.

Después de pelearme con el Mobile Media Converter, el Arista Transcoder y otros parecidos, el que menos problemas me ha dado ha sido el Avidemux, que además incorpora la opción de usar scripts. Para instalar este último en Ubuntu:
sudo apt-get install avidemux

Con Avidemux y con este simple script en Perl (guardar como mp4toavi.pl), se pueden convertir en un solo paso todos los archivos MP4 y FLV en un directorio al formato AVI (XVID/MP3).

#!/bin/perl
# Convert MP4/FLV files into AVI (XVID/MP3)
# @author   José Miguel Cotrino
# @date     01.03.2010
#
use strict;my $dir = $ARGV[0];
my $tmp = “tmp.js”;
if( !defined($dir) or $dir eq “” ) {

die “Please specify a directory where to look for MP4/FLV files”;

}

print “Parsing MP4/FLV files at $dir…\n;
foreach my $file (<$dir/*>) {
if( $file =~ m/\.mp4$/ ) {
process($file,“mp4”);
} elsif( $file =~ m/\.flv$/ ) {
process($file,“flv”);
}
}

exit 0;

sub process($$) {
my($source,$format) = @_;
my $target = $source;
$target =~ s/\.$format$/\.avi/;
print “Converting \”$source\” into \”$target\”\n;
open(SCRIPT, “>$tmp”);
print SCRIPT <<SCRIPTEND;
//AD
//–automatically built–
var app = new Avidemux();
// Load the file
app.forceUnpack();
app.load(“$source”);
app.rebuildIndex();
//** Video Codec conf **
app.video.codecPlugin(“92B544BE-59A3-4720-86F0-6AD5A2526FD2”, “Xvid”, “CQ=4”, “<?xml version=’1.0′?><XvidConfig><presetConfiguration><name><default></name><type>default</type></presetConfiguration><XvidOptions><threads>0</threads><vui><sarAsInput>false</sarAsInput><sarHeight>1</sarHeight><sarWidth>1</sarWidth></vui><motionEstimation>low</motionEstimation><rdo>dct</rdo><bFrameRdo>false</bFrameRdo><chromaMotionEstimation>false</chromaMotionEstimation><qPel>false</qPel><gmc>false</gmc><turboMode>false</turboMode><chromaOptimiser>false</chromaOptimiser><fourMv>false</fourMv><cartoon>false</cartoon><greyscale>false</greyscale><interlaced>none</interlaced><frameDropRatio>0</frameDropRatio><maxIframeInterval>0</maxIframeInterval><maxBframes>0</maxBframes><bFrameSensitivity>0</bFrameSensitivity><closedGop>false</closedGop><packed>false</packed><quantImin>2</quantImin><quantPmin>2</quantPmin><quantBmin>2</quantBmin><quantImax>31</quantImax><quantPmax>31</quantPmax><quantBmax>31</quantBmax><quantBratio>150</quantBratio><quantBoffset>100</quantBoffset><quantType>h.263</quantType><intraMatrix><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value><value>8</value></intraMatrix><interMatrix><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value><value>1</value></interMatrix><trellis>false</trellis><singlePass><reactionDelayFactor>0</reactionDelayFactor><averagingQuantiserPeriod>0</averagingQuantiserPeriod><smoother>0</smoother></singlePass><twoPass><keyFrameBoost>0</keyFrameBoost><maxKeyFrameReduceBitrate>0</maxKeyFrameReduceBitrate><keyFrameBitrateThreshold>0</keyFrameBitrateThreshold><overflowControlStrength>5</overflowControlStrength><maxOverflowImprovement>5</maxOverflowImprovement><maxOverflowDegradation>5</maxOverflowDegradation><aboveAverageCurveCompression>0</aboveAverageCurveCompression><belowAverageCurveCompression>0</belowAverageCurveCompression><vbvBufferSize>0</vbvBufferSize><maxVbvBitrate>0</maxVbvBitrate><vbvPeakBitrate>0</vbvPeakBitrate></twoPass></XvidOptions></XvidConfig>”);
//** Audio **
app.audio.reset();
app.audio.codec(“Lame”,128,20,”80 00 00 00 00 00 00 00 01 00 00 00 02 00 00 00 00 00 00 00 “);
app.audio.normalizeMode=0;
app.audio.normalizeValue=0;
app.audio.delay=0;
app.audio.mixer=”NONE”;
app.setContainer(“AVI”);
app.save(“$target”);
app.exit();
//End of script
SCRIPTEND

close(SCRIPT);
system(“avidemux –force-alt-h264 –run $tmp”);
unlink($tmp);
}

Para ejecutarlo, basta con:
perl mp4toavi.pl /directory_con_mp4s

Actualización: he cambiado el código para que funciona con Avidemux 2.5.1.

Artículos relacionados:

FacebookRedditMeneameotros