CodePudding user response:
FFmpegFrameGrabber grabber=null;Grabber=FFmpegFrameGrabber. CreateDefault (rtspUrl);
Int width=aiVideoConfig. GetImageWidth (), height=aiVideoConfig. GetImageHeight ();
//using TCP, or you will lost package serious
Grabber. SetOption (" rtsp_transport ", "TCP");
Grabber. SetOption (" framerate ", "25");
//grabber. SetFormat (" gdigrab ");
Grabber. SetImageWidth (width);
Grabber. SetImageHeight (height);
Grabber. SetVideoBitrate (3000000);
Grabber. SetVideoCodec (AV_CODEC_ID_H265);
//grabber. SetVideoOption (" vcodec ", "copy");
Grabber. SetOption (TimeoutOption. RW_TIMEOUT. GetKey (), "10000000");
//increase the timeout parameter
Grabber. SetOption (" stimoout ", "5 * 1000 * 1000");
/* grabber. SetOption (" buffer_size ", "1024000");
Stimeout grabber. SetOption (" ", "8000000"); */
//pull flow
Grabber. Start ();
Frame Frame=null;
ByteArrayOutputStream stream=null;
Opencv_core. IplImage img=null;
OpenCVFrameConverter converter=new OpenCVFrameConverter. ToIplImage ();
While (true) {
Frame grabber=. GrabFrame ();
If (frame) image==null) {
continue;
}
BufferedImage image=null;
Image=java2DFrameConverter. GetBufferedImage (frame);
If (frame==null) {
continue;
}
The stream=new ByteArrayOutputStream ();
//generated UUID
String uuid=uuid. RandomUUID (). The toString (). The toUpperCase ();
ImageIO. Write (image, "JPG", the new File (" d:/images/" + + ". JPG "uuid));
}