[Libav-user] "Segmentation fault" When encoding H264 video frame

M N assemblerx86 at yandex.com
Wed Sep 14 15:38:39 EEST 2016


14.09.2016, 14:32, "M N" <assemblerx86 at yandex.com>:
> 14.09.2016, 11:12, "Peter Steinbach" <steinbach at scionics.de>:
>>  if your distro doesn't offer ffmpeg with debug symbols, I suggest
>>  building ffmpeg with debug symbols enabled. then link your code with it.
>>  If you then run your app in gdb, the backtrace (type in 'bt' and hit
>>  enter after the SIGSEGV is emitted) and may contain the line of code in
>>  ffmpeg that yielded the segfault. with this, you might be able to find
>>  the root cause of this problem.
>>
>>  out of curiosity: what distro do you use, that has problems with
>>  valgrind?! I never heard something along those lines.
>>
>>  Best,
>>  Peter
>>  _______________________________________________
>>  Libav-user mailing list
>>  Libav-user at ffmpeg.org
>>  http://ffmpeg.org/mailman/listinfo/libav-user
>
> I use Gentoo, I will install ffmpeg with debug symbols and try backtracing.

OK, I have fixed Valgrind and got this output upon running my program in Valgrind:

************************************
==21468== Memcheck, a memory error detector
==21468== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==21468== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==21468== Command: ./out
==21468== 
==21468== Invalid write of size 8
==21468==    at 0x4013EA: main (main.c:49)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401405: main (main.c:51)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid write of size 8
==21468==    at 0x40145D: main (main.c:58)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401478: main (main.c:60)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4014C1: main (main.c:62)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x40151A: main (main.c:72)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401540: main (main.c:73)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x40155B: main (main.c:73)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401582: main (main.c:75)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x40159D: main (main.c:75)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4015C4: main (main.c:76)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4015DF: main (main.c:76)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401606: main (main.c:77)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401621: main (main.c:77)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x40164A: main (main.c:78)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401665: main (main.c:78)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x40169C: main (main.c:81)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401724: main (main.c:86)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x40173F: main (main.c:86)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401933: main (main.c:103)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401973: main (main.c:106)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4019A5: main (main.c:107)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
[libx264 @ 0xcb9e440] broken ffmpeg default settings detected
[libx264 @ 0xcb9e440] use an encoding preset (e.g. -vpre medium)
[libx264 @ 0xcb9e440] preset usage: -vpre <speed> -vpre <profile>
[libx264 @ 0xcb9e440] speed presets are listed in x264 --help
[libx264 @ 0xcb9e440] profile is optional; x264 defaults to high
==21468== Invalid read of size 8
==21468==    at 0x40149A: main (main.c:60)
==21468==  Address 0xcb95d18 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x40176D: main (main.c:89)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401788: main (main.c:89)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4017AF: main (main.c:90)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4017CA: main (main.c:90)
==21468==  Address 0xcb95d18 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4017F1: main (main.c:91)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x40180C: main (main.c:91)
==21468==  Address 0xcb95d18 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401835: main (main.c:92)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401850: main (main.c:92)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401880: main (main.c:94)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4018AE: main (main.c:95)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x4018E7: main (main.c:96)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401902: main (main.c:96)
==21468==  Address 0xcb95d68 is 6 bytes after a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401DB3: main (main.c:152)
==21468==  Address 0xcb95d10 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x401313: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x401DF1: main (main.c:154)
==21468==  Address 0xcb95d60 is 0 bytes inside a block of size 2 alloc'd
==21468==    at 0x4C29F40: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==21468==    by 0x40132E: main (main.c:31)
==21468== 
==21468== Invalid read of size 8
==21468==    at 0x5297EB0: avcodec_encode_video2 (in /usr/lib64/libavcodec.so.56.60.100)
==21468==    by 0x401E09: main (main.c:154)
==21468==  Address 0x48 is not stack'd, malloc'd or (recently) free'd
==21468== 
==21468== 
==21468== Process terminating with default action of signal 11 (SIGSEGV)
==21468==  Access not within mapped region at address 0x48
==21468==    at 0x5297EB0: avcodec_encode_video2 (in /usr/lib64/libavcodec.so.56.60.100)
==21468==    by 0x401E09: main (main.c:154)
==21468==  If you believe this happened as a result of a stack
==21468==  overflow in your program's main thread (unlikely but
==21468==  possible), you can try to increase the size of the
==21468==  main thread stack using the --main-stacksize= flag.
==21468==  The main thread stack size used in this run was 8388608.
==21468== 
==21468== HEAP SUMMARY:
==21468==     in use at exit: 3,782,903 bytes in 482 blocks
==21468==   total heap usage: 1,005 allocs, 523 frees, 10,004,233 bytes allocated
==21468== 
==21468== LEAK SUMMARY:
==21468==    definitely lost: 0 bytes in 0 blocks
==21468==    indirectly lost: 0 bytes in 0 blocks
==21468==      possibly lost: 51,360 bytes in 15 blocks
==21468==    still reachable: 3,731,543 bytes in 467 blocks
==21468==         suppressed: 0 bytes in 0 blocks
==21468== Rerun with --leak-check=full to see details of leaked memory
==21468== 
==21468== For counts of detected and suppressed errors, rerun with: -v
==21468== ERROR SUMMARY: 47 errors from 38 contexts (suppressed: 0 from 0)
Killed
************************************


And here is GDB output with backtracing:

************************************
[New Thread 0x7ffff0726700 (LWP 22020)]
[New Thread 0x7fffeff25700 (LWP 22021)]
[New Thread 0x7fffef724700 (LWP 22022)]
[New Thread 0x7fffeef23700 (LWP 22023)]
[New Thread 0x7fffee722700 (LWP 22024)]
[New Thread 0x7fffedf21700 (LWP 22025)]
[New Thread 0x7fffed720700 (LWP 22026)]
[libx264 @ 0x7e0830] broken ffmpeg default settings detected
[libx264 @ 0x7e0830] use an encoding preset (e.g. -vpre medium)
[libx264 @ 0x7e0830] preset usage: -vpre <speed> -vpre <profile>
[libx264 @ 0x7e0830] speed presets are listed in x264 --help
[libx264 @ 0x7e0830] profile is optional; x264 defaults to high
1
done
Write header 0: Success

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff705eeb0 in avcodec_encode_video2 () from /usr/lib64/libavcodec.so.56
(gdb) bt
#0  0x00007ffff705eeb0 in avcodec_encode_video2 ()
   from /usr/lib64/libavcodec.so.56
#1  0x0000000000401e0a in main () at main.c:154
************************************


More information about the Libav-user mailing list