The FFmpeg command line is
pretty simple:
ffmpeg -i infile outfile
That's all there is to a basic
command. You list your input
file preceded by an -i flag.
You list your output file as the
last file on the command line.
To convert from one file format
to another, you do this:
ffmpeg -i infile.avi outfile.mpg
FFmpeg does its best to set defaults
for you. Of course, you can explicitly
override the defaults on the command
line.
See the ffmpeg man page for more
details.
Ed Abbott
Sunday, July 24, 2011
Using FFmpeg to
Create a Slide-Show Video
I worked on this problem all day
yesterday. I've been trying to
create a slide-show video accompanied
by sound.
I want to upload my video to YouTube
once I've finished creating it. First,
though, I had to create the video. FFmpeg
is my chosen tool.
Here is what I tried first:
The above command line did not work. However,
I learned a lot by having it fail. Mostly I
learned to avoid false assumptions.
My sound file was 12 seconds long. As you
can see, the above command line has only one
image and one sound file.
I figured that FFmpeg would interpret
the above command line the only way that I
would consider to be reasonable. I figured
it would throw my one image on the screen
and then run my video for the length of the
sound file.
In other words, I thought FFmpeg would stretch
the time my one and only image stayed on the screen
to match the length of my audio file. Single
images do not have a duration but a sound file
does. So why not stretch the viewing time of
the image to match the sound?
Of course, I was thinking like a human being
rather than a computer. In life, that's
the totally right thing to do.
It's the wrong thing to do If you're trying
to tell a computer what to do. When talking
to a human being, think human. When talking
to a computer, think computer.
The thing I overlooked is the fact that FFmpeg
is primarily designed to create movies, not
sound tracks. Therefore, the movie trumps the
sound.
The above FFmpeg command line truncated my
sound. I'm surprised I was able to hear any
sound at all. I heard about one second of
sound.
I suspect what happened is that my one image
in the above command line became the one frame
in my movie. Thinking like a computer,
this is a totally reasonable thing to do. Take
one image and turn it into a one frame movie.
When the one frame is done, the movie is done.
That's what I think happened.
The reason I'm surprised I heard the sound at
all is because I never saw my one frame. I only
heard my one second of sound.
Here are the statistics that FFmpeg output after
completing execution of the above command line:
frame = 1
fps = 0
time = 12.4
The above statistics give me some insight into
what really happened. Probably my player got
confused. I fed my video player a video that
is 12.4 seconds long but that runs at zero
frames per second. Does this make any sense?
Not to my video player, apparently.
The fact that I only heard one second of audio
is probably due to the fact that I created a
video that totally confused my player. Zero
frames per second is not a very comprehensible
frame rate.
The next thing I tried is this:
The above command worked!
Notice these 4 characters:
%03d
That's a C Language formatting string
from the printf function. Basically
it means expect 3 numbers.
With 3 numbers expected, I have to create
more than one image file. When I do create
multiple image files, I name them like this:
image001.gif
image002.gif
image003.gif
Since FFmpeg seems to default to 25 frames
per second output, I will need 300 frames
to match precisely 12 seconds of audio.
12 seconds X 25 frames/second = 300 frames.
Therefore, my first file will be called this:
image001.gif
My last file will be called this:
image300.gif
Each file represents one frame in my movie.
I finally found the key to making this thing
work. I need to assume 25 frames per second
video and I need to create as many frames as
necessary to fill up the audio track with frames.
Of course, there may be a better way. However,
this is what I'e found so far.
Ed Abbott
yesterday. I've been trying to
create a slide-show video accompanied
by sound.
I want to upload my video to YouTube
once I've finished creating it. First,
though, I had to create the video. FFmpeg
is my chosen tool.
Here is what I tried first:
ffmpeg -i sound.wav -i image.gif movie.mpg
The above command line did not work. However,
I learned a lot by having it fail. Mostly I
learned to avoid false assumptions.
My sound file was 12 seconds long. As you
can see, the above command line has only one
image and one sound file.
I figured that FFmpeg would interpret
the above command line the only way that I
would consider to be reasonable. I figured
it would throw my one image on the screen
and then run my video for the length of the
sound file.
In other words, I thought FFmpeg would stretch
the time my one and only image stayed on the screen
to match the length of my audio file. Single
images do not have a duration but a sound file
does. So why not stretch the viewing time of
the image to match the sound?
Of course, I was thinking like a human being
rather than a computer. In life, that's
the totally right thing to do.
It's the wrong thing to do If you're trying
to tell a computer what to do. When talking
to a human being, think human. When talking
to a computer, think computer.
The thing I overlooked is the fact that FFmpeg
is primarily designed to create movies, not
sound tracks. Therefore, the movie trumps the
sound.
The above FFmpeg command line truncated my
sound. I'm surprised I was able to hear any
sound at all. I heard about one second of
sound.
I suspect what happened is that my one image
in the above command line became the one frame
in my movie. Thinking like a computer,
this is a totally reasonable thing to do. Take
one image and turn it into a one frame movie.
When the one frame is done, the movie is done.
That's what I think happened.
The reason I'm surprised I heard the sound at
all is because I never saw my one frame. I only
heard my one second of sound.
Here are the statistics that FFmpeg output after
completing execution of the above command line:
frame = 1
fps = 0
time = 12.4
The above statistics give me some insight into
what really happened. Probably my player got
confused. I fed my video player a video that
is 12.4 seconds long but that runs at zero
frames per second. Does this make any sense?
Not to my video player, apparently.
The fact that I only heard one second of audio
is probably due to the fact that I created a
video that totally confused my player. Zero
frames per second is not a very comprehensible
frame rate.
The next thing I tried is this:
ffmpeg -i track01.wav -i ./image%03d.gif track01.mpg
The above command worked!
Notice these 4 characters:
%03d
That's a C Language formatting string
from the printf function. Basically
it means expect 3 numbers.
With 3 numbers expected, I have to create
more than one image file. When I do create
multiple image files, I name them like this:
image001.gif
image002.gif
image003.gif
Since FFmpeg seems to default to 25 frames
per second output, I will need 300 frames
to match precisely 12 seconds of audio.
12 seconds X 25 frames/second = 300 frames.
Therefore, my first file will be called this:
image001.gif
My last file will be called this:
image300.gif
Each file represents one frame in my movie.
I finally found the key to making this thing
work. I need to assume 25 frames per second
video and I need to create as many frames as
necessary to fill up the audio track with frames.
Of course, there may be a better way. However,
this is what I'e found so far.
Ed Abbott
Friday, July 15, 2011
Installing FFmpeg
This is a new blog. I'm blogging
to help myself understand how to
install and use FFmpeg.
I know next to nothing about FFmpeg.
My understanding is that it can
be used to convert one video format
to another.
I hope it can also be used to convert
an mp3 file into a slide show movie that
exhibits photos. This is what I
hope to use it for.
I hope that the overall time of the movie
is controlled by the mp3 and that the timing
of each of the slides can be controlled by
suggesting to FFmpeg how long each slide
should stay on screen. If these 2 timing
issues can be controlled, I can make myself
a slide-show movie.
My first task is to install FFmpeg. I'm going
to use the standard Debian installer for this
purpose. I'm a Debian Linux user.
To get started, I type the following command
under Debian Lenny:
The output to the above command is several
packages that are relevant to FFmpeg. Here's
the package that actually contains FFmpeg:
Just to make sure I've not already installed FFmpeg,
I type the following command:
The above command comes back with the following
2 lines of information that tells me that
FFmpeg is not yet installed:
Note that the above aptitude show ffmpeg
command gives a lot of information that I've
chosen not to show here.
Since I've not yet installed FFmpeg, I'll
go ahead and install it:
OK. Now I ask what version number I just
installed:
The answer that comes back has a the following
copyright notice:
Looks like I have installed software that is
approxmately 3 years old. Here's what appears
to be the revision number:
I've googled the above revision number and
it appears this revision dates from 2008.
Here's what googling r11872 ffmpeg
gives as a result:
Looks like Debian has installed a version of
FFmpeg that is 3 years old. I'll see if this
version does what I want it to.
If it does not, I may have to install ffmeg from
source code. I don't like to do that but I will
do it if I have to.
On further investigation, I find the following
date on the last line of the man page for FFmpeg.
The man page was automatically installed when I
installed FFmpeg.
2011-02-13
Perhaps the version of FFmpeg that I've installed
is more up-to-date than I think it is. It would
make no sense to install an up-to-date man page with
out-of-date software.
Ed Abbott
to help myself understand how to
install and use FFmpeg.
I know next to nothing about FFmpeg.
My understanding is that it can
be used to convert one video format
to another.
I hope it can also be used to convert
an mp3 file into a slide show movie that
exhibits photos. This is what I
hope to use it for.
I hope that the overall time of the movie
is controlled by the mp3 and that the timing
of each of the slides can be controlled by
suggesting to FFmpeg how long each slide
should stay on screen. If these 2 timing
issues can be controlled, I can make myself
a slide-show movie.
My first task is to install FFmpeg. I'm going
to use the standard Debian installer for this
purpose. I'm a Debian Linux user.
To get started, I type the following command
under Debian Lenny:
rootprompt# aptitude search ffmpeg
The output to the above command is several
packages that are relevant to FFmpeg. Here's
the package that actually contains FFmpeg:
p ffmpeg - multimedia player, server and encoder
Just to make sure I've not already installed FFmpeg,
I type the following command:
rootprompt# aptitude show FFmpeg
The above command comes back with the following
2 lines of information that tells me that
FFmpeg is not yet installed:
Package: ffmpeg State: not installed
Note that the above aptitude show ffmpeg
command gives a lot of information that I've
chosen not to show here.
Since I've not yet installed FFmpeg, I'll
go ahead and install it:
rootprompt# aptitude install ffmpeg
OK. Now I ask what version number I just
installed:
ffmpeg -version
The answer that comes back has a the following
copyright notice:
Copyright (c) 2000-2008 Fabrice Bellard, et al
Looks like I have installed software that is
approxmately 3 years old. Here's what appears
to be the revision number:
FFmpeg version r11872
I've googled the above revision number and
it appears this revision dates from 2008.
Here's what googling r11872 ffmpeg
gives as a result:
Author: reimar Date: Tue Feb 5 19:39:55 2008 New Revision: 11872
Looks like Debian has installed a version of
FFmpeg that is 3 years old. I'll see if this
version does what I want it to.
If it does not, I may have to install ffmeg from
source code. I don't like to do that but I will
do it if I have to.
On further investigation, I find the following
date on the last line of the man page for FFmpeg.
The man page was automatically installed when I
installed FFmpeg.
2011-02-13
Perhaps the version of FFmpeg that I've installed
is more up-to-date than I think it is. It would
make no sense to install an up-to-date man page with
out-of-date software.
Ed Abbott
Subscribe to:
Posts (Atom)