PDA

View Full Version : HOWTO: convert .flv to .mpg using ffmpeg


DarkN00b
October 24th, 2006, 01:00 PM
I was searching for a program to convert .FLV files to .MPG files. I found an easy way to do it using the command line and ffmpeg. First, you have to make sure you have ffmpeg installed, if you don't then install it from the repositories.

Then:
1. Save a .flv file to a folder (your home folder is fine). I'm going to assume you know how to do this. :-D

2. Open a terminal window and navigate to the folder where you saved the .flv.

3. Type this in the terminal window and hit enter:

ffmpeg -i video.flv -ab 56 -ar 22050 -b 500 -s 320x240 video.mpg

Video.flv is the file you want to convert, so the name must be the same as the source file. You can name video.mpg whatever you want as long as it has the .mpg extension.

Here's an explanation of the options used here:
-b bitrate: set the video bitrate in kbit/s (default = 200 kb/s)
-ab bitrate: set the audio bitrate in kbit/s (default = 64)
-ar sample rate: set the audio samplerate in Hz (default = 44100 Hz)
-s size: set frame size. The format is WxH (default 160x128 )

If you need help, type man ffmpeg.

I use Keepvid (http://keepvid.com/) to download videos from YouTube and Google video. The result is a .flv file I can't watch in Ubuntu. Mplayer does not play the video and VLC doesn't play sound. ](*,)
NOTE:
This was taken from a blog called "The 409". This is not my own work, I just posted it here to make it Ubuntu specific. Go to The 409 (http://asuaf.org/~jj/blog/index.php/2006/01/08/convert-google-video-flvs-into-avi-mpg-etcin-linux/) for the original article.

honeydew
May 11th, 2007, 12:56 AM
I fouund this one laying around and thought it was a good script..


#!/bin/sh

# YouTube Videodownloader for those of us,
# who has no sucking Flash in their browsers.
# If you experience any problems with this script, please
# report them to ivap on SILCNet (https://silcnet.org)
#
# $Id: hacktube.sh,v 0.1.0.9 2007/04/29 00:45:51 ivap Exp $

if [ $# -lt 1 ]; then
echo -e 1>&2 "Usage: $0 [-f] <url or id>"
echo -e 1>&2 "Options:\n\t-f enable ffmpeg postprocessing"
echo -e 1>&2 "Examples: "
echo -e 1>&2 "\t$0 http://www.youtube.com/watch?v=injqufD1WZI"
echo -e 1>&2 "\t$0 injqufD1WZI"
exit 64
fi

while [ $# -ge 1 ]; do
case "$1" in
"-f")
if ! `which ffmpeg >/dev/null 2>&1`; then
echo 1>&2 "ERROR: Install ffmpeg and try again"
exit 69
fi
with_ffmpeg="true"
;;
*youtube*)
vid_url=$1
;;
*)
vid_url=`echo http://www.youtube.com/watch?v= $1 | sed 's/ //g'`
;;
esac
shift
done

if ! `which wget >/dev/null 2>&1`; then
echo 1>&2 "ERROR: Install wget and try again"
exit 69
fi

f_id=`echo $vid_url | sed 's/.*=//1'`
base_url='http://www.youtube.com/get_video?'
temp_fname=`mktemp html_data.XXXXXX`
if [ $? -ne 0 ]; then
echo "ERROR: cannot create temp file"
exit 69
fi

if ! wget -q -O $temp_fname $vid_url; then
echo "ERROR: could not retrieve requested page"
rm $temp_fname
exit 69
fi

new_url=`cat $temp_fname | grep player2.swf | sed 's/va.*?//1' | sed 's/".*;//g'`
complete=`echo $base_url $new_url| sed 's/ //1'`
rm $temp_fname

if ! wget -O ${f_id}.flv $complete; then
echo "ERROR: could not retrieve requested video"
exit 69
fi

#feel free to tune ffmpeg's flags
if [ -n "$with_ffmpeg" ]; then
if ffmpeg -acodec mp3 -i ${f_id}.flv ${f_id}.avi; then
rm ${f_id}.flv
exit 0
else
echo "ERROR: could not convert video"
rm -f ${f_id}.avi
exit 69
fi
fi


save this file and make it executable


chmod +x hacktube.sh


and then type ./hacktube.sh http://youtube.com/url....

enjoy =]

captgadget
May 15th, 2007, 04:44 PM
whenever I try this I get this error message: Big-Fish.flv: I/O error occured
Usually that means that input file is truncated and/or corrupted.

khalidaziz
April 23rd, 2008, 08:48 AM
That means you haven't navigated to the file. Do that by typing

cd /home/khalid/Desktop

replace "/home/khalid/Desktop" with whatever address the folder containing the file has.

ctyc
April 23rd, 2008, 10:13 AM
Very nice ffmpeg trick thanks.
:)

therabbt
April 27th, 2008, 09:10 AM
I can't get this working on Hardy. It worked great on Gutsy though.
Here's what I get. I'm not really sure how to get ffmpeg to work...

spencer@manbearnix:~/Desktop$ ffmpeg -i punched.flv -b 500 -s 320x240 out.mpg
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-pp --enable-swscaler --enable-pthreads --enable-libvorbis --enable-libtheora --enable-libogg --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 1d.49.3.0
libavcodec version: 1d.51.38.0
libavformat version: 1d.51.10.0
built on Mar 12 2008 14:31:53, gcc: 4.2.3 (Ubuntu 4.2.3-2ubuntu4)
punched.flv: Unknown format

Hells_Dark
April 27th, 2008, 09:13 AM
Nice :)
Even if i play the flv format with mplayer.. no problem at all..

Egeste
May 15th, 2008, 02:41 AM
I can't get this working on Hardy. It worked great on Gutsy though.
Here's what I get. I'm not really sure how to get ffmpeg to work...

spencer@manbearnix:~/Desktop$ ffmpeg -i punched.flv -b 500 -s 320x240 out.mpg
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-pp --enable-swscaler --enable-pthreads --enable-libvorbis --enable-libtheora --enable-libogg --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 1d.49.3.0
libavcodec version: 1d.51.38.0
libavformat version: 1d.51.10.0
built on Mar 12 2008 14:31:53, gcc: 4.2.3 (Ubuntu 4.2.3-2ubuntu4)
punched.flv: Unknown format

libavutil version: 1d.49.3.0
libavcodec version: 1d.51.38.0
libavformat version: 1d.51.10.0
built on Mar 12 2008 14:31:53, gcc: 4.2.3 (Ubuntu 4.2.3-2ubuntu4)
sw_attack.flv: Unknown format

ffmpegfailure
June 24th, 2008, 01:22 PM
Sorry, im new to ffmpeg. I tried your command line and this happened. Also, will the same script work for converting to mp4?

username:~$ ffmpeg video.flv -ab 56 -ar 22050 -b 500 -s 320x240 convertedvideo.mpg
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2004 Fabrice Bellard
configuration: --enable-gpl --enable-pp --enable-pthreads --enable-vorbis --enable-libogg --enable-a52 --enable-dts --enable-libgsm --enable-dc1394 --disable-debug --enable-shared --prefix=/usr
libavutil version: 0d.49.0.0
libavcodec version: 0d.51.11.0
libavformat version: 0d.50.5.0
built on Jan 28 2007 22:48:38, gcc: 4.1.2 20070106 (prerelease) (Ubuntu 4.1.1-21ubuntu7)
File video.flv' already exists. Overwrite ? [y/N] y
Cannot open video device /dev/video : No such file or directory
Could not find video grab device
username:~$

iqpilot
August 16th, 2009, 03:20 PM
I got the : Incorrect frame size , but the frame size is apps correct :(

hrvoje@localhost:~/Videos/Music$ ffmpeg -i CarlCox#118.flv -ab 56 -ar 22050 -b 500 -s 320×240 CarlCox#118.mpg
FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --enable-gpl --enable-pp --enable-swscaler --enable-pthreads --enable-libvorbis --enable-libtheora --enable-libogg --enable-libgsm --enable-dc1394 --disable-debug --enable-libmp3lame --enable-libfaadbin --enable-libfaad --enable-libfaac --enable-xvid --enable-x264 --enable-liba52 --enable-amr_nb --enable-amr_wb --enable-shared --prefix=/usr
libavutil version: 1d.49.3.0
libavcodec version: 1d.51.38.0
libavformat version: 1d.51.10.0
built on Mar 17 2009 21:37:49, gcc: 4.2.4 (Ubuntu 4.2.4-1ubuntu3)

Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000/1) -> 12.50 (25/2)
Input #0, flv, from 'CarlCox#118.flv':
Duration: 01:00:41.8, start: 0.000000, bitrate: 128 kb/s
Stream #0.0: Video: vp6f, yuv420p, 640x360, 12.50 fps(r)
Stream #0.1: Audio: mp3, 44100 Hz, stereo, 128 kb/s
Incorrect frame size

Nyken
November 6th, 2009, 01:19 AM
Have Karmic Koala now, but Darkn00b's instruction is currently correct. Had no problems using it.

tomski
November 17th, 2009, 11:34 AM
hi peep's
i use the following:


ffmpeg -i input.flv -target ntsc-dvd -s 648x364 -padleft 36 -padright 36 -padtop 58 -padbottom 58 output.mpg


i would love if some of you guy's out there could create a nautilus/sh script that would allow me to 'bulk' convert an entire folder full of flv files, keep the original filename & output to the input folder as i have approx 10Gb of flv files which i need to convert to mpg to play them on my d-link dsm520 & im getting fed up with doing it manually

i have tried various apps but they just complicate things further and do not want to learn their way lol
i know what i got
i know what i need

and the above code just works for me
thanks

FakeOutdoorsman
November 17th, 2009, 02:39 PM
hi peep's
i use the following:


ffmpeg -i input.flv -target ntsc-dvd -s 648x364 -padleft 36 -padright 36 -padtop 58 -padbottom 58 output.mpg


i would love if some of you guy's out there could create a nautilus/sh script that would allow me to 'bulk' convert an entire folder full of flv files, keep the original filename & output to the input folder as i have approx 10Gb of flv files which i need to convert to mpg to play them on my d-link dsm520 & im getting fed up with doing it manually

i have tried various apps but they just complicate things further and do not want to learn their way lol
i know what i got
i know what i need

and the above code just works for me
thanks

You could use FFmpeg with the find command to bulk convert your files. See andrew.46's excellent guide for details and examples:

Linux Basics: A gentle introduction to 'find' (http://ubuntuforums.org/showthread.php?t=1128937)

tomski
November 19th, 2009, 09:06 AM
thnx for the tip fakeoutdoorsman but i have no scripting experience and have no idea where to begin on implementing your advice!

i guess my post was more of a plea/request to readers to create it
my time is filled by trying to get my ubuntu to work correctly since the koala upgrade, perhaps once this is finished i will attempt to learn bash programming

mc4man
November 19th, 2009, 11:59 AM
For the moment here is a batch convert command that will do as you asked, same filename, same dir. ( using your parameters in blue

for f in *.flv; do ffmpeg -i "$f" -target ntsc-dvd -s 648x364 -padleft 36 -padright 36 -padtop 58 -padbottom 58 "${f%.flv}.mpg"; done

assumes your flash has a .flv ext. ( if no ext. then add

You just cd to the dir. containing files to be converted and run.

As far as a script, I've got to run but you could do it a few different ways, you'd probably want it executed in a visible terminal. (either by starting a terminal at the wanted dir. prompt as above for the command or having that part of the script.