Page 1 of 1
Snapshot of video stream / how to add to official vlc docs
Posted: 14 Oct 2009 21:30
by Ultraseamus
I am developing around vlc 1.0.2 (but would change to any other version if needed) in C++ for a program to be run on windows xp.
I am just trying to have a snapshot of my video feed save on my hard drive. I have searched around a bit, found a few examples, but mine will still not work. I get the feeling that I am missing somethign simple. To the extent of my knowledge, once I have a video feed playing, all I need to do is call the libvlc_video_take_snapshot function, and it should work. Many people that post problems about this state that a file is created but it is of size zero. For me on the other hand, there is never any file created. No exception is raised, but nothing seems to happen.
Code: Select all
libvlc_video_take_snapshot_dll(m_media_player, "D:\Data\picture.png", 0, 0, &ex);
Is this an invalid call? Is there additional setup prior to this that is required for this function to work? There are multiple settings related to snapshots "--snapshot-path=<string>", "--snapshot-prefix=<string>", etc. Do these have anything to do with the snapshot function I am trying to use? I have tried setting ones that seem like they might be valid, but still no luck. The "--snapshot-sequential" is the next feature I would want to implement after I have this working, but if I provide the file name in my function call, how would this work? Should my function call only include the path up to where the image should be stored?
I know that with my last issue with libvlc_video_set_crop_geometry not working it ended up being as simple as me needing to first add any desired crops into a list when I start vlc via "--custom-crop-ratios=<string>". Which leads me to think that maybe this snapshot problem is just as simple. This also brings me to my second question. I am not sure if I was the only one who got confused, or if my understanding of why my code now works is still incorrect. But, if it is possible I think it might be helpful for future beginners like myself if the official vlc documentation of the function mentioned any required preexisting conditions that must be met. I would happily modify that documentation if it is possible, and other more experienced developers agree it is correct.
Any help or advice on either of these matters would be greatly appreciated.
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 15 Oct 2009 02:20
by Ultraseamus
I have also tried using mediacontrol_snapshot, since I could just as easily save the image data on my own. But I am having the same level of success.
Another idea I am trying is sorting through the vlc code to see if I could maybe make my own function, but I am having trouble figuring all of that out. If anyone could point me to the end spot where the code physically accesses the frame to either save it to a file, or place in memory, it would probably help me figure it out. As far as I can tell the input_source_t variable which through a few iterations is a private variable from input_thread_t. Although to be honest I think I am in over my head trying to figure out this code.
I used to have VLC just write to memory, where I wrote all of my own functions to preform these tasks. It worked pretty well, but in the end having VLC handle the rendering resulted in a better picture. If there was an efficient way (somethign much less than using double the resources) to tell vlc to both display the feed in a window and write it to memory I can access, that would pretty much be perfect. Thanks again for any help anyone can provide me. I have considered creating a second media player, but that just seems so inefficient, especially when I seem to have a simple function alternative built into VLC for me.
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 15 Oct 2009 16:24
by RĂ©mi Denis-Courmont
In theory, you could have a video output plugin that provides the shared picture buffer to a a hook whenever it renders. But this is not supported by any existing plugin.
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 15 Oct 2009 19:48
by Beardless2
you are supplying a width and height of zero to the dll, try entering the dimensions of the output?
i.e. libvlc_video_take_snapshot_dll(m_media_player, "D:\Data\picture.png", 1024, 768, &ex);
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 15 Oct 2009 20:33
by Ultraseamus
First of all, thank you both very much for the replies.
you are supplying a width and height of zero to the dll, try entering the dimensions of the output?
i.e. libvlc_video_take_snapshot_dll(m_media_player, "D:\Data\picture.png", 1024, 768, &ex);
I tried this, and even went so far as to first the width and height from vlc:
Code: Select all
libvlc_exception_t ex;
libvlc_exception_init_dll (&ex);
int tempWidth = 0;
int tempHeight = 0;
tempHeight = libvlc_video_get_height_dll(m_media_player, &ex);
catchException (&ex);
tempWidth = libvlc_video_get_width_dll(m_media_player, &ex);
catchException (&ex);
libvlc_video_take_snapshot_dll(m_media_player, "D:\Data\picture.png", tempWidth, tempHeight, &ex);
catchException (&ex);
The width and height functions return the correct width and height, but as for the snapshot, nothing different happens.
Also, recently when I was trying to get the mediacontrol_snapshot function to work, it did actually return with an error of "Snapshot exception". This suggests to me that my media is somehow not setup correctly for the snapshot to be taken, even though it displays on the screen with no problem after I call:
Code: Select all
m_media_player = libvlc_media_player_new_from_media_dll (m_media, &ex);
catchException (&ex);
libvlc_media_player_play_dll (m_media_player, &ex);
catchException (&ex);
Could these two snapshot functions be failing for the same reason? Do I need to be calling other media player setup functions? Or, is this just a sign that I am have not correctly setup the media control? Once again, thanks very much for trying to help.
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 15 Oct 2009 23:02
by Ultraseamus
I called libvlc_media_player_has_vout right before I try to take the snapshot, thinking it seemed relevant, but it returned a 1 for true. Are there any other functions I could be calling , or tests I could be running to figure out if any part of my system is setup incorrectly? I may just try to start rolling back to older versions of VLC, since from the feedback I have received it seems that no one yet sees anything glaringly wrong with what I am doing.
Edit: Moving from 1.0.2 back to 9.8.a resulted in a file being created. Currently that file is of size 0 like most of the other people have had issues with. But it is a start.
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 20 Oct 2009 00:53
by Ultraseamus
I get the feeling that maybe I provide too much information and make it too hard to find my question. I think what this all comes down to, and what will eventually solve my problem is: How do I use the mediacontrol_snapshot function? It keeps returning with an error of "Snapshot exception" for me. I am currently working with version 9.8.a, and my vout is set to use directx.
If I got this function working it would be exactly what I need. Also, from going through the 9.8.a VLC source, I believe that the two functions are probably failing for the same reason. This same reason is probably also why no file is created with 1.0.2, it just looks like that source code catches the problem sooner.
A lot of people seem to report the "no input" error, not so many have had the "Snapshot exception". I originally had the "no input" error, but that was because I would create the media_control, then create a whole new media_player. Instead, I now use the media_player attached to the media_control. My feed displays correctly, but now I have this snapshot error.
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 20 Oct 2009 20:26
by Ultraseamus
In sample code for Libvlc_video_take_snapshot:
http://wiki.videolan.org/LibVLC_SampleCode_Thumbnailer there is specific code having to do with waiting for the position changed event. What is this all about? Is it somethign I need? I am currently not even setting my position, since I am receiving a live feed, it did not seem necessary, should I be doing this? I assume the set position is just to get to a certain point in the movie where he wants the snapshot to be, but it is the only difference in code that I can see.
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 28 Nov 2015 09:56
by Baghdad_boy
Hi Ultraseamus,
I know that this is a very old thread, but did you manage to solve the issue in the end?
I'm having the same problem with the
method. No error is thrown when the method is called. I've set "--verbose=2" to get a full log and there is no mention of the snapshot to be found.
Code: Select all
int result = libvlc_video_take_snapshot(_vlc_media_recorder, 0, "C:\\Users\\Dev\\Videos\\snap.png", 0, 0);
"result" returns 0 indicating a success but no file is generated and the video continues to play as normal.
I've also tried to set the width and height manually as well as to get them from the video stream as you did.
Any help would be greatly appreciated.
Cheers,
Baghdad_boy
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 14 Dec 2015 10:37
by cyborgc4
Hi,
I also facing same problem.
Can anyone advice me?
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 17 Dec 2015 02:20
by Baghdad_boy
Hey Cyborgc4,
I did get it working in the end. I still don't know the exact issue. It seems to be with the amount of time you give the VLC player to initialise. So you can't call the snapshot command from the same function that you use to initialise the VLC player.
I'll post back once I figure out what the exact thing causing the issue was, but maybe the comment above would be enough for you to figure it out.
Cheers,
Baghdad_boy
Re: Snapshot of video stream / how to add to official vlc docs
Posted: 28 Jun 2016 09:31
by Jean-Baptiste Kempf
look at logs with -vvv