[FFmpeg-user] The Magic Microsecond

Jan Ehrhardt phpdev at ehrhardt.nl
Sat Jul 7 22:54:47 CEST 2012


We are still using one of Sherpya's FFmpeg builds to transcode
recordings on a SD card. Due to security precautions (and restrictions
by sysadmins to -not- access files on the PC of the transcoder) we are
doing the transcoding entirely on SD cards.

Compare the four following command lines:

ffmpeg-r32754              -i /SD_VIDEO/MOV001.MOD -vf scale=384:288 \
	-aspect 4:3 -sws_flags bicubic -vcodec flv -b:v 320k \
	-strict -2 -acodec aac -ab 96k -ar 44100 output.flv

ffmpeg-r32754 -ss 0.000001 -i /SD_VIDEO/MOV001.MOD -vf scale=384:288 \
	-aspect 4:3 -sws_flags bicubic -vcodec flv -b:v 320k \
	-strict -2 -acodec aac -ab 96k -ar 44100 output.flv

ffmpeg-20120706              -i /SD_VIDEO/MOV001.MOD -vf scale=384:288 \
	-aspect 4:3 -sws_flags bicubic -vcodec flv -b:v 320k \
	-strict -2 -acodec aac -ab 96k -ar 44100 -threads 0 \
	output.flv

ffmpeg-20120706 -ss 0.000001 -i /SD_VIDEO/MOV001.MOD -vf scale=384:288 \
	-aspect 4:3 -sws_flags bicubic -vcodec flv -b:v 320k \
	-strict -2 -acodec aac -ab 96k -ar 44100 -threads 0 \
	output.flv 

You would expect them all to do the transcoding in more ore less the
same amount of time. Well, when the output file is on a SD card, it
ain't so.

The first command line ends with:
frame= 6012 fps= 22 q=24.7 Lsize= 12814kB time=00:04:00.48 \
	bitrate= 436.5kbits/s

The 22 fps was completely unacceptable and we moved to MEncoder, which
did not have the problem. By pure chance, I discovered a few weeks ago
how to speed up ffmpeg-r32754 dramatically: skip the first microsecond!
-ss 0.000001.

Result:
frame= 6010 fps=330 q=23.8 Lsize=   12809kB time=00:04:00.48 \
	bitrate= 436.3kbits/s

Fps: 330. Now we are talking! 15 times as fast.

ffmpeg-20120706 (Zeranoe build) does not behave as badly:
frame= 6012 fps=310 q=24.4 Lsize=   12813kB time=00:04:00.48 \
	bitrate= 436.5kbits/s

Newer FFmpeg with MT support, slower transcoding. The magic
microsecond does not really speed things up in the latest FFmpeg:
frame= 6000 fps=312 q=24.4 Lsize=   12814kB time=00:04:00.48 \
	bitrate= 436.5kbits/s

Questions:
1. Does anyone have the faintest idea, why skipping the first
   microsecond make FFmpeg-r32754 15 times as fast?
2. Was it fixed in later builds deliberately or by chance?
3. Any explanation why the newest FFmpeg is slower than the
   r32754?

A few closing remarks:
-  No, -ss 0 or -s 0.000000 won't work
-  We have similar problems with MP4box on a SD card. Sloooooow

Jan


T:\utils>ffmpeg-r32754 -ss 0.000001 -i /SD_VIDEO/MOV001.MOD -vf scale=384:288
-aspect 4:3 -sws_flags bicubic -vcodec flv -b:v 320k -strict -2 -acodec aac
-ab 64k -y output.flv
ffmpeg version N-32754-g936d4d4-Sherpya, Copyright (c) 2000-2011 the FFmpeg developers
  built on Sep 21 2011 13:48:46 with gcc 4.2.5 20090330 (prerelease) [Sherpya]
  libavutil    51. 16. 1 / 51. 16. 1
  libavcodec   53. 16. 0 / 53. 16. 0
  libavformat  53. 12. 0 / 53. 12. 0
  libavdevice  53.  4. 0 / 53.  4. 0
  libavfilter   2. 43. 2 /  2. 43. 2
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  51.  2. 0 / 51.  2. 0
[mpeg @ 0171d980] max_analyze_duration 5000000 reached at 5000000
Input #0, mpeg, from '/SD_VIDEO/MOV001.MOD':
  Duration: 00:04:00.44, start: 0.919744, bitrate: 1732 kb/s
    Stream #0.0[0x1e0]: Video: mpeg2video (Main), yuv420p, 352x288 [SAR 12:11 DAR 4:3], 3000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0.1[0x80]: Audio: ac3, 48000 Hz, stereo, s16, 128 kb/s
[buffer @ 03c82f80] w:352 h:288 pixfmt:yuv420p tb:1/1000000 sar:12/11 sws_param:
[scale @ 003ad1e0] w:352 h:288 fmt:yuv420p -> w:384 h:288 fmt:yuv420p flags:0x4
Output #0, flv, to 'output.flv':
  Metadata:
    encoder         : Lavf53.12.0
    Stream #0.0: Video: flv1 ([2][0][0][0] / 0x0002), yuv420p, 384x288 [SAR 1:1 DAR 4:3], q=2-31, 320 kb/s, 1k tbn, 25 tbc
    Stream #0.1: Audio: aac ([10][0][0][0] / 0x000A), 48000 Hz, stereo, s16, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0 (mpeg2video -> flv)
  Stream #0.1 -> #0.1 (ac3 -> aac)
Press [q] to stop, [?] for help
[mpeg2video @ 01730280] warning: first frame is no keyframe
frame=  159 fps=  0 q=11.1 size=     472kB time=00:00:06.31 bitrate= 611.7kbits/
frame=  332 fps=294 q=7.5 size=     927kB time=00:00:13.22 bitrate= 574.3kbits/s
frame=  458 fps=305 q=10.8 size=    1198kB time=00:00:18.21 bitrate= 538.6kbits/
frame=  466 fps=305 q=10.4 Lsize=    1223kB time=00:00:18.62 bitrate= 538.1kbits



T:\utils>ffmpeg-20120706 -i /SD_VIDEO/MOV001.MOD -vf scale=384:288 -aspect 4:3
-sws_flags bicubic -vcodec flv -b:v 320k -strict -2 -acodec aac -ab 64k
-y output.flv
ffmpeg version N-42288-g8293a21 Copyright (c) 2000-2012 the FFmpeg developers
  built on Jul  5 2012 20:56:23 with gcc 4.7.1
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-ru
ntime-cpudetect --enable-avisynth --enable-bzlib --enable-frei0r --enable-libass
 --enable-libcelt --enable-libopencore-amrnb --enable-libopencore-amrwb --enable
-libfreetype --enable-libgsm --enable-libmp3lame --enable-libnut --enable-libope
njpeg --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libth
eora --enable-libutvideo --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-
libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --e
nable-zlib
  libavutil      51. 64.100 / 51. 64.100
  libavcodec     54. 33.100 / 54. 33.100
  libavformat    54. 15.100 / 54. 15.100
  libavdevice    54.  1.100 / 54.  1.100
  libavfilter     3.  0.101 /  3.  0.101
  libswscale      2.  1.100 /  2.  1.100
  libswresample   0. 15.100 /  0. 15.100
  libpostproc    52.  0.100 / 52.  0.100
[mpeg @ 01dfc860] max_analyze_duration 5000000 reached at 5000000
Input #0, mpeg, from '/SD_VIDEO/MOV001.MOD':
  Duration: 00:04:00.44, start: 0.919744, bitrate: 1732 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 352x288 [SAR 12:11 DAR 4:3], 3000 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, s16, 128 kb/s
[graph 0 input from stream 0:0 @ 01cd7ee0] w:352 h:288 pixfmt:yuv420p tb:1/90000
 fr:25/1 sar:12/11 sws_param:flags=2
[output stream 0:0 @ 01ce93e0] No opaque field provided
[Parsed_scale_0 @ 01cd7e00] w:352 h:288 fmt:yuv420p sar:12/11 -> w:384 h:288 fmt:yuv420p sar:1/1 flags:0x4
[graph 1 input from stream 0:1 @ 01cf3480] tb:1/48000 samplefmt:s16 samplerate:4
8000 chlayout:0x3
[auto-inserted resampler 0 @ 01cf3600] chl:stereo fmt:s16 r:48000Hz -> chl:stereo fmt:flt r:48000Hz
Output #0, flv, to 'output.flv':
  Metadata:
    encoder         : Lavf54.15.100
    Stream #0:0: Video: flv1 ([2][0][0][0] / 0x0002), yuv420p, 384x288 [SAR 1:1 DAR 4:3], q=2-31, 320 kb/s, 1k tbn, 25 tbc
    Stream #0:1: Audio: aac ([10][0][0][0] / 0x000A), 48000 Hz, stereo, flt, 64 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video -> flv)
  Stream #0:1 -> #0:1 (ac3 -> aac)
Press [q] to stop, [?] for help
[mpeg2video @ 01cd5b80] warning: first frame is no keyframe
frame=  142 fps=0.0 q=9.6 size=     454kB time=00:00:05.48 bitrate= 679.1kbits/s
frame=  299 fps=299 q=6.7 size=     867kB time=00:00:11.81 bitrate= 601.0kbits/s
frame=  359 fps=239 q=8.3 size=    1026kB time=00:00:14.23 bitrate= 590.9kbits/s
frame=  515 fps=257 q=12.2 size=    1346kB time=00:00:20.39 bitrate= 540.8kbits/



More information about the ffmpeg-user mailing list