c++ - Display multiple OpenCv IplImages over VLC Video Output -
i'm trying send multiple frames (previsously taken actual video file) via socket (c++) play vlc.
i've searched lot , didn't find solution. hope can me.
so, code:
#include <stdio.h> #include <stdlib.h> #include <direct.h> #include <iostream> #include <winsock2.h> #include <windows.h> #include <iostream> #include <string.h> #include <time.h> #include <errno.h> //#include <fstream> #include <opencv2/core/core.hpp> // basic opencv structures (cv::mat, scalar) #include <opencv2/highgui/highgui.hpp> // opencv window i/o using namespace std; #define port 6666 #define group "127.0.0.1" //#define inaddr_any int serversock, clientsock; int is_data_ready = 0; struct sockaddr_in server, client; int bytes = 0; int count = 0; int addrlen = sizeof(server); int clielen = sizeof(client); int opt = 1; //methods void quit(char* msg, int retval); void quit(char* msg, int retval) { if (retval == 0) { fprintf(stdout, (msg == null ? "" : msg)); fprintf(stdout, "\n"); } else { fprintf(stderr, (msg == null ? "" : msg)); fprintf(stderr, "\n"); } if (clientsock) closesocket(clientsock); if (serversock) closesocket(serversock); exit(retval); } int main() { // initialize winsock wsadata wsadata; int iresult = wsastartup(makeword(2, 2), &wsadata); if (iresult != no_error) { wprintf(l"wsastartup failed error: %ld\n", iresult); return 1; } //char *imgname; //path e nome das imagens int i=0; char filename[50]; iplimage *img = cvloadimage(<path\\imgname.jpg); //1ÂȘ imagem como referĂȘncia //iplimage *img2; cvsize size; size.width = img->width; size.height = img->height; /* setup server's ip , port */ memset(&server,0,sizeof(server)); server.sin_family = af_inet; server.sin_port = htons(6666/*port*/); server.sin_addr.s_addr = inet_addr("127.0.0.1"/*group*/); //server.sin_addr.s_addr = inaddr_any; socket serversock = socket(af_inet, sock_stream, 0); //socket t; //t = socket(af_inet, sock_stream,null); if (serversock < 0) { // or == -1 wprintf(l"socket failed error: %ld\n", wsagetlasterror()); wsacleanup(); //quit("socket() failed", 1); } /* bind socket */ int b = bind(serversock, (const sockaddr*)&server, sizeof(server)); if (b < 0) { wprintf(l"socket failed error: %ld\n", wsagetlasterror()); wsacleanup(); quit("bind() failed", 1); } /* wait connection */ int l = listen(serversock, 5); if(l < 0) { quit("listen() failed.", 1); } setsockopt(serversock, sol_socket, so_keepalive, (const char*) &opt, sizeof(int)); while(img != null) { sprintf(filename, "filter\\frame_%d.jpg", i); img = cvloadimage(filename); if (img) { int imgsize = (int) &size; sendto(serversock, img->imagedata, imgsize, 0, (const struct sockaddr*)&server, addrlen); if(bytes < 0) { //error wprintf(l"socket failed error: %ld\n", wsagetlasterror()); wsacleanup(); quit("sendto failed", 1); } //end socket stuff cout << "image sent!" << endl; } i++; } cvreleaseimage(&img); }
ant open vlc , set receive network stream on next address: rtp://127.0.0.1:6666
.
the application ends , vlc doesn't show anything.
thanks lot!
first,
int sendto( _in_ socket s, _in_ const char *buf, _in_ int len, _in_ int flags, _in_ const struct sockaddr *to, _in_ int tolen );
sendto
third argument « length, in bytes, of data pointed buf parameter »
, not address of opencv size object. that's not surprising if program crashes. imgsize
should img.imagesize
.
secondly, doubt vlc able decode stream composed of several raw image data, i'm pretty sure needs streaming protocol around it.
first need use transport protocol streaming protocol (http, rtp, etc.). need build actual video stream (mjpeg, mpeg4, etc.)
your server relatively stream mjpeg on http, other protocol, should use external library.
you should search how implementing video streaming server in c++, see thread : how started implementing video streaming server in c/c++?
Comments
Post a Comment