matham / ffpyplayer

A cython implementation of an ffmpeg based player.
GNU Lesser General Public License v3.0
134 stars 38 forks source link

Segfault in VideoState.audio_decode_frame #111

Open tito opened 3 years ago

tito commented 3 years ago

I got right now a replicable bug when i try to load some videos, but only after unloading previous one. See by yourself:

[ERROR  ] [ffpyplayer  ] swr_convert() failed
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff54046f40] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 0 Hz (null) 0 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff54046f40] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 0 Hz (null) 0 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff54046f40] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff54046f40] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 0 Hz (null) 0 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff5405bf00] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 0 Hz (null) 0 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff5405bf00] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 0 Hz (null) 0 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff5405bf00] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 0 Hz (null) 0 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Context has not been initialized
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] swr_convert() failed
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff5405bf00] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 0 Hz (null) 0 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff5405bf00] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7ffe70056340] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 0 Hz (null) 0 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
[ERROR  ] [ffpyplayer  ] [SWR @ 0x7fff5405bf00] Requested input sample rate 0 is invalid
[ERROR  ] [ffpyplayer  ] Cannot create sample rate converter for                 conversion of 48000 Hz s16 2 channels to 48000 Hz s16 2 channels!
double free or corruption (!prev)
--Type <RET> for more, q to quit, c to continue without paging--c

Thread 86 "SDLAudioP2" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fff5f7be640 (LWP 36852)]
0x00007ffff7dd9d22 in raise () from /usr/lib/libc.so.6
(gdb) bt
#0  0x00007ffff7dd9d22 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff7dc3862 in abort () from /usr/lib/libc.so.6
#2  0x00007ffff7e1bd28 in __libc_message () from /usr/lib/libc.so.6
#3  0x00007ffff7e2392a in malloc_printerr () from /usr/lib/libc.so.6
#4  0x00007ffff7e251bc in _int_free () from /usr/lib/libc.so.6
#5  0x00007ffff7e289e8 in free () from /usr/lib/libc.so.6
#6  0x00007fffe67b264f in __pyx_f_10ffpyplayer_6player_4core_10VideoState_audio_decode_frame (__pyx_v_self=<optimized out>) at /tmp/pip-req-build-t3rjrbgv/ffpyplayer/player/core.c:18500
#7  __pyx_f_10ffpyplayer_6player_4core_10VideoState_audio_decode_frame (__pyx_v_self=0x55555652e9f0) at /tmp/pip-req-build-t3rjrbgv/ffpyplayer/player/core.c:18114
#8  0x00007fffe67b21b9 in __pyx_f_10ffpyplayer_6player_4core_10VideoState_sdl_audio_callback (__pyx_v_self=0x55555652e9f0, __pyx_v_stream=0x7fffa402ed40 "", __pyx_v_len=4096) at /tmp/pip-req-build-t3rjrbgv/ffpyplayer/player/core.c:19374
#9  0x00007fffeef98bf9 in SDL_RunAudio (devicep=devicep@entry=0x7fffa47e4af0) at /root/ffmpeg_sources/SDL2-2.0.10/src/audio/SDL_audio.c:735
#10 0x00007fffeeff917c in SDL_RunThread (data=0x7fffa402ca50) at /root/ffmpeg_sources/SDL2-2.0.10/src/thread/SDL_thread.c:283
#11 0x00007fffef07d709 in RunThread (data=<optimized out>) at /root/ffmpeg_sources/SDL2-2.0.10/src/thread/pthread/SDL_systhread.c:79
#12 0x00007ffff7f72259 in start_thread () from /usr/lib/libpthread.so.0
#13 0x00007ffff7e9b5e3 in clone () from /usr/lib/libc.so.6

Just posting this, cannot share the video, but here is the ffprobe on it:

$ ffprobe ~/work/NEWYORK/REV3/LOBBY/SOLAIRE_v7.mp4 
ffprobe version n4.4 Copyright (c) 2007-2021 the FFmpeg developers
  built with gcc 10.2.0 (GCC)
  configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-amf --enable-avisynth --enable-cuda-llvm --enable-lto --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmfx --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librav1e --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-libzimg --enable-nvdec --enable-nvenc --enable-shared --enable-version3
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/tito/work/NEWYORK/REV3/LOBBY/SOLAIRE_v7.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: mp42mp41
    creation_time   : 2021-05-27T17:50:05.000000Z
  Duration: 00:00:45.97, start: 0.000000, bitrate: 10302 kb/s
  Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 9925 kb/s, 30 fps, 30 tbr, 30k tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2021-05-27T17:50:05.000000Z
      handler_name    : ?Mainconcept Video Media Handler
      vendor_id       : [0][0][0][0]
      encoder         : AVC Coding
  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 317 kb/s (default)
    Metadata:
      creation_time   : 2021-05-27T17:50:05.000000Z
      handler_name    : #Mainconcept MP4 Sound Media Handler
      vendor_id       : [0][0][0][0]

There is only one video fullscreen, but 2 others are in background paused, ready to be played. Dunno if that behavior trigger the bug, if i have time, i'll try to post a code to replicate the issue.

tito commented 3 years ago

A tiny different backtrace after multiple unload/load that works

[Thread 0x7fff9e7fc640 (LWP 39235) exited]
[Thread 0x7fff97fff640 (LWP 39239) exited]
--Type <RET> for more, q to quit, c to continue without paging--2;11u 

Thread 86 "SDLAudioP2" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff5f7be640 (LWP 38571)]
0x00007fffe67b24fa in __pyx_f_10ffpyplayer_6player_4core_10VideoState_audio_decode_frame (__pyx_v_self=<optimized out>) at /tmp/pip-req-build-t3rjrbgv/ffpyplayer/player/core.c:18270
18270   /tmp/pip-req-build-t3rjrbgv/ffpyplayer/player/core.c: Aucun fichier ou dossier de ce type.
(gdb) bt
#0  0x00007fffe67b24fa in __pyx_f_10ffpyplayer_6player_4core_10VideoState_audio_decode_frame (__pyx_v_self=<optimized out>) at /tmp/pip-req-build-t3rjrbgv/ffpyplayer/player/core.c:18270
#1  __pyx_f_10ffpyplayer_6player_4core_10VideoState_audio_decode_frame (__pyx_v_self=0x555556530ed0) at /tmp/pip-req-build-t3rjrbgv/ffpyplayer/player/core.c:18114
#2  0x00007fffe67b21b9 in __pyx_f_10ffpyplayer_6player_4core_10VideoState_sdl_audio_callback (__pyx_v_self=0x555556530ed0, __pyx_v_stream=0x7fffa402ed40 "", __pyx_v_len=4096) at /tmp/pip-req-build-t3rjrbgv/ffpyplayer/player/core.c:19374
#3  0x00007fffeef98bf9 in SDL_RunAudio (devicep=devicep@entry=0x7fffa47e4af0) at /root/ffmpeg_sources/SDL2-2.0.10/src/audio/SDL_audio.c:735
#4  0x00007fffeeff917c in SDL_RunThread (data=0x7fffa402ca50) at /root/ffmpeg_sources/SDL2-2.0.10/src/thread/SDL_thread.c:283
#5  0x00007fffef07d709 in RunThread (data=<optimized out>) at /root/ffmpeg_sources/SDL2-2.0.10/src/thread/pthread/SDL_systhread.c:79
#6  0x00007ffff7f72259 in start_thread () from /usr/lib/libpthread.so.0
#7  0x00007ffff7e9b5e3 in clone () from /usr/lib/libc.so.6
rnixx commented 3 years ago

I had strange segfaults when displaying 2 identical videos next to each other when trying to "simultanously" unload them. It was no real use case, just for testing, so i ignored it for now. But IIRC it was also a thing with SDL audio (need to double check).

There's also some issues in the kivy tracker complaining about audio tracks continue to run if player gets stopped and i have another one in mind ranting about issues with SDL mixer and playing multiple audio tracks (forgive me if this was no issue with ffpyplayer).

Also, on linux systems, ffpyplayer won't work if pulseaudio is not installed (not tried with jack), but at least ALSA only won't work.

So obviously there's some issue(s) about how ffpyplayer interferes with SDL Audio.

I can help out testing potential fixes, but a deeper look what might cause those issues should be done by someone with deeper knowledge about SDL audio.

I'm in for helping out wherever i can ;)

tito commented 3 years ago

@rnixx Could you reference others bugs reported that may be the same as this one ? And if you have a snippet that replicate the issue to dig in that would be perfect :)