What's the most recommended way to go?
This is a pretty big topic. Try looking at OpenCV. It is nice for image and video manipulation, and you can stream video from files and webcams.
Take a look at DirectX "Filter Graphs". You can use a simple tool from the DirectX SDK called 'Graph Edit' to construct a sequence of DirectShow Filters which can do things like capture video streams from a TV card or decode an MPEG/AVI file and then operate on the data stream and ultimately render it to video/audio or a file.
Most of the DirectShow samples are in VC++.
Related
I have logitech webcam, which streams 1080p#30fps using MJPG compression via USB2.0. I need to write this raw stream to hard drive or send via network. I do NOT need to decompress it. OpenCV gives me decompressed frames, so i need to compress them back. This leads to heavy CPU utilization waste. How to get raw MJPEG stream instead as it comes from camera? (Windows 7, Visual Studio, C++)
Windows native video capture related APIs DirectShow and Media Foundation let you capture video from a webcam in original format. It is a natural task for these APIs and is done in a straightforward way (specifically, if a web camera gets hardware compressed M-JPEG feed, you can have that programmatically).
About Video Capture in DirectShow
Audio/Video Capture in Media Foundation
You are free to do whatever you want with the data afterwards: decompress, send over network, compose a Motion JPEG over HTTP response feed etc.
I need to use DirectShow (C++) for recording a webcam and saving the data to a file.
I really don't know how DirectShow works, this is a "stage" (working experience), but at school we didn't study it.
I think the best way to implement this could be:
List the video devices connected to the computer
Select the correct camera (there will be only one)
Retrieve the video
Save it to a file
Now there are two problems:
Where can I find a good reference book or how do I start?
The saved video shouldn't be too big, does DirectShow provide a way to compress it?
I won't use OpenCV because sometime it doesn't work properly (It doesn't find the camera).
Are there any high level wrapper that could help?
EDIT: the program won't have a window, it will run in background called by a dll.
Where can I find a good reference book or how do I start?
DirectShow introduction material
The saved video shouldn't be too big, does DirectShow provide a way to compress it?
Yes it provides capabilities to attach codecs, that needs to be installed in the system. These are typically third party codecs (for reasons beyond the scope of brief answer). You might want to record into Windows Media files to not depend on third party codecs. SWee more on MSDN: Choosing a Compression Filter.
This may be a dumb question but I'm having a hard time conceptualizing what I need to do here...In the past I've used DirectShow to connect to a camera and capture an AVI using a source filter, AVI mux, compression filter, run the graph, etc...piece of cake.
In this particular case I am getting notified when my non DirectShow camera driver has a buffer ready. I get notification and then I go and grab the BYTE* and render it using GDI. I now also need to create an AVI with these buffers.
Conceptually it makes sense for me to use something like vfw and write to an AVI stream every time I receive a buffer, of course vfw is old technology and I was also having some problems getting that to work (as I posted in a different forum).
How can I push these buffers into a DirectShow AVI Mux and write to a file? Do I have to create my own source filter to receive these buffers, then add my source filter and avi mux to a filter graph?
Thanks for any tips
So you have BYTE* with video frame data. It is very close to what you supposed. Your choices are to either use VFW AVIFileOpen and friends to write into AVI file, or inject data into DirectShow pipeline. To do the latter, you typically make your PushSource-like filter and push video frames from there (through AVI Mux to File Writer).
I want to read in an .avi video file for a program that I am making. I have the file location saved as a string. Is there any good tutorials on using .avi files in c++ or does anyone know who to read one in? Is it the same as normal files?
I have a previously asked SO question that goes into better detail but here is what I want to do:
I am making a program that will detect faces (though OpenCV) As of now I have been given a video processor program that will detect each face on a frame, and return the frame as a image and the CvRec of the faces. I want to take these faces and test them to validate that they are all actually faces.
After I have all the faces (tested) I want to then take the images and test them together. I test the faces on each frame for size and distance changes. If the faces pass this for a frame length of two seconds, then I want to crop the face and make it the subject of each frame.
After each frame is cropped I then want to save the new video file for the user.
Hopefully that helps. If anyone needs a better explanation please let me know.
First of all, a little background.
What is AVI?
AVI stands for Audio Video Interleave. It is a special case of the RIFF (Resource Interchange File Format). AVI is defined by Microsoft and it is the most common format for audio/video data.
I assume you would want to read a avi file and decode the compressed video frames. AVI file is just like any other normal file and you can use fread()(in C) or iostream(in C++) to open an avi file and read it contents. But the contents of an avi file are video frames in a compressed format. The compression allows video content of bigger sizes to be efficiently packed in less memory space.To make any sense of this compressed data you would have to decode the encoded data format.You will have to study the standard which describes how AVI encoding is done and then extract and decode the frames. this raw video data now when fed to a video device will be displayed in video format.
It seems you are staying within OpenCV so things are easy. If OpenCV is compiled properly it is capable of delegating io/coding/decoding to other libraries. Quicktime and others for example, but best is to use ffmpeg. You open, read and decode everything using the OpenCV API which gives you the video frame by frame.
Make sure your OpenCV is compiled with ffmpeg support and then read the OpenCV tutorial on how to read/write AVI files. It's really easy.
Getting OpenCV to be built with ffmpeg support might be hard though. You might want to switch to an older version of OpenCV if you can't get ffmpeg running with the current one.
Personally i would not spent time trying to read the video by yourself and delegate the task to OpenCV. That's how it is supposed to be used.
I'm currently doing my Multimedia assignment where I have to create a new video using one video as a foreground and another as a background. OpenCV allows me to do just that: extracting images from each frame in video, processing them and putting the results back into a video format. However, OpenCV is only a computer vision library. Is there a library that allows me to do the same for sound? I'd like to extract sound (music, actually) from a video I'm using and put it into the final video.
You can use libavcodec library used in FFmpeg.
Try Tuna Audio Extracter (http://github.com/tuna74/TunaAudioExtracter). You can use the extracter part from that program.