I just want to show the IP camera video without sound, but this camera plays video with sound, and I get [mp3 # 0x107808800] Header missing in the console. How do I play without sound? I'm using vstarcam-30s. Here is my code:
int main (int argc, char *argv[])
{
VideoCapture vcap;
Mat image;
string videoStreamAddress =
"rtsp://[IPADDRESS]/profile2/media.smp";
if (!vcap.open(videoStreamAddress)) {
cout << "Error opening video stream or file" << endl;
return -1;
}
for(;;) {
if(!vcap.read(image)) {
cout << "No frame" << endl;
waitKey();
}
imshow("Output Window", image);
if(waitKey(1) >= 0) break;
}
return 0;
}
Related
I have written a program to display a stored video file using opencv. I attached the code below. I am not getting any errors while building it but no output is displayed.
int main(int argc, char *argv[])
{
if (argc <= 1)
{
printf("Usage: %s video\n", argv[0]);
return -1;
}
VideoCapture capture(argv[1]);
namedWindow("display",cv::WINDOW_AUTOSIZE);
capture.set(cv::CAP_PROP_FRAME_WIDTH, 640);
capture.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
if(!capture.isOpened())
{
printf("Failed to open the video\n");
return -1;
}
int i;
for(i=0;i<390;i++)
{
Mat frame;
capture >> frame; // get a new frame from camera
cout << "frame =" << endl << " " << frame << endl << endl;
imshow("display",frame);
}
}
I included the cout line at the end to check if the frame is getting any value or not. So a got a number of values in a matrix, but the video window is not appearing.
You have to add a very small delay after imshow by using waitKey.
imshow("display",frame);
waitKey(10); //Wait 10 milliseconds before showing next frame.
i working in a stereo camera project i have two cameras 5megapixels in every one i connected it with my laptop and run my code but when i run it i get this error libv4l2: error turning on stream: No space left on device
im linux os that's my c++ opencv code there are any ideas how to fix it i tried others codes i found it in network but still give me the same error
#include <opencv2/opencv.hpp>
int main()
{
cv::VideoCapture cap1(1);
cv::VideoCapture cap2(2);
if(!cap1.isOpened())
{
std::cout << "Cannot open the video cam [1]" << std::endl;
return -1;
}
if(!cap2.isOpened())
{
std::cout << "Cannot open the video cam [2]" << std::endl;
return -1;
}
cap1.set(CV_CAP_PROP_FPS, 15);
cap2.set(CV_CAP_PROP_FPS, 15);
// Values taken from output of Version 1 and used to setup the exact same parameters with the exact same values!
cap1.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap1.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
cap2.set(CV_CAP_PROP_FRAME_WIDTH, 640);
cap2.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
cv::namedWindow("cam[1]",CV_WINDOW_AUTOSIZE);
cv::namedWindow("cam[2]",CV_WINDOW_AUTOSIZE);
while(1)
{
cv::Mat frame1, frame2;
bool bSuccess1 = cap1.read(frame1);
bool bSuccess2 = cap2.read(frame2);
if (!bSuccess1)
{
std::cout << "Cannot read a frame from video stream [1]" << std::endl;
break;
}
if (!bSuccess2)
{
std::cout << "Cannot read a frame from video stream [2]" << std::endl;
break;
}
cv::imshow("cam[1]", frame1);
cv::imshow("cam[2]", frame2);
if(cv::waitKey(30) == 27)
{
std::cout << "ESC key is pressed by user" << std::endl;
break;
}
}
return 0;
}
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap(0); // open the video camera no. 0
if (!cap.isOpened()) // if not success, exit program
{
cout << "ERROR: Cannot open the video file" << endl;
return -1;
}
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << "Frame Size = " << dWidth << "x" << dHeight << endl;
Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));
VideoWriter oVideoWriter ("D:/MyVideo.avi", CV_FOURCC('P','I','M','1'), 20, frameSize, true); //initialize the VideoWriter object
if ( !oVideoWriter.isOpened() ) //if not initialize the VideoWriter successfully, exit the program
{
cout << "ERROR: Failed to write the video" << endl;
return -1;
}
while (1)
{
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "ERROR: Cannot read a frame from video file" << endl;
break;
}
oVideoWriter.write(frame); //writer the frame into the file
imshow("MyVideo", frame); //show the frame in "MyVideo" window
if (waitKey(10) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}
I am developing this project using Visual Studio 2012 express and opencv_2.4.9 and windows 7 x64.
But, this code is not working.
Just write out this message "ERROR: Failed to write the video".
Use try, catch to see if you can get a more detailed error message.
One thing I remember when writing videos is that you need to verify you have the codecs installed and in the correct directory or added as a PATH environment variable.
opencv_ffmpeg.dll was the issue for me, and making sure it was in the correct directory and being renamed to opencv_ffmpeg249.dll
I am trying to get full HD processing using Qt and OpenCV, I can only get 480p at the moment, as you can see in the code I have got the width and height of the frame. I have also tried setting the size of the using cvSize(1920 x 1080) but it doesn't change the resolution.
Many thanks for any help!
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
VideoCapture cap(1); //capture webcam
if (!cap.isOpened()) //if not successful then exit
{
qDebug() << "Cannot open webcam";
return -1;
}
namedWindow("Camera feed", CV_WINDOW_AUTOSIZE); //create window
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get width of frames of video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get height of frames of video
Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));
qDebug() << "Frame size = " << dWidth << "x" << dHeight << endl;
VideoWriter oVideoWriter("video.avi", CV_FOURCC('M','P','E','G'), 20, frameSize);
if(!oVideoWriter.isOpened())
{
qDebug() << "ERROR: Failed to write the video" << endl;
return -1;
}
while(1)
{
Mat frame;
bool bSuccess = cap.read(frame); //read a new frame from video
if(!bSuccess) //if unsuccessful, break loop
{
qDebug() << "Cannot read frame from video file" << endl;
break;
}
oVideoWriter.write(frame); //write the frame into the file
imshow("Camera feed", frame); //show the frame in "Live Feed" window
qDebug() << "Recording" << endl;
if (waitKey(30) == 27)
{
qDebug() << "Esc key is pressed by user" << endl;
break;
}
}
return 0;
}
Have you tried setting forcing your capture to HD by setting the properties:
cap.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);
If so, check if this resolution is supported by the device in other programs like guvcview or v4l2-ctl. If you have the last one installed you can check the supported modes with:
v4l2-ctl --list-formats
I have written a program to display a stored video file using opencv. I attached the code below. I am not getting any errors while building it but no output is displayed.
int main(int argc, char *argv[])
{
if (argc <= 1)
{
printf("Usage: %s video\n", argv[0]);
return -1;
}
VideoCapture capture(argv[1]);
namedWindow("display",cv::WINDOW_AUTOSIZE);
capture.set(cv::CAP_PROP_FRAME_WIDTH, 640);
capture.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
if(!capture.isOpened())
{
printf("Failed to open the video\n");
return -1;
}
int i;
for(i=0;i<390;i++)
{
Mat frame;
capture >> frame; // get a new frame from camera
cout << "frame =" << endl << " " << frame << endl << endl;
imshow("display",frame);
}
}
I included the cout line at the end to check if the frame is getting any value or not. So a got a number of values in a matrix, but the video window is not appearing.
You have to add a very small delay after imshow by using waitKey.
imshow("display",frame);
waitKey(10); //Wait 10 milliseconds before showing next frame.