Extract frames from stream video

Khi connect internet thi em extract frame thanh cong. Nhung khi disconnect internet thi frame no data. Anh chi giup e : lam nhu the nao de khi reconnect thi extract frame duoc ?

#include "opencv2/opencv.hpp"
#include<iostream>
#include<string>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
using namespace cv;
void extractFromStream(VideoCapture cap)
{
	 int id=0;
	 while(1)
	{
		Mat img;
		bool bSuccess = cap.read(img);

		if(!bSuccess)
		{
			
			cout<<"No frame\n";
			waitKey();

		}
		id++;

		char filename[100];
		strcpy(filename, "/home/dieuninh/Desktop/a/i_");
		char frame_id[30];
		sprintf(frame_id,"%d",id);
		strcat(filename, frame_id);
		strcat(filename, ".jpg");
		cout<<endl<<filename<<endl;
		imwrite( filename, img );
		if(cv::waitKey(1) ==27) break;

	}
}
int main() {
	string stream="http://4co2.vp9.tv/chn/VTT4/v.m3u8";
	VideoCapture cap;
	cap.open(stream);
	bool success=cap.isOpened();
	if( !success){
			cout << "Cannot open the video file" << endl;
			return -1;
		}
	cout<<"OKKKKKKKKKKKK";
	
	extractFromStream(cap);
		waitKey(0);
}

Thay vì return khi ko có internet, bạn chỉ in ra thông báo thôi, và khi nào có internet bạn lại gọi hàm extractFromStream là được.

yêu cầu là khi reconnect thì phải tiếp tục extract frame next của frame trước đó. nhưng trong khoảng tgian disconnect thì stream đã chạy qua rất nhiều frames mới r ạ.

Thế thì đâu có được nữa bạn, vì stream là liên tục, đâu phải mất mạng là nó cũng dừng đâu, trừ khi bạn xử lý theo kiểu của Sopcast, tức là chấp nhận ko phải live stream mà có 1 độ trễ để lưu lại stream trong khoảng thời gian trễ đó, phòng trường hợp khi mất mạng bạn sẽ lấy được một số frame sau, nhưng nói chung nếu mất mạng quá lâu cũng ko có cách nào lấy đc toàn bộ cả.

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?