AviSynth / AviSynthPlus

AviSynth with improvements
http://avs-plus.net
975 stars 75 forks source link

Threading segfault on real video, Ubuntu 19.10 #127

Open qyot27 opened 4 years ago

qyot27 commented 4 years ago

Ubuntu 19.10 64-bit Core i5-9400, 16GB RAM

Script:

LoadPlugin("/home/qyot27/FFMS2_cplugin/libffms2.so.2")
SetFIlterMTMode("DEFAULT_MT_MODE", MT_NICE_FILTER)
SetFIlterMTMode("FFmpegSource2", MT_SERIALIZED)
FFmpegSource2("Frozen.mkv",atrack=-1)
#ColorbarsHD()
#Trim(0,24)
#Info()
#Crop(0,0,-3200,-1860)
Prefetch(4)

Segfaults. If I comment out the FFMS2 invocation and enable ColorbarsHD, it works, even with all the other filters enabled as well. From the backtrace, it looks as if it might have to do with the Prefetcher:

qyot27@cappuccino:~$ mpv test.avs
[ffmpeg/demuxer] avisynth: Stream #0: not enough frames to estimate rate; consider increasing probesize
 (+) Video --vid=1 (rawvideo 3840x2160 23.976fps)
 (+) Audio --aid=1 (pcm_s32le 8ch 48000Hz)
AO: [pulse] 48000Hz 7.1 8ch s32
Segmentation fault (core dumped)
qyot27@cappuccino:~$ 

(gdb) r test.avs
Starting program: /usr/local/bin/mpv test.avs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff26aa700 (LWP 21018)]
[New Thread 0x7ffff1ea9700 (LWP 21019)]
[New Thread 0x7ffff16a8700 (LWP 21020)]
[New Thread 0x7ffff0ea7700 (LWP 21021)]
[New Thread 0x7fffe3fff700 (LWP 21022)]
[New Thread 0x7fffe37fe700 (LWP 21023)]
[New Thread 0x7fffe2ffd700 (LWP 21024)]
[New Thread 0x7fffe27fc700 (LWP 21025)]
[New Thread 0x7fffe1244700 (LWP 21026)]
[New Thread 0x7fffe0a43700 (LWP 21027)]
[New Thread 0x7fffcbfff700 (LWP 21028)]
[New Thread 0x7fffcb7fe700 (LWP 21029)]
[New Thread 0x7fffcaffd700 (LWP 21030)]
[New Thread 0x7fffca7fc700 (LWP 21031)]
[New Thread 0x7fffb7fff700 (LWP 21033)]
[New Thread 0x7fffb77fe700 (LWP 21034)]
[New Thread 0x7fffb6ffd700 (LWP 21035)]
[New Thread 0x7fffb67fc700 (LWP 21036)]
[New Thread 0x7fffb5ffb700 (LWP 21037)]
[New Thread 0x7fffb57fa700 (LWP 21038)]
[New Thread 0x7fffaffff700 (LWP 21041)]
[New Thread 0x7fffaf7fe700 (LWP 21042)]
[New Thread 0x7fffaeffd700 (LWP 21043)]
[New Thread 0x7fffae7fc700 (LWP 21044)]
[ffmpeg/demuxer] avisynth: Stream #0: not enough frames to estimate rate; consider increasing probesize
[Thread 0x7fffe27fc700 (LWP 21025) exited]
[New Thread 0x7fffe27fc700 (LWP 21045)]
[New Thread 0x7fffadffb700 (LWP 21046)]
 (+) Video --vid=1 (rawvideo 3840x2160 23.976fps)
 (+) Audio --aid=1 (pcm_s32le 8ch 48000Hz)
[New Thread 0x7fffad7fa700 (LWP 21047)]
[Thread 0x7fffad7fa700 (LWP 21047) exited]
[New Thread 0x7fffad7fa700 (LWP 21048)]
[New Thread 0x7fffacff9700 (LWP 21049)]
[New Thread 0x7fff56ede700 (LWP 21050)]
[New Thread 0x7fff566dd700 (LWP 21051)]
[New Thread 0x7fff55edc700 (LWP 21052)]
AO: [pulse] 48000Hz 7.1 8ch s32

Thread 25 "mpv/opener" received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffae7fc700 (LWP 21044)]
__GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
50  ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007ffff62f4899 in __GI_abort () at abort.c:79
#2  0x00007fffc857250c in matroska_read_packet ()
   from /home/qyot27/FFMS2_cplugin/libffms2.so.2
#3  0x00007fffc84e425f in ff_read_packet ()
   from /home/qyot27/FFMS2_cplugin/libffms2.so.2
#4  0x00007fffc84e4bdb in read_frame_internal ()
   from /home/qyot27/FFMS2_cplugin/libffms2.so.2
#5  0x00007fffc84e58d8 in av_read_frame ()
   from /home/qyot27/FFMS2_cplugin/libffms2.so.2
#6  0x00007fffc84c5dcc in FFMS_VideoSource::ReadFrame (this=0x7fffcc0496f0, 
    pkt=0x7fffae7fb510) at src/core/videosource.cpp:660
#7  0x00007fffc84c5f3d in FFMS_VideoSource::DecodeNextFrame (
    this=0x7fffcc0496f0, AStartTime=@0x7fffae7fb5a0: -1, 
    Pos=@0x7fffae7fb5a8: -1) at src/core/videosource.cpp:695
#8  0x00007fffc84c635b in FFMS_VideoSource::GetFrame (this=0x7fffcc0496f0, n=2)
    at src/core/videosource.cpp:769
#9  0x00007fffc84aabb5 in FFMS_GetFrame (V=0x7fffcc0496f0, n=2, 
    ErrorInfo=0x7fffae7fb690) at src/core/ffms.cpp:157
#10 0x00007fffc84d2446 in AvisynthVideoSource::GetFrame (this=0x7fffcc001290, 
    n=2, Env=0x7fffae7fbc20) at src/avisynth/avssources.cpp:554
#11 0x00007fffe1637ffb in AudioDub::GetFrame (this=0x7fffce0e6860, n=2, 
    env=0x7fffae7fbc20) at ../avs_core/filters/edit.cpp:842
--Type <RET> for more, q to quit, c to continue without paging--
#12 0x00007fffe1552576 in Prefetcher::ThreadWorker (env=0x7fffae7fbc20, 
    data=0x7fffcd556790) at ../avs_core/core/Prefetcher.cpp:101
#13 0x00007fffe155f950 in ThreadFunc (thread_id=4, msgQueue=0x7fffa8d1cf48)
    at ../avs_core/core/ThreadPool.cpp:84
#14 0x00007fffe15648fb in std::__invoke_impl<void, void (*)(unsigned long, mpmc_bounded_queue<ThreadMessage>*), unsigned long, mpmc_bounded_queue<ThreadMessage>*> (__f=@0x7fffcd8f8be8: 0x7fffe155f7f3 <ThreadFunc(size_t, MessageQueue*)>, 
    __args#0=@0x7fffcd8f8be0: 4, __args#1=@0x7fffcd8f8bd8: 0x7fffa8d1cf48)
    at /usr/include/c++/9/bits/invoke.h:60
#15 0x00007fffe1564810 in std::__invoke<void (*)(unsigned long, mpmc_bounded_queue<ThreadMessage>*), unsigned long, mpmc_bounded_queue<ThreadMessage>*> (__fn=
    @0x7fffcd8f8be8: 0x7fffe155f7f3 <ThreadFunc(size_t, MessageQueue*)>, 
    __args#0=@0x7fffcd8f8be0: 4, __args#1=@0x7fffcd8f8bd8: 0x7fffa8d1cf48)
    at /usr/include/c++/9/bits/invoke.h:95
#16 0x00007fffe156472f in std::thread::_Invoker<std::tuple<void (*)(unsigned long, mpmc_bounded_queue<ThreadMessage>*), unsigned long, mpmc_bounded_queue<ThreadMessage>*> >::_M_invoke<0ul, 1ul, 2ul> (this=0x7fffcd8f8bd8)
    at /usr/include/c++/9/thread:244
#17 0x00007fffe15646ca in std::thread::_Invoker<std::tuple<void (*)(unsigned long, mpmc_bounded_queue<ThreadMessage>*), unsigned long, mpmc_bounded_queue<ThreadMessage>*> >::operator() (this=0x7fffcd8f8bd8) at /usr/include/c++/9/thread:251
#18 0x00007fffe15646aa in std::thread::_State_impl<std::thread::_Invoker<std::tuple<void (*)(unsigned long, mpmc_bounded_queue<ThreadMessage>*), unsigned long, --Type <RET> for more, q to quit, c to continue without paging--
mpmc_bounded_queue<ThreadMessage>*> > >::_M_run (this=0x7fffcd8f8bd0)
    at /usr/include/c++/9/thread:195
#19 0x00007ffff65b2f74 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#20 0x00007ffff69ea669 in start_thread (arg=<optimized out>)
    at pthread_create.c:479
#21 0x00007ffff63f1323 in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb) quit
A debugging session is active.

    Inferior 1 [process 21017] will be killed.

Quit anyway? (y or n) y
pinterf commented 4 years ago

Could you help me with libffms2.so.2? Should I build it (dependencies?) or a simple file upload is enough?

DJATOM commented 4 years ago

It's not that hard to compile, probably even easier than on Windows. Assuming you already have ffmpeg libs installed in the system, it's just something like

./configure 
NPROC=$(nproc)
make -j${NPROC}

or so.

pinterf commented 4 years ago

Thanks

git clone git://github.com/qyot27/ffms2_cplugin.git
cd ffms2_cplugin
git checkout c_plugin
./configure
make -j$(nproc)
make install

result:

./configure
checking whether linking with FFmpeg or Libav...
unable to link against Libav
make: *** [GNUmakefile:106: config.mak] Error 1
DJATOM commented 4 years ago
djatom@atomch-server:~/ffms2_cplugin$ ./configure --enable-avisynth
avisynth support is invalid under non-MinGW environments
checking whether linking with FFmpeg or Libav...
avisynth:     no
avisynth-gcc: no
avxsynth:     no
vapoursynth:  no
debug:        no
gprof:        no
PIC:          no
shared:       no
optlevel:     2

You can run 'make' now.

Apparently we can't build from c_plugin branch atm. @qyot27 should provide updated build scripts to do so.

sl1pkn07 commented 4 years ago

you need use the patches_plusvp9av1 branch

checking whether linking with FFmpeg or Libav... 
avisynth-c:   no
avisynth-cpp: yes
avxsynth:     no
vapoursynth:  yes
debug:        no
gprof:        no
PIC:          yes
shared:       yes
optlevel:     2
pinterf commented 4 years ago

No luck on patches_plusvp9av1 either: Libav problem, which I cannot solve with my present knowledge

./configure --enable-avisynth-c
avisynth support is invalid under non-MinGW environments
checking whether linking with FFmpeg or Libav...
unable to link against Libav
 ./configure --enable-avisynth-cpp
checking whether linking with FFmpeg or Libav...
unable to link against Libav
DJATOM commented 4 years ago
djatom@atomch-server:~/ffms2_cplugin$ ./configure --enable-avisynth-cpp --enable-shared --enable-pic
checking whether linking with FFmpeg or Libav...
avisynth-c:   no
avisynth-cpp: yes
avxsynth:     no
vapoursynth:  no
debug:        no
gprof:        no
PIC:          yes
shared:       yes
optlevel:     2

You can run 'make' now.
djatom@atomch-server:~/ffms2_cplugin$ make
 CXX    src/core/audiosource.o
...
 CXX    libffms2.so.2
 CXX    src/index/ffmsindex.o
 AR     libffms2.a
 RANLIB libffms2.a
 CXX    ffmsindex

So I just tried to encode FFVideoSource (mp4 file) without prefetch and it works. console-output

sl1pkn07 commented 4 years ago

libav is not dead project?

DJATOM commented 4 years ago

@pinterf you can try to compile ffmpeg locally

git clone https://github.com/qyot27/FFmpeg.git
cd ./FFmpeg
git checkout avsplus_linux
./configure --enable-gpl --enable-version3 --disable-doc --disable-stripping --enable-avisynth
make -j$(nproc)
sudo make install

That way ffmpeg libs will be available for configuring and compilation.

DJATOM commented 4 years ago

Prefetch is also works.

qyot27 commented 4 years ago

The error is specifically audio-related, and seems isolated in FFMS2 itself, since FFAudioSource works, as does FFVideoSource, and using AudioDub to pair them works. The atrack parameter in the FFmpegSource2 function in the C++ plugin does not.