USB camera encoded data stream
up vote
2
down vote
favorite
Currently, I am working on a streaming project. I need to grab frames from USB camera and send them over TCP.
To open USB camera video stream I'm using cv::VideoCapture
. This allows me to read already decoded frames. According to this question I understood that there is no way to get encoded frame data using cv::VideoCapture
and I need to encode each frame again and send it whatever I need using cv::imencode
. The problem is that I can encode frames to some specific format listed here, and, in case, I use either .jpg or .png the file size still quite big and on receiving side frame rate very poor.
My question is: Is there any way to get mjpeg or h264 encoded data directly
or maybe you can suggest a better way to encode frames.
OpenCV 3.4.3, camera RICOH THETA V, language C++.
My code:
void Streamer::start()
cv::Mat img;
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));
if (!cap.isOpened())
throw std::invalid_argument("No device found.");
std::vector<int> format_params;
format_params.push_back(CV_LOAD_IMAGE_COLOR);
format_params.push_back(CV_IMWRITE_PNG_STRATEGY);
for (;;)
cap.read(img);
cv::imencode(".png", img, buffer_, format_params);
std::string strbuf(buffer_.begin(), buffer_.end());
server_->sendString(socket, strbuf);
cap.release();
c++ opencv stream encode
add a comment |
up vote
2
down vote
favorite
Currently, I am working on a streaming project. I need to grab frames from USB camera and send them over TCP.
To open USB camera video stream I'm using cv::VideoCapture
. This allows me to read already decoded frames. According to this question I understood that there is no way to get encoded frame data using cv::VideoCapture
and I need to encode each frame again and send it whatever I need using cv::imencode
. The problem is that I can encode frames to some specific format listed here, and, in case, I use either .jpg or .png the file size still quite big and on receiving side frame rate very poor.
My question is: Is there any way to get mjpeg or h264 encoded data directly
or maybe you can suggest a better way to encode frames.
OpenCV 3.4.3, camera RICOH THETA V, language C++.
My code:
void Streamer::start()
cv::Mat img;
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));
if (!cap.isOpened())
throw std::invalid_argument("No device found.");
std::vector<int> format_params;
format_params.push_back(CV_LOAD_IMAGE_COLOR);
format_params.push_back(CV_IMWRITE_PNG_STRATEGY);
for (;;)
cap.read(img);
cv::imencode(".png", img, buffer_, format_params);
std::string strbuf(buffer_.begin(), buffer_.end());
server_->sendString(socket, strbuf);
cap.release();
c++ opencv stream encode
1
I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
– api55
Nov 7 at 8:48
@api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
– Yevhenii Veretennikov
Nov 9 at 6:41
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Currently, I am working on a streaming project. I need to grab frames from USB camera and send them over TCP.
To open USB camera video stream I'm using cv::VideoCapture
. This allows me to read already decoded frames. According to this question I understood that there is no way to get encoded frame data using cv::VideoCapture
and I need to encode each frame again and send it whatever I need using cv::imencode
. The problem is that I can encode frames to some specific format listed here, and, in case, I use either .jpg or .png the file size still quite big and on receiving side frame rate very poor.
My question is: Is there any way to get mjpeg or h264 encoded data directly
or maybe you can suggest a better way to encode frames.
OpenCV 3.4.3, camera RICOH THETA V, language C++.
My code:
void Streamer::start()
cv::Mat img;
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));
if (!cap.isOpened())
throw std::invalid_argument("No device found.");
std::vector<int> format_params;
format_params.push_back(CV_LOAD_IMAGE_COLOR);
format_params.push_back(CV_IMWRITE_PNG_STRATEGY);
for (;;)
cap.read(img);
cv::imencode(".png", img, buffer_, format_params);
std::string strbuf(buffer_.begin(), buffer_.end());
server_->sendString(socket, strbuf);
cap.release();
c++ opencv stream encode
Currently, I am working on a streaming project. I need to grab frames from USB camera and send them over TCP.
To open USB camera video stream I'm using cv::VideoCapture
. This allows me to read already decoded frames. According to this question I understood that there is no way to get encoded frame data using cv::VideoCapture
and I need to encode each frame again and send it whatever I need using cv::imencode
. The problem is that I can encode frames to some specific format listed here, and, in case, I use either .jpg or .png the file size still quite big and on receiving side frame rate very poor.
My question is: Is there any way to get mjpeg or h264 encoded data directly
or maybe you can suggest a better way to encode frames.
OpenCV 3.4.3, camera RICOH THETA V, language C++.
My code:
void Streamer::start()
cv::Mat img;
cv::VideoCapture cap(0);
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('H', '2', '6', '4'));
if (!cap.isOpened())
throw std::invalid_argument("No device found.");
std::vector<int> format_params;
format_params.push_back(CV_LOAD_IMAGE_COLOR);
format_params.push_back(CV_IMWRITE_PNG_STRATEGY);
for (;;)
cap.read(img);
cv::imencode(".png", img, buffer_, format_params);
std::string strbuf(buffer_.begin(), buffer_.end());
server_->sendString(socket, strbuf);
cap.release();
c++ opencv stream encode
c++ opencv stream encode
edited Nov 11 at 12:34
Zoe
10.7k73575
10.7k73575
asked Nov 7 at 6:31
Yevhenii Veretennikov
1113
1113
1
I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
– api55
Nov 7 at 8:48
@api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
– Yevhenii Veretennikov
Nov 9 at 6:41
add a comment |
1
I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
– api55
Nov 7 at 8:48
@api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
– Yevhenii Veretennikov
Nov 9 at 6:41
1
1
I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
– api55
Nov 7 at 8:48
I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
– api55
Nov 7 at 8:48
@api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
– Yevhenii Veretennikov
Nov 9 at 6:41
@api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
– Yevhenii Veretennikov
Nov 9 at 6:41
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184564%2fusb-camera-encoded-data-stream%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I think that if you are not going to do any kind of image processing and only stream a video... maybe it is better to use a library/app that does that directly... for example gstreamer or ffmpeg using something like rtsp which in the client side you can connect using videocapture of OpenCV
– api55
Nov 7 at 8:48
@api55 Thanks for your reply. Yes, in my case I am not doing any image processing. I have now tried to use ffmpeg to stream video using rtp but could not make it work. It would be great if I could use ffmpeg instead.
– Yevhenii Veretennikov
Nov 9 at 6:41