TIP Converting flash videos
From Gentoo Linux Wiki
Contents |
[edit] Getting flash videos
You can download flash videos with websites such as keepvid or using Firefox add-ins such as Video DownloadHelper.
[edit] Converting flash videos
Use Mediainfo to find out how the flash video was encoded, and use this info to set your encode options.
[edit] Converting flash videos to xvid
mencoder video.flv -ovc xvid -oac mp3lame -xvidencopts bitrate=1500 -o video.avi
mencoder comes with the package media-video/mplayer. The problem is that the sound doesn't match the video so we have to re-convert it with media-video/avidemux.
[edit] Converting flash videos to MP3
Flash videos are not the pinnacle of audio quality. For example, Youtube converts the sound to a 22050 sampling rate mono mp3 with 64K bitrate.
[edit] Using ffmpeg
ffmpeg -i video.flv -ab 64k -ar 22050 videosound.mp3
-i is to specified input file, -ab audio bitrate, -ar audio sampling frequency
[edit] Using mplayer
[edit] dump audio as mp3
mplayer -dumpaudio -dumpfile audio_file.mp3 video.flv
[edit] dump audio as wav and re-encode
mplayer -vc null -vo null -ao pcm -benchmark video.flv
This will output a file named audiodump.wav, then convert this file to mp3 or any other codec:
lame audiodump.wav videosound.mp3
[edit] Perl scripts
i've made a perl script in order to make the conversion with mencoder more easy i've hardcoded the directories...feel free to fork it
#!/usr/bin/perl
#This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
if (!defined(@ARGV)) {
print 'voici le contenu du repertoire panthere rose:',"\n";
print '_____________________________________________',"\n";
system(ls, '/media/hda1/Documents and Settings/FC1/Desktop/panthere rose/');
print '========================================================================================',"\n";
print 'voici le contenu du repertoire rc dand D:',"\n";
print '_________________________________________',"\n";
system(ls, '/media/hda4/rc/');
}
if (defined(@ARGV)) {
# my @cmdline=qw/-ovc xvid -oac mp3lame -xvidencopts bitrate=1500 -o/;
# my $cmdline='-ovc xvid -oac mp3lame -xvidencopts bitrate=1500 -o';
# system(mencoder,$ARGV[0],$cmdline,$ARGV[1]);
system "mencoder '/media/hda1/Documents and Settings/FC1/Desktop/panthere rose/$ARGV[0]' -ovc xvid -oac mp3lame -xvidencopts bitrate=1500 -o '/media/hda4/rc/$ARGV[1]'"
}
#!/usr/bin/perl
#This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
if (!defined(@ARGV)) {
print 'voici le contenu du repertoire panthere rose:',"\n";
print '_____________________________________________',"\n";
system(ls, '/media/hda1/Documents and Settings/FC1/Desktop/panthere rose/');
print '========================================================================================',"\n";
print 'voici le contenu du repertoire rc dand D:',"\n";
print '_________________________________________',"\n";
system(ls, '/media/hda4/rc/');
}
if (defined(@ARGV)) {
#cd to the vfat hdd
system(cd, '/media/hda4/rc/');
#Mplayer extract the audio as a wav
system "mplayer -vc null -vo null -ao pcm -benchmark '/media/hda1/Documents and Settings/FC1/Desktop/panthere rose/$ARGV[0]'";
#Transforming the audiodump.wav into mp3
system "lame audiodump.wav '/media/hda4/rc/$ARGV[1]'";
system (rm, 'audiodump.wav')
}
[edit] Info for the perl scripts
in order to convert flash videos with blank space in the name use the simple quote:
audio.pl 'my flash video.flv' my_flash_video.mp3
by the way the name of my scripts are audio.pl and video.pl (so they don't interfere with others command)
[edit] GUI Perl script
i have made a giu in order to transform flash video in mp3
here are the dependencies:
emerge dev-perl/gtk2-perl
#!/usr/bin/perl -w
#This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# use strict ;
use Gtk2 '-init' ;
use constant FALSE => 0;
use constant TRUE =>1;
our $filename;
our $save_as;
sub quit{
Gtk2->main_quit;
}
sub file_chooser {
my $file_chooser =
Gtk2::FileChooserDialog->new ('Choose a flash video to convert to mp3',
undef, 'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok');
# create a preview widget, which will show a quick summary of information
# about the selected file, updated whenever the selection changes.
# note that this assumes you're on a unix-like system with the 'file'
# utility installed.
my $preview_widget = Gtk2::Label->new;# ('wheeeee');
$preview_widget->set_line_wrap (TRUE);
$preview_widget->set_size_request (150, -1);
$file_chooser->set (preview_widget => $preview_widget,
preview_widget_active => TRUE);
$file_chooser->signal_connect (selection_changed => sub {
$filename = $file_chooser->get_preview_filename;
# we'll hide the preview widget if the selected item is a directory.
# in practice, you may find this really annoying, as it causes the
# window to change size.
my $active = defined $filename && not -d $filename;
if ($active) {
my $size = sprintf '%.1fK', (-s $filename) / 1024;
my $desc = `file '$filename'`;
$desc =~ s/^$filename:\s*//;
$preview_widget->set_text ("$size\n$desc");
}
$file_chooser->set (preview_widget_active => $active);
});
# add an app-specific entry to the shortcut list.
# $file_chooser->add_shortcut_folder ('/tmp');
# eval { $file_chooser->add_shortcut_folder_uri ('http://localhost/'); };
# warn "couldn't add shortcut: $@\n" if $@;
if ('ok' eq $file_chooser->run) {
# you can get the user's selection as a filename or a uri.
# my $uri = $file_chooser->get_uri;
# print "uri $uri\n";
# $filename = $file_chooser->get_filename;
# print "$filename\n";
}
$file_chooser->destroy;
}
sub file_saver {
my $dialog = Gtk2::FileChooserDialog->new('Save as',undef,'save',
'gtk-ok', 'ok',
'gtk-cancel', 'cancel');
my $response = $dialog->run(); # this blocks
if ($response eq 'ok') {
$save_as = $dialog->get_filename();
}
$dialog->destroy;
}
my $dialog = Gtk2::Dialog->new ('convertisseur flv->mp3', $main_app_window,
'destroy-with-parent',
'Choisir un fichier flv' => '1',
'sauvegarder sous forme de mp3' => '2',
'convertir' => '3');
$dialog->signal_connect (response => \&button_response );
$dialog->signal_connect(delete_event => \&quit);
sub button_response {
my ($dialog, $response_id) = @_;
if ($response_id eq '1') {
file_chooser();
}
if ($response_id eq '2') {
file_saver();
}
if ($response_id eq '3') {
# sub destroy {
# $finished->destroy;
# }
$test=1;
chdir "/tmp";
# print "$save_as\n";
# open(INPUT, " mplayer -vc null -vo null -ao pcm -benchmark /home/gentux/luniz -slave|");
# && lame audiodump.wav /tmp/luniz.mp3
system "ffmpeg -i '$filename' -vn -acodec copy '$save_as' ";
my $finished = Gtk2::Dialog->new ('La conversion est finie', undef,'destroy-with-parent', 'ok' => '4');
$label = Gtk2::Label->new("le mp3 se trouve a l'endroit suivant: $save_as");
$finished->vbox->add ($label);
$finished->signal_connect (response => \&quit );
$finished->show_all;
}
}
$dialog->show_all;
Gtk2->main;
[edit] GUI for converting flash videos in xvid
#!/usr/bin/perl -w
#This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
#This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
use strict ;
use Gtk2 '-init' ;
use Gtk2::Helper;
use Glib qw(TRUE FALSE);
use Time::HiRes qw(usleep);
use FileHandle;
our $filename;
our $save_as;
our $progressbar;
sub quit{
Gtk2->main_quit;
}
sub pulse {
# $progressbar = shift;
$progressbar->set_pulse_step(1/10);
$progressbar->pulse;
return 1;
}
sub finished {
my $finished = Gtk2::Dialog->new ('The conversion has finished', undef,'destroy-with-parent', 'ok' => '4');
my $label = Gtk2::Label->new("you can find the xvid here: $save_as");
$finished->vbox->add ($label);
$finished->signal_connect (response => \&quit );
$finished->show_all;
#print "the conversion has finished\n"
}
sub progressbar {
Gtk2->main_iteration while Gtk2->events_pending;
# $progressbar->set_pulse_step(0.1 ) ;
$progressbar->pulse;
usleep(100000);
}
sub file_chooser {
my $file_chooser =
Gtk2::FileChooserDialog->new ('Choose a flash video to convert to xvid',
undef, 'open',
'gtk-cancel' => 'cancel',
'gtk-ok' => 'ok');
# create a preview widget, which will show a quick summary of information
# about the selected file, updated whenever the selection changes.
# note that this assumes you're on a unix-like system with the 'file'
# utility installed.
my $preview_widget = Gtk2::Label->new;
$preview_widget->set_line_wrap (TRUE);
$preview_widget->set_size_request (150, -1);
$file_chooser->set (preview_widget => $preview_widget,
preview_widget_active => TRUE);
$file_chooser->signal_connect (selection_changed => sub {
$filename = $file_chooser->get_preview_filename;
# we'll hide the preview widget if the selected item is a directory.
# in practice, you may find this really annoying, as it causes the
# window to change size.
my $active = defined $filename && not -d $filename;
if ($active) {
my $size = sprintf '%.1fK', (-s $filename) / 1024;
my $desc = `file '$filename'`;
$desc =~ s/^$filename:\s*//;
$preview_widget->set_text ("$size\n$desc");
}
$file_chooser->set (preview_widget_active => $active);
});
# add an app-specific entry to the shortcut list.
# $file_chooser->add_shortcut_folder ('/tmp');
# eval { $file_chooser->add_shortcut_folder_uri ('http://localhost/'); };
# warn "couldn't add shortcut: $@\n" if $@;
if ('ok' eq $file_chooser->run) {
# you can get the user's selection as a filename or a uri.
# my $uri = $file_chooser->get_uri;
# print "uri $uri\n";
# $filename = $file_chooser->get_filename;
# print "$filename\n";
}
$file_chooser->destroy;
}
sub file_saver {
my $dialog = Gtk2::FileChooserDialog->new('Save as',undef,'save',
'gtk-ok', 'ok',
'gtk-cancel', 'cancel');
my $response = $dialog->run(); # this blocks
if ($response eq 'ok') {
$save_as = $dialog->get_filename();
}
$dialog->destroy();
}
my $main_app_window;
my $dialog = Gtk2::Dialog->new ('flv->xvid convertissor', $main_app_window,
'destroy-with-parent',
'Choose a flv file' => '1',
'Save in Xvid format' => '2',
'Convert' => '3',
"Afficher l'endroit ou se trouve le xvid" => '4'
);
$dialog->signal_connect (response => \&button_response );
$dialog->signal_connect(delete_event => \&quit);
$progressbar = Gtk2::ProgressBar->new;
$dialog->vbox->add ($progressbar);
sub button_response {
my ($dialog, $response_id) = @_;
if ($response_id eq '1') {
file_chooser();
}
if ($response_id eq '2') {
file_saver();
}
if ($response_id eq '3') {
# $test=1;
chdir "/tmp";
# open my $pipe, '-|', "mencoder '$filename' -ovc xvid -oac mp3lame -xvidencopts bitrate=1500 -o '$save_as'" or die "can't do the processing";
#
# my $tag;
# $tag = Gtk2::Helper->add_watch( fileno( $pipe ), in => sub {
# if ( eof( $pipe ) ) {
# Gtk2::Helper->remove_watch( $tag );
# close( $pipe );
# my $finished = Gtk2::Dialog->new ('The conversion has finished', undef,'destroy-with-parent', 'ok' => '4');
# my $label = Gtk2::Label->new("you can find the xvid here: $save_as");
# $finished->vbox->add ($label);
# $finished->signal_connect (response => \&quit );
# $finished->show_all;
# }
# else {
# # $progressbar->{timer} = Glib::Timeout->add(100,\&pulse);
# Gtk2->main_iteration while Gtk2->events_pending;
# # $progressbar->set_pulse_step(0.1 ) ;
# $progressbar->pulse;
# usleep(100000);
# }
my $pipe = FileHandle->new;
open $pipe, '-|', "mencoder '$filename' -ovc xvid -oac mp3lame -xvidencopts bitrate=1500 -o '$save_as'" or die "can't do the processing";
my $watch;
$watch = Gtk2::Helper->add_watch ( $pipe->fileno, 'in', sub {
watcher_callback( $pipe, $watch );
});
sub watcher_callback {
my ($pipe, $watch) = @_;
# we safely can read a chunk into $buffer
my $buffer;
if ( not sysread($pipe, $buffer, 4096) ) {
# obviously the connected pipe was closed
finished();
Gtk2::Helper->remove_watch ($watch) or die "couldn't remove watcher";
close($pipe);
return 1;
}
# do something with $buffer ...
# print $buffer;
progressbar();
# *always* return true
return 1;
}
return 1;
if ($response_id eq '4') {
print "$save_as\n";
}
}
}
$dialog->show_all;
Gtk2->main;
[edit] GUI for converting all the flash videos that are in a folder in mp3
#!/usr/bin/perl #This program is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or #(at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program. If not, see <http://www.gnu.org/licenses/>. use Gtk2 '-init' ; use Gtk2::Helper; use Glib qw(TRUE FALSE); use Time::HiRes qw(usleep); use FileHandle; use strict; our $save_as; our $destdir; our $input; # our $save_as; our @save_as; our $pipe = FileHandle->new; my $main_app_window; my $dialog = Gtk2::Dialog->new ('mass_flv2mp3', $main_app_window, 'destroy-with-parent', "Choisir un dossier" => '1' , "Destination" => '2', "transformer" => '3' ); $dialog->signal_connect (response => \&button_response ); $dialog->signal_connect(delete_event => \&quit); our $progressbar = Gtk2::ProgressBar->new; $dialog->vbox->add ($progressbar); sub button_response { my ($dialog, $response_id) = @_; if ($response_id eq '1') { folder_chooser(); } if($response_id eq '2') { destination(); } if($response_id eq '3') { processing(); } if($response_id eq '4') { quit(); } } sub folder_chooser { my $dialog = Gtk2::FileChooserDialog->new('Choisir un dossier a convertir',undef,'open', 'gtk-ok', 'ok', 'gtk-cancel', 'cancel'); $dialog->set_action('select-folder'); my $response = $dialog->run(); # this blocks if ($response eq 'ok') { $input = $dialog->get_filename(); } $dialog->destroy(); } sub destination { my $dialog = Gtk2::FileChooserDialog->new('Destination',undef,'open', 'gtk-ok', 'ok', 'gtk-cancel', 'cancel'); $dialog->set_action('select-folder'); my $response = $dialog->run(); # this blocks if ($response eq 'ok') { $destdir = $dialog->get_filename(); } $dialog->destroy(); } sub quit { Gtk2->main_quit; } sub processing { print "input: $input\n"; print "output: $destdir\n"; opendir(DIR, $input) or die "can’t opendir $input: $!"; our @files = readdir(DIR); @files = File::Spec->no_upwards( @files ); # remoove the . and the .. our $file; foreach $file (@files) { $save_as = "$file.mp3"; push (@save_as,$save_as) } our $files_number = @files; for my $i (0..($files_number -1)) { print "###########################################################################################################################\n"; print "files: $destdir/$files[$i] \n"; print "destdir/saveas: $input/$save_as[$i] \n"; print "###########################################################################################################################\n"; our $final_input = "$input/$files[$i]"; our $final_output = "$destdir/$save_as[$i]"; open $pipe, '-|', "ffmpeg", "-i", "$final_input", "-vn", "-acodec", "copy", "$final_output" or die "line 91: $files[$i] and $destdir/$save_as[$i] "; } my $watch; $watch = Gtk2::Helper->add_watch ( $pipe->fileno, 'in', sub { watcher_callback( $pipe, $watch ); }); sub watcher_callback { my ($pipe, $watch) = @_; # we safely can read a chunk into $buffer my $buffer; if ( not sysread($pipe, $buffer, 4096) ) { # obviously the connected pipe was closed finished(); Gtk2::Helper->remove_watch ($watch) or die "couldn't remove watcher"; close($pipe); return 1; } # do something with $buffer ... print $buffer; # progressbar(); $progressbar->{timer} = Glib::Timeout->add(1000, \&progressbar, $progressbar); # *always* return true return 1; } } sub progressbar { $progressbar->{timer} = Glib::Timeout->add(100, \&progressbar, $progressbar); } sub finished { my $finished = Gtk2::Dialog->new ('The extraction has finished', undef,'destroy-with-parent', 'ok' => '4'); my $label = Gtk2::Label->new("point k9copy to the dvd folder that you can find in this folder: $save_as"); $finished->vbox->add ($label); $finished->signal_connect (response => \&quit ); $finished->show_all; $finished->signal_connect (response => \&button_response ); } $dialog->show_all; Gtk2->main; 0;
