twitter / vireo

Vireo is a lightweight and versatile video processing library written in C++11
MIT License
927 stars 111 forks source link

helloworld crashes on any mp4 file #18

Open giulianoc opened 6 years ago

giulianoc commented 6 years ago

Hi, I tested the helloworld.cpp program but it seems it crashes on any mp4 file. I tried to do some debugging but without a bit of information about the code is not easy to find out. giu

canbal commented 6 years ago

Can you share more information about the crash and your environment (OS, gcc version etc)? Also please provide a diff of your changes if you made any.

I don't experience any crash on my side when testing on a Mac.

ghost commented 4 years ago

Hi @canbal , this seems to an issue on Ubuntu 20.04 (Linux machine 5.4.0-28-generic #32-Ubuntu SMP Wed Apr 22 17:40:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux ) also. g++ compiler version(g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0) . gcc compiler version(gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0) . It also fails for the external tools like keyframes , chunk etc all resulting in seg-faults. I know the cause of this . Not really sure there is an elegant solution. Backtracing the seg-fault on gdb points to function parse_pixel_aspect_ratio which calls h264_parse_sps(from lsmash.so shared library) passing a reference of h264_info( variable of type h264_info_t) . Following the chain of calls in lsmash C library, h264_parse_sps   --> h264_parse_sps_minimally     --> nalu_import_rbsp_from_ebsp       -->nalu_remove_emulation_prevention here it ultimately crashes while dereferencing the dst pointer which originally is the memory pointed by h264_info.buffer.rbsp . This leads us to back to where h264_info's sub fields were assigned memory just before the call to h264_parse_sps( in the same parse_pixel_aspect_ratio function) i.e if (h264_setup_parser(&h264_info, 1) != 0) { return false; } It seems that memory is indeed allocated(in the C library's domain at least) toh264_info's sub-fields,as a non-zero value is returned, but is freed when the function returns back to the CPP function.

Could it be that heap is not shared between C library and CPP application ? Please suggest the next course of action to make the library work.

ghost commented 4 years ago

Progress: It seems there is a problem with l-smash library . The h264.h functions aren't meant to be imported directly but only for internal use . See here for more info. The workaround would be to pass a reference of struct of two integers like pixel_aspect_ratio (for pixel aspect ratio's width and height ) to the library and call the required library functions(h264_setup_parser,h264_cleanup_parser) from within . After the changes , helloworld example works fine but some utility programs like chunk are still giving exceptions.