OpenCV - how to read video from buffer? - c++

Reading video from disk is simple - CvCapture* capture = cvCreateFileCapture(argv[1]);, but I need to read mp4 file which is already in std::string VideoBuffer.
How to do that?

Related

Why my App cannot decode the RTSP stream?

I use live555 to receive RTP video frame (frame encoded in H264). I use Live555 open my local .sdp file to receive frame data. I just saw DummySink::afterGettingFrame was called ceaselessly。 if fReceiveBuffer in DummySink is correct, Why FFMPEG cannot decode the frame? My code is wrong?
Here is my Code Snippet:
http://paste.ubuntu.com/12529740/
the function avcodec_decode_video2 is always return failed , its value less than zero
fReceiveBuffer is present one video frame?
Oh, Here is my FFMPEG init code need to open related video decoder:
http://paste.ubuntu.com/12529760/
I read the document related H264 again, I found out that I-frame(IDR) need SPS/PPS separated by 0x00000001 insert into the header and decoder have a capacity to decode the frame correctly. Here is a related solution
FFmpeg can't decode H264 stream/frame data
Decoding h264 frames from RTP stream
and now, My App works fine, it can decode the frame and convert it to OSD Image for displaying to screen .

How to detect motion from already store webm video in c++

I want to detect motion in already existing video, The video is stored in the webm format. I have seen some demo of opencv but those samples is capturing the motion of the live webcam streaming.
Is there any library or api which capture the motion of the webm video file in c++?
please help me.
If you have the code that run with the webcam input you only have to change the input type to accept the video file as input.
Basically, you can accomplish it using the VideoCapture object.
cv::VideoCapture cap("path/for/file.fileextension")
and then, putting this input into a Mat datatype (separating by frame):
Mat frame;
cap >> frame;

Size in kbytes of AVI of video in C++/OpenCV

Is there a way to know the size of an avi video in OpenCV? There are some videos that are blank and instead of processing them I want to get rid of them by comparing their size to a threshold. For example, if the size of the video is 200 kB or less, then I skip processing that video.
Update:
CvCapture *capture = cvCreateFileCapture(path);
IplImage *img = cvQueryFrame( capture );
All videos have the same number of frames but some videos have all blank frames.
You can get number of frames by getting CV_CAP_PROP_FRAME_COUNT video property using GetCaptureProperty:
CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.
To get size of file (video) there is another API - depends on your system (WinAPI, POSIX etc).
For example on Windows it's GetFileSizeEx() function.
Also look at this SO discussion.
If you want to get the actual file size, you will have to use fopen() or stat as OpenCV doesn't store this information in a cvCapture object. However, you can detect blank videos like so:
CvCapture *capture = cvCaptureFromAVI( argv[1] );
int numFrames = (int) cvGetCaptureProperty(&capture, CV_CAP_PROP_FRAME_COUNT);
Then just decide if it's blank based on the number of frames.
Relevant Documentation:
http://opencv.willowgarage.com/documentation/reading_and_writing_images_and_video.html?highlight=cvcapture#getcaptureproperty
If the file size is different for the blank videos, but the files have the same number of frames, it's due to video compression via keyframing. That means the best way to detect blank frames is via getting the file size, which is outside of the scope of OpenCV and can easily be accomplished using plain C/C++:
#include <sys/stat.h>
...
struct stat st;
stat(avi_filename, &st);
size = st.st_size;

Reading frames from CIF video in OpenCV 2.4.2

The problem is the following:
There is a CIF video file that is supposed to be processed by the OpenCV.
Unfortunately, I am not able to read frames from this video. The following code
cv::VideoCapture cap = cv::VideoCapture("foreman.cif");
if(!cap.isOpened()) {
std::cout << "Open file error" << std::endl;
return -1;
}
gives Open file error in console.
Is there any way to grab frames from CIF video using OpenCV?
I don't think openCV can read raw YUV streams directly.
You can use memcoder to convert it to an avi, compressed or not.
Or you can use regular c/c++ to read the data blocks, copy them into an image and use cvCvtColor() to convert YUV->BGR

Reading video stream and writing it to a buffer

I'm writing a program in C++ using DirectShow API in order to accelerate video encoding part. This program should read video stream from Video Capture Card, and pass it to the encoder, without intermediate raw data file which is usually passed.
But encoder is not my software, in fact, it was bought.
This encoder used to accept a raw data file with it's details and give an encoded file as an output. So I've decided to read video stream from Video Capture Card, save it to some buffer, and when the size of a buffer is appropriate (appropriate is specified in encoder) pass it to encoder.
But I'm new to DirectShow as well as to a whole multimedia programming, so what I'm asking is an advise about a function to use to read a stream, or about total solution, or any useful links.
Thanks in Advance
EDIT 1: What I meant by Accelerate is to read video stream in encoder directly, instead of creating intermediate YUV file and making encoder to read YUV file.