How to take a screenshot when streaming
Posted: 21 Oct 2014 09:42
Hello,
I am able to create a network stream from a capcuring device (camera) using libvlc. I am able to display the stream on the streaming pc and conect to the stream from another pc.
However, I am not able to take a screenshot on the streaming pc. I tried the function libvlc_video_take_snapshot. Therefore, I wanted to stream into memory and read the picture directly from the memory. When I stream into the memory, I am not able to stream into network and vice versa. I managed to do both separately. Is possible to stream into the memory and into the network simultaniously?
Or is there an easier way on how to take a screenshot?
Thank you, Martin.
My code:
I am able to create a network stream from a capcuring device (camera) using libvlc. I am able to display the stream on the streaming pc and conect to the stream from another pc.
However, I am not able to take a screenshot on the streaming pc. I tried the function libvlc_video_take_snapshot. Therefore, I wanted to stream into memory and read the picture directly from the memory. When I stream into the memory, I am not able to stream into network and vice versa. I managed to do both separately. Is possible to stream into the memory and into the network simultaniously?
Or is there an easier way on how to take a screenshot?
Thank you, Martin.
My code:
Code: Select all
int _tmain(int argc, _TCHAR* argv[])
{
// VLC pointers
libvlc_instance_t *inst;
libvlc_media_t *m;
void *pUserData = 0;
VideoDataStruct dataStruct;
// VLC options
char smem_options[1000];
// RV24
sprintf(smem_options
,
"--sout=#duplicate{dst=display, dst=transcode{vcodec=RV24}:smem{"
"video-prerender-callback=%lld,"
"video-postrender-callback=%lld,"
"video-data=%lld,"
"no-time-sync}, dst='transcode{vcodec=mp2v,vb=800,scale=Auto,width=240,height=320,acodec=mpga,ab=128,channels=2,samplerate=44100}:http{mux=ts,dst=:8080/}}"
, (long long int)(intptr_t)(void*)&cbVideoPrerender
, (long long int)(intptr_t)(void*)&cbVideoPostrender
, (long long int)(intptr_t)(void*)&dataStruct
);
// sout - stream output
const char * const vlc_args[] = {
"-I", "dummy", // Don't use any interface
"--ignore-config", // Don't use VLC's config
"--extraintf=logger", // Log anything
"--verbose=1", // Be verbose
smem_options // Stream to memory
};
// We launch VLC
inst = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args);
/* Create a new item */
m = libvlc_media_new_location(inst, "dshow://");
/* Create a media player playing environement */
mp = libvlc_media_player_new_from_media (m);
/* play the media_player */
libvlc_media_player_play (mp);
Sleep (6000); /* Let it play a bit */
/* Take a snapshot of the current video window */
libvlc_video_take_snapshot (mp, 0, "D:\\snapshots\\file2.png", 240, 320);
Sleep (1000000); /* Let it play a bit */
}
void cbVideoPrerender(void *p_video_data, uint8_t **pp_pixel_buffer, int size) {
// Locking
if (size > videoBufferSize || !videoBuffer)
{
printf("Reallocate raw video buffer\n");
free(videoBuffer);
videoBuffer = (uint8_t *) malloc(size);
videoBufferSize = size;
}
*pp_pixel_buffer = videoBuffer;
}
void cbVideoPostrender(void *p_video_data, uint8_t *p_pixel_buffer, int width, int height, int pixel_pitch, int size, int64_t pts) {
// Unlocking
}