Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2122 closed defect (fixed)

Commit 75d900d makes skipping in the input while using swresample very slow

Reported by: eelco Owned by: Michael Niedermayer
Priority: important Component: swresample
Version: git-master Keywords: regression
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

In commit 75d900d52edb281eb4ab4989800e75abe7555937 the memory allocation method used for allocating memory for audio switched to using av_mallocz (from av_malloc). I’m curious to learn why this change was made, because it makes skipping in a file (using -ss before the input) several orders of magnitude slower.

Version 1.0:

% time ./ffmpeg -ss 2 -i ~/Downloads/example.mkv -t 1 -vcodec copy -f matroska -map 0:0 -acodec ac3 -async 1 -map 0:1 -y /dev/null
ffmpeg version 1.0 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec 28 2012 14:35:11 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
...
frame=   74 fps=7.2 q=-1.0 Lsize=       0kB time=00:00:01.01 bitrate=   0.0kbits/s    
video:28kB audio:56kB subtitle:0 global headers:0kB muxing overhead -100.000000%
       10.32 real         3.52 user         6.74 sys

Version 1.0 with commit 75d900d reverted:

% time ./ffmpeg -ss 2 -i ~/Downloads/example.mkv -t 1 -vcodec copy -f matroska -map 0:0 -acodec ac3 -async 1 -map 0:1 -y /dev/null
ffmpeg version 1.0 Copyright (c) 2000-2012 the FFmpeg developers
  built on Dec 28 2012 14:35:11 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
...
frame=   74 fps=0.0 q=-1.0 Lsize=       0kB time=00:00:01.01 bitrate=   0.0kbits/s    
video:28kB audio:56kB subtitle:0 global headers:0kB muxing overhead -100.000000%
        0.46 real         0.05 user         0.35 sys

(Note that it wasn’t a clean build, so the ‘built on’ banner didn’t change.)

I also tried testing with an -ss value of 100, but killed it after a about 5 minutes. With the commit reverted it takes about a second.

We found the cause of the problem by profiling ffmpeg and saw that all time was being spent in av_mallocz. I haven’t looked into it any further, but I suspect that the av_mallocz call exposes a bug that previously didn’t cause any problem.

I also checked the 1.1 release, the problem is still there.

Change History (7)

comment:1 by Carl Eugen Hoyos, 11 years ago

Keywords: regression added

Is the problem also reproducible with current git head?
Please provide your command line together with complete, uncut console output.

comment:2 by eelco, 11 years ago

Yes.

time ./ffmpeg -ss 2 -i ~/Downloads/example.mkv  -t 1 -vcodec copy -f matroska -map 0:0 -acodec ac3 -async 1 -map 0:1 -y /dev/null 
ffmpeg version N-48635-g8615970 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan  8 2013 15:38:39 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
  configuration: --prefix=/Users/eelco/Projects/Beamer/FFmpeg/build --enable-gpl --enable-version3 --enable-libx264 --disable-shared --enable-static --enable-libtheora --enable-libvorbis --enable-libvo-aacenc --disable-doc --extra-cflags='-DMACOSX_DEPLOYMENT_TARGET=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -I/Users/eelco/Projects/Beamer/FFmpeg/build/include' --extra-ldflags='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -L/Users/eelco/Projects/Beamer/FFmpeg/build/lib'
  libavutil      52. 13.100 / 52. 13.100
  libavcodec     54. 86.100 / 54. 86.100
  libavformat    54. 59.106 / 54. 59.106
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 32.100 /  3. 32.100
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from '/Users/eelco/Downloads/example.mkv':
  Metadata:
    title           : Project X Extended Cut (2012) – Release for HDCLUB by Pro_Rock_
    creation_time   : 2012-08-05 02:07:48
  Duration: 01:32:59.79, start: 0.000000, bitrate: 11159 kb/s
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1280x720, SAR 1:1 DAR 16:9, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Stream #0:1(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 384 kb/s
    Metadata:
      title           : Дубляж
    Stream #0:2(rus): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s (default)
    Metadata:
      title           : VO MaksCiganov
    Stream #0:3(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), fltp, 1536 kb/s
    Metadata:
      title           : Оригинал
    Stream #0:4(rus): Subtitle: subrip (default)
    Metadata:
      title           : Force
    Stream #0:5(rus): Subtitle: subrip
    Metadata:
      title           : Full
    Stream #0:6(eng): Subtitle: subrip
    Metadata:
      title           : Оригинал
-async is forwarded to lavfi similarly to -af aresample=async=1:min_hard_comp=0.100000.
Output #0, matroska, to '/dev/null':
  Metadata:
    title           : Project X Extended Cut (2012) – Release for HDCLUB by Pro_Rock_
    encoder         : Lavf54.59.106
    Stream #0:0(eng): Video: h264, yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 23.98 fps, 1k tbn, 1k tbc (default)
    Stream #0:1(rus): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : Дубляж
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (ac3 -> ac3)
Press [q] to stop, [?] for help
frame=   74 fps=6.5 q=-1.0 Lsize=      86kB time=00:00:01.01 bitrate= 690.1kbits/s    
video:28kB audio:56kB subtitle:0 global headers:0kB muxing overhead 1.790181%
       11.46 real         3.66 user         7.47 sys

comment:3 by Carl Eugen Hoyos, 11 years ago

Priority: normalimportant
Version: 1.1git-master

comment:4 by Clément Bœsch, 11 years ago

I'm not able to reproduce with a local mkv. Would you mind uploading a sample or point one on http://samples.ffmpeg.org/ ?

comment:5 by eelco, 11 years ago

I found out it only seems reproducible with a 5.1 audio track. The test below is with the 720p version of Sintel, downloaded from http://www.sintel.org/download

time ./ffmpeg -ss 2 -i ~/Downloads/Sintel.2010.720p.mkv  -t 1 -vcodec copy -f matroska -map 0:0 -acodec ac3 -async 1 -map 0:1 -y /dev/null 
ffmpeg version N-48635-g8615970 Copyright (c) 2000-2013 the FFmpeg developers
  built on Jan  8 2013 15:38:39 with llvm-gcc 4.2.1 (LLVM build 2336.11.00)
  configuration: --prefix=/Users/eelco/Projects/Beamer/FFmpeg/build --enable-gpl --enable-version3 --enable-libx264 --disable-shared --enable-static --enable-libtheora --enable-libvorbis --enable-libvo-aacenc --disable-doc --extra-cflags='-DMACOSX_DEPLOYMENT_TARGET=10.6 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -I/Users/eelco/Projects/Beamer/FFmpeg/build/include' --extra-ldflags='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.6 -L/Users/eelco/Projects/Beamer/FFmpeg/build/lib'
  libavutil      52. 13.100 / 52. 13.100
  libavcodec     54. 86.100 / 54. 86.100
  libavformat    54. 59.106 / 54. 59.106
  libavdevice    54.  3.102 / 54.  3.102
  libavfilter     3. 32.100 /  3. 32.100
  libswscale      2.  1.103 /  2.  1.103
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
Input #0, matroska,webm, from '/Users/eelco/Downloads/Sintel.2010.720p.mkv':
  Metadata:
    creation_time   : 2011-04-24 17:20:33
  Duration: 00:14:48.03, start: 0.000000, bitrate: 6071 kb/s
    Chapter #0.0: start 0.000000, end 103.125000
    Metadata:
      title           : Chapter 01
    Chapter #0.1: start 103.125000, end 148.667000
    Metadata:
      title           : Chapter 02
    Chapter #0.2: start 148.667000, end 349.792000
    Metadata:
      title           : Chapter 03
    Chapter #0.3: start 349.792000, end 437.208000
    Metadata:
      title           : Chapter 04
    Chapter #0.4: start 437.208000, end 472.075000
    Metadata:
      title           : Chapter 05
    Chapter #0.5: start 472.075000, end 678.833000
    Metadata:
      title           : Chapter 06
    Chapter #0.6: start 678.833000, end 744.083000
    Metadata:
      title           : Chapter 07
    Chapter #0.7: start 744.083000, end 888.032000
    Metadata:
      title           : Chapter 08
    Stream #0:0(eng): Video: h264 (High), yuv420p, 1280x544, SAR 1:1 DAR 40:17, 24 fps, 24 tbr, 1k tbn, 48 tbc
    Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 640 kb/s
    Metadata:
      title           : AC3 5.1 @ 640 Kbps
    Stream #0:2(ger): Subtitle: subrip
    Stream #0:3(eng): Subtitle: subrip
    Stream #0:4(spa): Subtitle: subrip
    Stream #0:5(fre): Subtitle: subrip
    Stream #0:6(ita): Subtitle: subrip
    Stream #0:7(dut): Subtitle: subrip
    Stream #0:8(pol): Subtitle: subrip
    Stream #0:9(por): Subtitle: subrip
    Stream #0:10(rus): Subtitle: subrip
    Stream #0:11(vie): Subtitle: subrip
-async is forwarded to lavfi similarly to -af aresample=async=1:min_hard_comp=0.100000.
Output #0, matroska, to '/dev/null':
  Metadata:
    encoder         : Lavf54.59.106
    Chapter #0.0: start 0.000000, end 1.000000
    Metadata:
      title           : Chapter 01
    Stream #0:0(eng): Video: h264, yuv420p, 1280x544 [SAR 1:1 DAR 40:17], q=2-31, 24 fps, 1k tbn, 1k tbc
    Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s
    Metadata:
      title           : AC3 5.1 @ 640 Kbps
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (ac3 -> ac3)
Press [q] to stop, [?] for help
frame=   74 fps=7.1 q=-1.0 Lsize=     305kB time=00:00:01.01 bitrate=2454.6kbits/s    
video:248kB audio:56kB subtitle:0 global headers:0kB muxing overhead 0.512768%
       10.44 real         3.72 user         6.71 sys

comment:6 by Michael Niedermayer, 11 years ago

Reproduced by developer: set
Resolution: fixed
Status: newclosed

comment:7 by eelco, 11 years ago

Great! Thank you for fixing it.

For documentation, this is the commit that fixes it: http://git.videolan.org/?p=ffmpeg.git;a=commit;h=dc6588421e09d755655e5def870b2ebed515bc9d

Note: See TracTickets for help on using tickets.