WebCam Preview and Capture to File (Windows) - c++

What are the available options for creating applications that allow preview of a webcam and exporting the current webcam image to file?
EDIT: I've since found that MS Media Foundation offers similar features to DirectShow that work from Vista upwards. However, while apparently possible, the documentation, samples, and forums don't suggest an easy way to perform the above. On the other hand, with DirectShow you can fairly easily merge two of the sample apps to achieve it.
EDIT: Researching available camera APIs I've also found the MS MediaCapture API looks useful but this seems to be only available on windows 8 (and may be limited to managed C++/.net/javascript).
EDIT: DirectShow is supported on the Windows 8 standard desktop (For Metro style applications the video platform is Media Foundation).

Consider using directshow. You may have a look here

You basically found the answers yourself. DirectShow and Media Foundation are the APIs. Neither of the two cover all Microsoft environments: Metro supports a subset of MF, and MF is not available in legacy OSes. DirectShow is presumably easier, more flexible, with more sample code around.

Related

Grabbing frames when VideoInfoHeader2 structure

I'm working on an application that makes analysis on video files.
Being no expert on DirectShow I used simple code for the analysis
of all frames (SampleGrabber, Callback etc.).
This works fine for all media files, even when decoded with
VideoInfoHeader2 structure (although it shouldn't, as stated everywhere).
The problem is with grabbing a single frame.
For this I used IMediaDet. And this doesn't do if there's only VideoInfoHeader2, and no VideoInfoHeader.
I tried modifications of my analysis code (OneShot, Seek), but it doesn't do.
All sources in the internet concerning this are not very helpful, as they point to SDK/ DX examples that aren't accessible anymore, or they just say that modification would be "easy".
Well, maybe for an DX expert ...
(But I need to use the car, not first to build it ... ;-)
As the matter became more & more important to me my "workaround" is to recode all videos with VideoInfoHeader2, save them with VideoInfoHeader, and do the analysis/ grabbing on that.
Very resource consuming, and the opposite of smart ...
Any help appreciated.
You outlined the necessary steps which are still the easiest solution (provided that you don't give up and use Windows API; using a third party library might be easier in comparison but this is beyond the scope of this question).
Sample Grabber and IMediaDet are parts of deprecated DirectShow Editing Services, development of which was stopped long ago. If you are not satisfied with stock API, you have to use a more flexible replacement. For example, you can grab source of similar Sample Grabber sample from older DirectX or Platform SDK and extend it to support VIDEOINFOHEADER2.
IMediaDet is nothing but COM class building its own graph internally trying to decode video. It is inflexible and almost every time your building your own graph is a more reliable solution.
Microsoft's answer to this problem is - as they abandoned DirectShow development - newer API Media Foundation. However there are reasons why this "answer" is not so good: limited OS compatibility, limited support for codecs and formats, completely new API which has little in common with DirectShow and you need to redesign your application.
All together, you either have to find a Sample Grabber replacement using one of the popular and explained methods (no matter they look not so much helpful), or switch to another API or third party library. Or, another possible solution is to use a different filter/codec which is capable of decoding into VIDEOINFOHEADER formatted media type.

Any cross-platform video playback library for c++?

I mainly code using the Qt library, which is cross-platform enough for my need. However, I found out that if I'd like to play a video file there are no good options for cross-platform video playback. The Phonon module doesn't seem to work on my machine and I am not sure if it is supported on the major platforms (Windows, OSX, Linux).
Are their any light-weight alternatives for simple video playback? I would be okay to change my video to any format as long as its playable cross-platform.
I am considering libVLC as one option. Someone have already made a wrapper but it only supports Windows and Linux.
I found the Theora playback library to be very useful and only depends on the original theora library. Here is a simple Qt project I made that encapsulate everything needed to play (only video) theora media. You just type 'qmake' and you are good to go.
According to the documentation is appears Phonon needs third party libraries to work correctly. Have you installed the appropriate backend to the platform you're on?
From the documentation:
Backends
The multimedia functionality is not implemented by Phonon itself, but
by a back end - often also referred to as an engine. This includes
connecting to, managing, and driving the underlying hardware or
intermediate technology. For the programmer, this implies that the
media nodes, e.g., media objects, processors, and sinks, are produced
by the back end. Also, it is responsible for building the graph, i.e.,
connecting the nodes. The backends of Qt use the media systems
DirectShow (which requires DirectX) on Windows, QuickTime on Mac, and
GStreamer on Linux. The functionality provided on the different
platforms are dependent on these underlying systems and may vary
somewhat, e.g., in the media formats supported.
Backends expose
information about the underlying system. It can tell which media
formats are supported, e.g., AVI, mp3, or OGG.
A user can often add
support for new formats and filters to the underlying system, by, for
instance, installing the DivX codex. We can therefore not give an
exact overview of which formats are available with the Qt backends.
QtWebKit 2.2 has support for HTML5 media. It should (at least eventually) be pretty cross-platform, but probably has the same backend issues as Phonon. But a Q(Graphics)WebView with a <video> element could do the trick for a truly play-and-forget solution.

Finding C++ multimedia editing graph-like frameworks?

I'm searching for multimedia editing graph-like frameworks where you can create graph elements with C++ and where you can build graphs for your app needs from elements of framework.
So far I know there are
GStreamer
DirectShow
QuickTime
Qt Phonon (cross-platform wrapper around first 3)
I wonder to see what else is out there - are there proprietary or open source, cross-platform or platform-dependent alternatives and what are their main goals?
Microsoft Media Foundation -- more or less a replacement for DirectShow. I don't see any drastic improvements, but if you want to use (for example) Microsoft's new H.264 decoder, you're pretty much stuck with it. As you can undoubtedly guess from the name, it's Windows only. Perhaps less obviously, it's supported only on Vista and later.
Another that sort of fits the description is FFMpeg.

Using Windows media foundation

Ok so my new gig is high performance video (think Google streetview but movies) - the hard work is all embedded capture and image processing but:
I was looking at the new MS video offerings to display content = Windows Media Foundation.
Is anyone actually using this ?
There are no books on the topic.
The only documentation is a developer
team blog with a single entry 9 months old.
I thought we had got past having to learn an MS api by spying on the com control messages!
Is it just another wrapper around the same old activeX control?
I read the Media Foundation Programming Guide, and it's as complete as everything else is w/ MS, in that you have all the information you need, no clue on how to find it, and no idea what's important when.
I'm trying to use MMF, but I'm currently not getting anywhere, and am thinking that going back to DirectShow might be the better approach as there is more example code with explanations.
No, it does not appear to be just another wrapper around the same ActiveX controls.
Did you read Media Foundation Programming Guide? It looks pretty complete.
To get started with Media Foundation you might want to read this. Media Foundation was first introduced in Windows Vista. Thus, you must have Vista or later versions of Windows to develop Media Foundation apps. If you are targeting Windows XP users then, D-Show might be a better option.

How can one play a FLV file from Youtube in a C++ application?

I'm using C++ to get Youtube video links, but now I would like to be able to play a stream in my application.
Using C++ wxWidgets, what cross platform options do I have?
Look at existing video players like mplayer or vlc that can both play flv files.
It you want a something a a somewhat lower level, Qt::media supports Gstream that supports flv. However this might go against what you want as you use wxwidgets.
Then, you can directly look into integrating GStreamer in your app.
The wxMediaCtrl class in wxWidgets is used to play video:
http://docs.wxwidgets.org/stable/wx_wxmediactrl.html
http://docs.wxwidgets.org/trunk/classwx_media_ctrl.html
On MacOS X and Windows wxMediaCtrl uses the native backend, and on Linux GStreamer. I don't know if the native backends on the first two support flv.
FFMPEG supports demuxing and decoding of the FLV format (among others), and is the best implementation I know of besides Flash itself. It's relatively easy to use, and it's used by all of the software others have suggested for decoding of Flash Video.
After some searching in google I believe there isn't something pre-made in C++ that will match WxWidgets but you should be able to find a decoder and use it's API.