[FFmpeg-devel] first experience with ffmpeg
D. Hugh Redelmeier
hugh
Fri Feb 15 08:09:19 CET 2008
As a developer, I value learning about users first exposure to a
program. Newbies trip over things that the experienced no longer
notice. That is why I am trying to describe my initial experiences
with ffmpeg even if they will turn out to be embarrassing.
This is going to be presented as a narrative. Large parts may be
uninteresting. I will highlight points that I hope are worth noting
with "===>".
My platform is Fedora 7 Linux on x86-64.
Why did I try ffmpeg? Because I wanted to capture CBC Radio streams
and listen to them on my portable MP3 players.
CBC Radio streams are mms: containing WMA stuff. Here is an example:
mms://wm.cbc.ca/cbcr1-winnipeg
I found that I could capture this with a program called mmsrip. Here,
for example, is a command to capture 10 minutes of the stream for
Toronto:
mmsrip --delay=600 --output=foo.wma mms://wm.cbc.ca/cbcr1-toronto
I then found that these wma files could be played via mplayer, but
they did strange/bad things to my MP3 players. For example, the
Creative Zen V would lock up (requiring a reset (using a
paper-clip)). My Samsung player wasn't happy either. This defeated
my goal.
Why were these .wma files not good? I still don't know. Could I fix
them?
mplayer said that it was using ffmpeg to decode these files, and that
worked:
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
AUDIO: 44100 Hz, 1 ch, s16le, 32.0 kbit/4.54% (ratio: 4003->88200)
Selected audio codec: [ffwmav2] afm: ffmpeg (DivX audio v2 (FFmpeg))
So I decided to play with ffmpeg. My goal was to transcode, sort of,
without transcoding. I wanted to create a new .wma without incurring
new conversion losses.
========================================================
My first (recorded) use of ffmpeg:
$ ffmpeg -v -i 2008.02.11-19.28.wma 2008.02.11-19.28.mp3
FFmpeg version SVN-r8876, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --prefix=/usr --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man!
libavutil version: 49.4.0
libavcodec version: 51.40.4
libavformat version: 51.12.1
built on May 3 2007 12:41:19, gcc: 4.1.2 20070424 (Red Hat 4.1.2-11)
File '2008.02.11-19.28.wma' already exists. Overwrite ? [y/N] n
Not overwriting - exiting
The problem is that -v takes an argument, so it "ate" the -i, leaving
what I thought of as in input file to be treated as an output file.
Thank goodness for the overwrite warning!
===> the ffmpeg program should diagnose malformed arguments to -v.
I more carefully read the manual and tried "-v verbose" which made
ffmpeg quiet -- pretty counterintuitive!
===> the ffmpeg manpage's description of the -v flag should explain
that "verbose" is not a literal string but (I imagine) an integer.
It should explain what possible values are.
Eventually, I converted the file to .mp3.
I had captured an hour of radio. I wanted to extract a few minutes
from it. I played the mp3 with xmms and wrote down the start time and
duration of the part I wished to capture.
I then used this the do the extraction
$ ffmpeg -ss 00:23:44 -t 00:09:15 -i 2008.02.11-19.28.wma don.mp3
This did not work. It seemed as if ffmpeg ignored the -ss and just
started extracting from the beginning. I don't know why. Perhaps you
can tell me from the verbose output.
$ ffmpeg -v 9 -ss 00:23:44 -t 00:09:15 -i 2008.02.11-19.28.wma don.mp3
FFmpeg version SVN-r8876, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --prefix=/usr --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --extra-cflags=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic --enable-libmp3lame --enable-libogg --enable-libtheora --enable-libvorbis --enable-libfaad --enable-libfaac --enable-libgsm --enable-xvid --enable-x264 --enable-liba52 --enable-liba52bin --enable-libdts --enable-pp --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-opts --disable-strip
libavutil version: 49.4.0
libavcodec version: 51.40.4
libavformat version: 51.12.1
built on May 3 2007 12:41:19, gcc: 4.1.2 20070424 (Red Hat 4.1.2-11)
[asf @ 0x2aaaaad51720]read_seek: 0 1424000
[asf @ 0x2aaaaad51720]gen_seek: 0 1424000
[asf @ 0x2aaaaad51720]asf_read_pts failed
[asf @ 0x2aaaaad51720]asf_read_pts failed
[asf @ 0x2aaaaad51720]pos_min=0x9f5 pos_max=0xe08e6b dts_min=1156820972 dts_max=1160422154
[asf @ 0x2aaaaad51720]2549 4067 14716523 / 1156820972 1156821361 1160422154 target:1424000 limit:14716523 start:2550 noc:0
[asf @ 0x2aaaaad51720]pos=0x9f5 1156820972<=1424000<=1156821361
Input #0, asf, from '2008.02.11-19.28.wma':
Duration: 01:01:16.7, start: 0.000000, bitrate: 32 kb/s
Stream #0.0, 1/1000: Audio: wmav2, 44100 Hz, mono, 32 kb/s
File 'don.mp3' already exists. Overwrite ? [y/N] y
Output #0, mp3, to 'don.mp3':
Stream #0.0, 1/90000: Audio: mp3, 44100 Hz, mono, 64 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
size= 82kB time=10.5 bitrate= 64.0kbits/s dup=0 drop=0 size= 161kB time=20.6 bitrate= 64.0kbits/s dup=0 drop=0 size= 241kB time=30.9 bitrate= 64.0kbits/s dup=0 drop=0 size= 353kB time=45.2 bitrate= 64.0kbits/s dup=0 drop=0 size= 510kB time=65.3 bitrate= 64.0kbits/s dup=0 drop=0 size= 671kB time=85.9 bitrate= 64.0kbits/s dup=0 drop=0 size= 849kB time=108.6 bitrate= 64.0kbits/s dup=0 drop=0 size= 1012kB time=129.5 bitrate= 64.0kbits/s dup=0 drop=0 size= 1178kB time=150.7 bitrate= 64.0kbits/s dup=0 drop=0 size= 1338kB time=171.3 bitrate= 64.0kbits/s dup=0 drop=0 size= 1499kB time=191.9 bitrate= 64.0kbits/s dup=0 drop=0 size= 1658kB time=212.2 bitrate= 64.0kbits/s dup=0 drop=0 size= 1809kB time=231.6 bitrate= 64.0kbits/s dup=0 drop=0 size= 1969kB time=252.1 bitrate= 64.0kbits/s dup=0 drop=0 size= 2128kB time=272.4 bitrate= 64.0kbits/s dup=0 drop=0 size= 2287kB !
time=292.7 bitrate= 64.0kbits/s dup=0 drop=0 size= 2432kB time=311.3 bitrate= 64.0kbits/s dup=0 drop=0 size= 2577kB time=329.8 bitrate= 64.0kbits/s dup=0 drop=0 size= 2729kB time=349.3 bitrate= 64.0kbits/s dup=0 drop=0 size= 2873kB time=367.8 bitrate= 64.0kbits/s dup=0 drop=0 size= 3018kB time=386.3 bitrate= 64.0kbits/s dup=0 drop=0 size= 3163kB time=404.9 bitrate= 64.0kbits/s dup=0 drop=0 size= 3314kB time=424.2 bitrate= 64.0kbits/s dup=0 drop=0 size= 3462kB time=443.1 bitrate= 64.0kbits/s dup=0 drop=0 size= 3608kB time=461.8 bitrate= 64.0kbits/s dup=0 drop=0 size= 3753kB time=480.3 bitrate= 64.0kbits/s dup=0 drop=0 size= 3908kB time=500.2 bitrate= 64.0kbits/s dup=0 drop=0 size= 4054kB time=518.9 bitrate= 64.0kbits/s dup=0 drop=0 size= 4197kB time=537.2 bitrate= 64.0kbits/s dup=0 drop=0 size= 4338kB time=555.3 bitrate= 64.0kbits/s dup=0 drop=0 size= 4340kB time=555.5 bit!
rate= 64.0kbits/s dup=0 drop=0
video:0kB audio:4340kB global headers:0kB muxing overhead 0.000000%
[Later I find a workaround.]
I decided to try converting from .wma to .wma. I could not seem to
guess the correct name of the codec. So I typed "ffmpeg -formats".
===> the output of "ffmpeg -formats" should explaining what the letters
in front of the codec name mean "DE[VA]SD".
Of course, it turns out that what I really wanted was "-acodec copy".
I did not find that easy to discover.
Now I just tried what should have been a null transformation:
$ ffmpeg -v 9 -i 2008.02.11-19.28.wma -acodec copy 2008.02.11-19.28y.wma
FFmpeg version SVN-r8876, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --prefix=/usr --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --shlibdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --extra-cflags=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic --enable-libmp3lame --enable-libogg --enable-libtheora --enable-libvorbis --enable-libfaad --enable-libfaac --enable-libgsm --enable-xvid --enable-x264 --enable-liba52 --enable-liba52bin --enable-libdts --enable-pp --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-opts --disable-strip
libavutil version: 49.4.0
libavcodec version: 51.40.4
libavformat version: 51.12.1
built on May 3 2007 12:41:19, gcc: 4.1.2 20070424 (Red Hat 4.1.2-11)
Input #0, asf, from '2008.02.11-19.28.wma':
Duration: 01:01:16.7, start: 0.000000, bitrate: 32 kb/s
Stream #0.0, 1/1000: Audio: wmav2, 44100 Hz, mono, 32 kb/s
Output #0, asf, to '2008.02.11-19.28y.wma':
Stream #0.0, 1/90000: Audio: wmav2, 44100 Hz, mono, 32 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
timestamp discontinuity 1156820972000, new offset= -1156820972000
size= 15147kB time=3601.6 bitrate= 34.5kbits/s dup=0 drop=0
video:0kB audio:14077kB global headers:0kB muxing overhead 7.602273%
Interestingly, it was not a null transformation:
-rw-rw-r-- 1 hugh hugh 14718041 2008-02-11 20:28 2008.02.11-19.28.wma
-rw-rw-r-- 1 hugh hugh 15510844 2008-02-12 00:46 2008.02.11-19.28y.wma
The file grew.
Now here is the surprise (to me): the -ss flag started working.
===> Why??
Then I tried to extract the segment I wanted. Unfortunately, the time
co-ordinates reported by xmms did NOT match -ss and -t.
===> why?
When I was done, the extracted file DID play in my Zen V. Good job, ffmpeg team!
But: the Zen's fast forward didn't work. Furthermore, it reported to
length (in time) of the file to be 0!
===> Why?
I discovered exiftool and applied it to the various files.
I've marked with * some of the things that look fishy to me.
[root at redex ideas]# exiftool ../cbc/2008.02.11-19.28.wma
ExifTool Version Number : 7.00
File Name : 2008.02.11-19.28.wma
Directory : ../cbc
File Modification Date/Time : 2008:02:11 20:28:12
File Type : WMA
MIME Type : audio/x-ms-wma
Title : CBC Radio One Winnipeg
Author : www.cbc.ca
Copyright : (C) Canadian Broadcasting Corporation
File ID : 37850006-3F6A-4844-B69A-1358437CD6B1
File Size : 2549
Creation Date : 2008:01:29 15:07:02Z
* Data Packets : 4294967295
* Play Duration : 0 sec
* Send Duration : 0 sec
Preroll : 1578
* Flags : 9
Min Packet Size : 1518
Max Packet Size : 1518
Max Bitrate : 32645
Stream Type : Audio
Error Correction Type : Audio Spread
Time Offset : 0 sec
Stream Number : 1
* Audio Codec ID : Windows Media v2
Audio Channels : 1
Audio Sample Rate : 44100
Is VBR : False
* Audio Codec Name : Windows Media Audio 9
Audio Codec Description : 32 kbps, 44 kHz, mono 1-pass CBR
Warning : Large ASF objects not supported
[root at redex ideas]# exiftool ../cbc/2008.02.11-19.28y.wma
ExifTool Version Number : 7.00
File Name : 2008.02.11-19.28y.wma
Directory : ../cbc
File Modification Date/Time : 2008:02:12 00:46:01
File Type : WMA
MIME Type : audio/x-ms-wma
* File ID : 00000000-0000-0000-0000-000000000000
File Size : 15510844
Creation Date : 0000:00:00 00:00:00Z
Data Packets : 4847
Play Duration : 3604.282 sec
Send Duration : 3601.182 sec
Preroll : 3100
* Flags : 2
Min Packet Size : 3200
Max Packet Size : 3200
Max Bitrate : 32024
Stream Type : Audio
Error Correction Type : Audio Spread
Time Offset : 0 sec
Stream Number : 1
Audio Codec ID : Windows Media v2
Audio Channels : 1
Audio Sample Rate : 44100
* Audio Codec Name : Windows Media Audio V8
* Audio Codec Description :
===> Why did the Audio Codec Name change?
===> Why did Flags change (I don't know what they mean anyway)?
[root at redex ideas]# exiftool ../cbc/don-wma.wma
ExifTool Version Number : 7.00
File Name : don-wma.wma
Directory : ../cbc
File Modification Date/Time : 2008:02:12 00:57:29
File Type : WMA
MIME Type : audio/x-ms-wma
* File ID : 00000000-0000-0000-0000-000000000000
File Size : 2189244
Creation Date : 0000:00:00 00:00:00Z
Data Packets : 684
* Play Duration : 4294970.029 sec
* Send Duration : 4294966.929 sec
Preroll : 3100
Flags : 2
Min Packet Size : 3200
Max Packet Size : 3200
Max Bitrate : 32024
Stream Type : Audio
Error Correction Type : Audio Spread
Time Offset : 0 sec
Stream Number : 1
Audio Codec ID : Windows Media v2
Audio Channels : 1
Audio Sample Rate : 44100
* Audio Codec Name : Windows Media Audio V8
* Audio Codec Description :
===> why is Play Duration something close to 2^32 ms
===> why is Send Duration something close to 2^32 ms
I wonder if those are why the Zen V gets the length wrong.
More information about the ffmpeg-devel
mailing list