bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.53k stars 1.58k forks source link

Some problem with these code, sometime recorder may blocked? #2180

Open swinghu opened 8 months ago

swinghu commented 8 months ago
        FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(localPath, width, height);
        recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
        recorder.setFrameRate(frame);
        recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
        recorder.setFormat("mp4");
        recorder.start();

        Future<Void> future =closeTaskExecutor.submit(()->{
                int index = imgMap.firstKey();
                int maxIndex = imgMap.lastKey();
                try {
                    for(int i =0; i<timeSlash; i++) {
                        for(int j =0; j<frame; j++) {
                            sb.append(" " + index);
                            File file = imgMap.get(index);
                            if (null == file){
                                continue;
                            }
                            recorder.record(imgFrameMap2.get(index).get());
                            index++;
                            if (index > maxIndex) {
                                break;
                            }
                        }
                    }
                }catch (Exception e) {
                    LOGGER.error("e, ", e);
                }finally {
                    LOGGER.info("future release record!");
                    try {
                        recorder.stop();
                        recorder.release();
                    }catch (Exception e){
                        LOGGER.warn("e ", e);
                    }
                }
                return null;
            });

most of the time run very well record finished in 300ms , but when request press goes up, some times it record slowly , may cost more than 20s, some problem with the implemention? May javacv + ffmpeg some component would be blocked?

version info : org.bytedeco:javacv-platform:1.5.5 org.bytedeco:ffmpeg:4.3.2-1.5.5:linux-x86_64