Opened 13 years ago

Closed 13 years ago

#429 closed defect (fixed)

ffmpeg is killed by kernel (out of Memmry)

Reported by: mus Owned by: Michael Niedermayer
Priority: normal Component: undetermined
Version: unspecified Keywords: memory x264 killed kernel
Cc: Blocked By:
Blocking: Reproduced by developer: yes
Analyzed by developer: no

Description

I originally created a bug report for this for libav. Since ffmpeg (compiled from git) has exactly the same issue and no one has reacted to the libav bug report yet, I thought I should add it here.

ffmpeg is killed by the kernel when encoding some HD videos with x264 because it uses too much memory. See the original bug report here, this should include all needed information, including the used ffmpeg command line: http://bugzilla.libav.org/show_bug.cgi?id=31

Attachments (2)

v9loglevel99 (5.0 KB ) - added by mus 13 years ago.
output of "ffmpeg -v 9 -loglevel 99 -i input.mkv"
ffmpeg-subtitle-interleave.diff (2.3 KB ) - added by wg 13 years ago.
Treat subtitle streams as noninterleaved when 20 seconds have passed without a packet

Download all attachments as: .zip

Change History (15)

comment:1 by Carl Eugen Hoyos, 13 years ago

Component: FFmpegundetermined
Priority: importantnormal
Status: newopen
Version: gitunspecified

FFmpeg command line and complete, uncut output missing (it is needed on this page).

Is the problem only reproducible with -vcodec libx264, or can you reproduce the problem with another codec?
Does every sample show the oom, or is a specific sample needed?

comment:2 by mus, 13 years ago

I just did some more testing. After I did a fresh compile from Git, I saw that there are some ongoing changes regarding the -new* and -map options (thank god, I actually switched to libav because the syntax for avconv is much better). I couldn't quite figure out how the -map option works now, so I used an older build from the official Arch Linux repos (compiled on 2011-07-24) for testing.

Anyway, it seems like this is caused by - and here comes the surprise - the subtitles.

All the files that have this problem have 3 subtitles. If I do the following, I can actually watch the memory getting eaten up in "top" within minutes and ffmpeg getting killed:

ffmpeg -i input.mkv -scodec copy -vcodec copy -an output.mkv -scodec copy -newsubtitle -scodec copy -newsubtitle

If I use the following instead (not copying the third subtitle), memory consumption stays at about 4% and everything works fine:

ffmpeg -i input.mkv -scodec copy -vcodec copy -an output.mkv -scodec copy -newsubtitle

When I ripped these movies with MakeMKV I always told MakeMKV to rip 4 subtitles:

English
English (forced)
German
German (forced)

The subs causing this problem is the German forced. MakeMKV probably didn't rip the English forced subs because they were empty.

I'm gonna upload the ffmpeg output and some more info tomorrow.

by mus, 13 years ago

Attachment: v9loglevel99 added

output of "ffmpeg -v 9 -loglevel 99 -i input.mkv"

comment:3 by mus, 13 years ago

Some more testing:

Copying video and only the first two subs - works:

ffmpeg -i input.mkv -an -vcodec copy -scodec copy output.mkv -scodec copy -newsubtitle

---

Copying video and all subs - eats all memory within minutes and is killed by kernel:

ffmpeg -i input.mkv -an -vcodec copy -scodec copy output.mkv -scodec copy -newsubtitle -scodec copy -newsubtitle

---

Copying only the first two subs without video or audio - works:

ffmpeg -i input.mkv -an -vn -scodec copy output.mkv -scodec copy -newsubtitle

---

Copying all subs only - hangs after the following output, memory consumption stuck at 0.6%, I can still quit by pressing q. I only let it running a few minutes, I'm gonna try if it continues after a longer time:
size= 3kB time=00:00:00.00 bitrate= 0.0kbits/s

ffmpeg -i input.mkv -an -vn -scodec copy output.mkv -scodec copy -newsubtitle -scodec copy -newsubtitle

comment:4 by Carl Eugen Hoyos, 13 years ago

Please test git head (ffmpeg -i input.mkv -an -map 0:0 -vcodec copy -map 0:3 -scodec copy -map 0:4 -scodec copy -map 0:5 -scodec copy out.mkv) or at least 0.8.2 as listed on http://ffmpeg.org/download.html
Please provide the as-short-as-possible command line with -an (you did that) that allows to reproduce the problem and complete, uncut output of that call including backtrace etc. as described on http://ffmpeg.org/bugreports.html
Please consider using the "Code block" function of the editor instead of attaching the output.

comment:5 by mus, 13 years ago

I'm a little confused about the gdb part, I don't have a ffmpeg_g binary. Where can I get it? I built from Git with the Arch Linux build system, which uses the following configure options:

--prefix=/usr \
--enable-gpl \
--enable-libfaac \
--enable-libmp3lame \
--enable-libtheora \
--enable-libvorbis \
--enable-libx264 \
--enable-nonfree \
--enable-postproc \
--enable-x11grab

comment:6 by Carl Eugen Hoyos, 13 years ago

Consider building without any build system, just use git clone and ./configure && make (no need to install).

If you do not want to test the new user interface (-map instead of -newsubtitle), you can use git checkout oldabi to get the newest version compatible with 0.7.

comment:7 by mus, 13 years ago

ok, I got it, thanks.
The command line I'm using now is:

ffmpeg -i input.mkv -c copy -map 0 -map -0:a out.mkv

I'm not sure what I'm doing wrong, but the bt/disass/info commands I'm supposed to run after the crash don't seem to have any information. Sorry, but I'm not really familiar with this debugging stuff...

I'm using a different file here btw, I have accidentally overwritten the other video I was using. In this file, the subtitle causing the problem is the second one and not the third.

GNU gdb (GDB) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/mus/ffmpeg/ffmpeg_g...done.
(gdb) r -i input.mkv -c copy -map 0 -map -0:a out.mkv
Starting program: /home/mus/ffmpeg/ffmpeg_g -i input.mkv -c copy -map 0 -map -0:a out.mkv
[Thread debugging using libthread_db enabled]
ffmpeg version N-32325-g6f8b1fc, Copyright (c) 2000-2011 the FFmpeg developers
  built on Sep  5 2011 18:25:51 with gcc 4.6.1 20110819 (prerelease)
  configuration: 
  libavutil    51. 16. 0 / 51. 16. 0
  libavcodec   53. 13. 0 / 53. 13. 0
  libavformat  53. 11. 0 / 53. 11. 0
  libavdevice  53.  3. 0 / 53.  3. 0
  libavfilter   2. 37. 0 /  2. 37. 0
  libswscale    2.  1. 0 /  2.  1. 0
[matroska,webm @ 0x129f780] Estimating duration from bitrate, this may be inaccurate
Input #0, matroska,webm, from 'input.mkv':
  Duration: 01:50:20.40, start: 0.000000, bitrate: 2176 kb/s
    Chapter #0.0: start 0.000000, end 762.887111
    Metadata:
      title           : Chapter 00
    Chapter #0.1: start 762.887111, end 1439.354578
    Metadata:
      title           : Chapter 01
    Chapter #0.2: start 1439.354578, end 2046.502778
    Metadata:
      title           : Chapter 02
    Chapter #0.3: start 2046.502778, end 2780.110667
    Metadata:
      title           : Chapter 03
    Chapter #0.4: start 2780.110667, end 3571.192622
    Metadata:
      title           : Chapter 04
    Chapter #0.5: start 3571.192622, end 4710.414022
    Metadata:
      title           : Chapter 05
    Chapter #0.6: start 4710.414022, end 5524.977778
    Metadata:
      title           : Chapter 06
    Chapter #0.7: start 5524.977778, end 6060.929867
    Metadata:
      title           : Chapter 07
    Chapter #0.8: start 6060.929867, end 6359.144444
    Metadata:
      title           : Chapter 08
    Chapter #0.9: start 6359.144444, end 6620.405000
    Metadata:
      title           : Chapter 09
    Stream #0.0(eng): Video: h264 (High), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
    Stream #0.1(eng): Audio: dts (DTS), 48000 Hz, 5.1(side), s16, 1536 kb/s (default)
    Metadata:
      title           : 3/2+1
    Stream #0.2(deu): Audio: ac3, 48000 Hz, 5.1(side), s16, 640 kb/s
    Metadata:
      title           : 3/2+1
    Stream #0.3(deu): Subtitle: hdmv_pgs_subtitle (default)
    Stream #0.4(deu): Subtitle: hdmv_pgs_subtitle
    Stream #0.5(eng): Subtitle: hdmv_pgs_subtitle
File 'out.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'out.mkv':
  Metadata:
    encoder         : Lavf53.11.0
    Chapter #0.0: start 0.000000, end 762.887111
    Metadata:
      title           : Chapter 00
    Chapter #0.1: start 762.887111, end 1439.354578
    Metadata:
      title           : Chapter 01
    Chapter #0.2: start 1439.354578, end 2046.502778
    Metadata:
      title           : Chapter 02
    Chapter #0.3: start 2046.502778, end 2780.110667
    Metadata:
      title           : Chapter 03
    Chapter #0.4: start 2780.110667, end 3571.192622
    Metadata:
      title           : Chapter 04
    Chapter #0.5: start 3571.192622, end 4710.414022
    Metadata:
      title           : Chapter 05
    Chapter #0.6: start 4710.414022, end 5524.977778
    Metadata:
      title           : Chapter 06
    Chapter #0.7: start 5524.977778, end 6060.929867
    Metadata:
      title           : Chapter 07
    Chapter #0.8: start 6060.929867, end 6359.144444
    Metadata:
      title           : Chapter 08
    Chapter #0.9: start 6359.144444, end 6620.405000
    Metadata:
      title           : Chapter 09
    Stream #0.0(eng): Video: h264, yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 1k tbn, 1k tbc (default)
    Stream #0.1(deu): Subtitle: hdmv_pgs_subtitle (default)
    Stream #0.2(deu): Subtitle: hdmv_pgs_subtitle
    Stream #0.3(eng): Subtitle: hdmv_pgs_subtitle
Stream mapping:
  Stream #0.0 -> #0.0 (copy)
  Stream #0.3 -> #0.1 (copy)
  Stream #0.4 -> #0.2 (copy)
  Stream #0.5 -> #0.3 (copy)
Press [q] to stop, [?] for help
frame=45503 fps=259 q=-1.0 size= 1862235kB time=00:08:09.61 bitrate=31158.1kbits/s    
Program terminated with signal SIGKILL, Killed.
The program no longer exists.
(gdb) bt
No stack.
(gdb) disass $pc-32,$pc+32
No registers.
(gdb) info all-registers
The program has no registers now.

comment:8 by Carl Eugen Hoyos, 13 years ago

Since I was unable to reproduce with a random hdmv_pgs_subtitle sample, please upload a suitable input file to http://www.datafilehost.com/

comment:9 by mus, 13 years ago

http://www.datafilehost.com/download-75668c5c.html

I uploaded the subtitle file only (within a MKV container). I tried to split the whole file in <100MB parts, but then it is not reproducible because ffmpeg is done too fast. You should be able to reproduce it if you merge the subtitle with a big video file. I tried it myself, I merged the video track of another file with the subtitle and could reproduce it with the resulting file (which then only contains one video and one subtitle track).

First merge it:
mkvmerge -o merged.mkv -A -S input.mkv subsample.mkv

Then start ffmpeg, which should be killed after a few minutes:
ffmpeg -i merged.mkv -c copy out.mkv

Another interesting thing: Doing the merging with ffmpeg will not cause the problem:

ffmpeg -i input.mkv -i subsample.mkv -c copy -map 0:v:0 -map 1:s:0 output.mkv

comment:10 by wg, 13 years ago

This subtitle track has large gaps in it without any packets (from 60 to 486 and 490 to 6200 seconds). I suspect that you need those large time gaps in buffer memory because ffmpeg refuses to treat subtitles specially. To confirm this theory, please try the appended patch (for ffmpeg-0.8.1 but should apply to more recent versions as well).

by wg, 13 years ago

Treat subtitle streams as noninterleaved when 20 seconds have passed without a packet

comment:11 by mus, 13 years ago

That's what I call a fast bugfix! I just applied the patch to the current Git code and it seems to work perfectly! I guess this ticket can be closed for now, I'm gonna report back if there are any more problems.

When can I expect this patch to be commited to Git?

Thank you very much!

comment:12 by Michael Niedermayer, 13 years ago

Patch locally applied, tabs and unrelated changes removed
will push soon

Thanks alot for the patch

comment:13 by Michael Niedermayer, 13 years ago

Reproduced by developer: set
Resolution: fixed
Status: openclosed

patch pushed, issue should be fixed

Note: See TracTickets for help on using tickets.