Page 1 of 1

libVLC invmem transcoding fails on MPEG-TS but works with PS

Posted: 10 Sep 2009 16:38
by MCyr
I've been messing around with libVLC for the last couple of days, mainly experimenting with the fake and invmem modules. I'm trying to use VLC to generate MPEG-TS content, but without much success up to now. I was able to use vlc (not libvlc) to transcode pictures through fake:// to MPEG-TS and it worked flawlessly. Now, trying to be a little more fancy, I'm trying to implement a custom drawing routine as the source material for libvlc transcoding process through the use of the invmem codec. My problem is that libVLC segfaults when I try to transcode to MPEG-TS, but works when I'm trying with MPEG-PS. It makes no sense to me since the MPEG video encoding should be done in the same way and consumes the same video frames (in my case PictureData.data), and only the packetizing/muxing should be affected by that change.

In fact, it does work a bit, but only for 1.33 secs of MPEG-TS content.

Valgrind does see a couple of invalid read/writes, but I'm unable to figure if I'm the one doing something wrong or if it's invmem or the transcoding/muxing process. In fact, it sees the same faulty read/writes in both the MPEG-TS and MPEG-PS generation, but TS segfaults (when not run with valgrind) and PS doesn't.

Any ideas, pointers or anything?

Thanks,
Martin

Code: Select all

#define _GNU_SOURCE #include <stdio.h> #include <string.h> #include <stdlib.h> #include <vlc/vlc.h> #define VIDEO_WIDTH "720" #define VIDEO_HEIGHT "480" #define BITRATE "4500000" #define I_VIDEO_WIDTH 720 #define I_VIDEO_HEIGHT 480 #define I_BYTES_PER_PIXEL 3 typedef struct PictureData_ { uint8_t *data; } PictureData; void *lock(void* data) { PictureData *pic = (PictureData *)data; return pic->data; } void *unlock(void* data) { PictureData *pic = (PictureData *)data; return pic->data; } int main (int main_argc, char** main_argv) { libvlc_exception_t ex; libvlc_instance_t *vlc; libvlc_media_t *media; libvlc_media_player_t *player; char buffer[64], *buffer2; int argc; PictureData pic; const char * argv[] = { "-I", "dummy", "--ignore-config", "-vvvvv", "--no-audio", "--sout", "","--disable-screensaver" }; pic.data = (uint8_t *)malloc(I_VIDEO_HEIGHT * I_VIDEO_WIDTH * I_BYTES_PER_PIXEL * sizeof(uint8_t)); memset(pic.data, 0xf0, I_VIDEO_HEIGHT * I_VIDEO_WIDTH * I_BYTES_PER_PIXEL * sizeof(uint8_t)); asprintf(&buffer2, "#transcode{vcodec=mp2v,vb=" BITRATE ",height=" VIDEO_HEIGHT ",width=" VIDEO_WIDTH "}:std{dst=%s}", main_argv[1]); argv[6] = buffer2; argc = sizeof(argv) / sizeof(*argv); libvlc_exception_init (&ex); vlc = libvlc_new (argc, argv, &ex); media = libvlc_media_new (vlc, "fake://", &ex); libvlc_media_add_option (media, ":codec=invmem", &ex); sprintf(buffer, ":invmem-width=%i", I_VIDEO_WIDTH); libvlc_media_add_option (media, buffer, &ex); sprintf(buffer, ":invmem-height=%i", I_VIDEO_HEIGHT); libvlc_media_add_option (media, buffer, &ex); sprintf(buffer, ":invmem-lock=%lld", (long long int)(intptr_t)lock); libvlc_media_add_option (media, buffer, &ex); sprintf(buffer, ":invmem-unlock=%lld", (long long int)(intptr_t)unlock); libvlc_media_add_option (media, buffer, &ex); sprintf(buffer, ":invmem-data=%lld", (long long int)(intptr_t)&pic); libvlc_media_add_option (media, buffer, &ex); player = libvlc_media_player_new_from_media (media, &ex); libvlc_media_player_set_media (player, media, &ex); libvlc_media_player_play (player, &ex); libvlc_wait (vlc); libvlc_media_release (media); libvlc_release(vlc); return (EXIT_SUCCESS); }

Code: Select all

==31635== Thread 5: ==31635== Invalid read of size 8 ==31635== at 0xC0CA039: DecodeBlock (in /usr/lib64/vlc/codec/libinvmem_plugin.so) ==31635== by 0x8973A6D: Send (in /usr/lib64/vlc/stream_out/libstream_out_transcode_plugin.so) ==31635== by 0x34DF6A6691: sout_InputSendBuffer (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63F143: DecoderProcess (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63FAEA: DecoderThread (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF68CC73: thread_entry (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x3F76406869: start_thread (in /lib64/libpthread-2.10.1.so) ==31635== by 0x3F758DE25C: clone (in /lib64/libc-2.10.1.so) ==31635== Address 0x4da21f0 is 360 bytes inside a block of size 384 free'd ==31635== at 0x4A0633D: free (vg_replace_malloc.c:323) ==31635== by 0xCF0A488: Filter (in /usr/lib64/vlc/video_filter/libswscale_plugin.so) ==31635== by 0x34DF69C749: filter_chain_VideoFilter (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x8973ACE: Send (in /usr/lib64/vlc/stream_out/libstream_out_transcode_plugin.so) ==31635== by 0x34DF6A6691: sout_InputSendBuffer (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63F143: DecoderProcess (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63FAEA: DecoderThread (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF68CC73: thread_entry (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x3F76406869: start_thread (in /lib64/libpthread-2.10.1.so) ==31635== by 0x3F758DE25C: clone (in /lib64/libc-2.10.1.so) ==31635== ==31635== Invalid read of size 4 ==31635== at 0x34DF666E70: PictureReleaseCallback (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0xC0CA046: DecodeBlock (in /usr/lib64/vlc/codec/libinvmem_plugin.so) ==31635== by 0x8973A6D: Send (in /usr/lib64/vlc/stream_out/libstream_out_transcode_plugin.so) ==31635== by 0x34DF6A6691: sout_InputSendBuffer (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63F143: DecoderProcess (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63FAEA: DecoderThread (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF68CC73: thread_entry (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x3F76406869: start_thread (in /lib64/libpthread-2.10.1.so) ==31635== by 0x3F758DE25C: clone (in /lib64/libc-2.10.1.so) ==31635== Address 0x4da21a8 is 288 bytes inside a block of size 384 free'd ==31635== at 0x4A0633D: free (vg_replace_malloc.c:323) ==31635== by 0xCF0A488: Filter (in /usr/lib64/vlc/video_filter/libswscale_plugin.so) ==31635== by 0x34DF69C749: filter_chain_VideoFilter (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x8973ACE: Send (in /usr/lib64/vlc/stream_out/libstream_out_transcode_plugin.so) ==31635== by 0x34DF6A6691: sout_InputSendBuffer (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63F143: DecoderProcess (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63FAEA: DecoderThread (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF68CC73: thread_entry (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x3F76406869: start_thread (in /lib64/libpthread-2.10.1.so) ==31635== by 0x3F758DE25C: clone (in /lib64/libc-2.10.1.so) ==31635== ==31635== Invalid write of size 4 ==31635== at 0x34DF666E7A: PictureReleaseCallback (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0xC0CA046: DecodeBlock (in /usr/lib64/vlc/codec/libinvmem_plugin.so) ==31635== by 0x8973A6D: Send (in /usr/lib64/vlc/stream_out/libstream_out_transcode_plugin.so) ==31635== by 0x34DF6A6691: sout_InputSendBuffer (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63F143: DecoderProcess (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63FAEA: DecoderThread (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF68CC73: thread_entry (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x3F76406869: start_thread (in /lib64/libpthread-2.10.1.so) ==31635== by 0x3F758DE25C: clone (in /lib64/libc-2.10.1.so) ==31635== Address 0x4da21a8 is 288 bytes inside a block of size 384 free'd ==31635== at 0x4A0633D: free (vg_replace_malloc.c:323) ==31635== by 0xCF0A488: Filter (in /usr/lib64/vlc/video_filter/libswscale_plugin.so) ==31635== by 0x34DF69C749: filter_chain_VideoFilter (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x8973ACE: Send (in /usr/lib64/vlc/stream_out/libstream_out_transcode_plugin.so) ==31635== by 0x34DF6A6691: sout_InputSendBuffer (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63F143: DecoderProcess (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF63FAEA: DecoderThread (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x34DF68CC73: thread_entry (in /usr/lib64/libvlccore.so.4.0.0) ==31635== by 0x3F76406869: start_thread (in /lib64/libpthread-2.10.1.so) ==31635== by 0x3F758DE25C: clone (in /lib64/libc-2.10.1.so)

Re: libVLC invmem transcoding fails on MPEG-TS but works with PS

Posted: 29 Sep 2009 17:58
by MCyr
Thanks to Hugo Beauzee-Luyssen, it's all running smoothly now.

See git commit df36b003c8242b41d6deae4aa1dc08c4a02410d4.

Big thanks to you Hugo.