This is a C++ project. I have a remote server with an ip camera connected to the network. My cLient is connected to the server over a ssh channel. I want ffmpeg to stream raw h264 frames to the client to display a video on the application window. My problem is that ffmpeg only delivers one single frame to be displyed.
Here is my code:
retVal = ssh_channel_request_exec(channel,
"ffmpeg -stream_loop -1 -rtsp_transport tcp -i rtsp://localhost:554/101 -c copy -f h264 pipe:");
if (retVal != SSH_OK) {
sprintf_s(buffer, "Error: %s\n", ssh_get_error(session));
SendMessage(hStatus, SB_SETTEXT, 3, (LPARAM)buffer);
return 0;
}
size_t memsize = 1024 * 100;
uint8_t* data = (uint8_t*)malloc(memsize);
size_t nbytes = ssh_channel_read(channel, data, memsize, 0);
while (nbytes > 0) {
DataParser(data, nbytes);
nbytes = ssh_channel_read(channel, data, sizeof(memsize), 0);
}
First ssh_channel_read function can read one frame into the data buffer. But the same function in the loop only reads 8 bytes of garbage. Can someone please explain what I have missed.
I just spotted the typo: You pass sizeof(memsize)
to ssh_channel_read
in the loop. That is always 8. You meant to pass memsize
instead.