Home > Back-end >  Want to ask ffmpeg decoding frame gray screen problem
Want to ask ffmpeg decoding frame gray screen problem

Time:09-23

Want to ask next javacv or ffmpeg used old buddy, I here back to the RTSP remote monitoring by others address, according to the RTSP video streaming using javacv frame decoding, but the picture of the extracted occasionally there will be a grey screen or screen problem, to TCP or so, this problem is studied for a long time didn't find a solution next javacv, please is there any way I can determine whether every frame image complete method

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));
}
  • Related