2

I am working to get stream from file to my buffer so that i can send it via my custom port/protocol and i am facing couple of issues, so please help me out

where i am:

  • After reading the tutorial from https://wiki.videolan.org/Stream_to_memory_(smem)_tutorial/ I am able to compile and run

  • I have done following changes for smem options to work with video (please refer to complete code mentioned at the end)

      sprintf(smem_options, "#transcode{vcodec=RV32}:smem{video-postrender-callback=%lld,video-prerender-callback=%lld}",
      // We are using transcode because smem only support raw audio and video formats
      (long long int)(intptr_t)(void*)&handleStream, (long long int)(intptr_t)(void*)&prepareRender);
    
  • I can see that both prerender and postrenders are being called and data is being supplied

My Problems:

  • currently to test the output I am dumping the buffer directly to file, some thing like fwrite (p_pixel_buffer, sizeof(char), i_size, myfile); but dumped file is not being read either by VLC player or any other streaming player so I am sure I am missing here something, because if I ask VLC player to write directly to file by giving full transcode values then things are fine

      sprintf(smem_options,
          "#transcode{vcodec=theo,vb=800,acodec=vorb,ab=128,channels=2,samplerate=44100}:file{dst=stream-output.ogg}"
      );
    

My Questions

  • Is reading from the buffer correct? because I read

First, a quick warning: starting with VLC2.2 (current git version, to be released soon), the size parameter is a size_t. There's no API for smem (yet? hopefully this will change), which sucks, so this would silently break your application.

from Get frame from video with libvlc smem and convert it to opencv Mat. (c++)

if yes then * Is there any alternative API where i can hook and get buffer?

if not then * What's wrong with what I am doing and what do I need to do to get this done?

Any pointers/sample program would be great help.

PS:

Jon
  • 9,156
  • 9
  • 56
  • 73
rajiv
  • 486
  • 6
  • 9

2 Answers2

0

Your code and process appears correct, but the reason you probably can't open the resulting data is because you are writing out raw image data into a buffer which is just BGR or other pixel data and not a video file VLC will open. With SMEM interface you are basically telling VLC what output format to transcode into memory, so in the example you linked for OpenCV they are transcoding to BGR or something else that they can then using in a cv::Mat structure to display.

bossbarber
  • 870
  • 6
  • 10
0

You can also check this sample code written for smem module in C++. It does not save buffer but at least provides a handy way to access buffers both for video and audio.

And it has to be said that current VLC 2.2.4 has issues when transcoding streams in conjunction with smem module. Latest 3.0.0 nightly builds seam to overcome the issue.

Alternatively you can use libvlc_video_set_callbacks, libvlc_video_set_format_callbacks, libvlc_audio_set_callbacks and libvlc_audio_set_format_callbacks functions to access data. See sample code and a discussion for details.

alex
  • 425
  • 4
  • 21