Closed wlkfec closed 2 years ago
public static void createGif(String dest) throws Exception{ FFmpegLogCallback.set(); FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("0"); grabber.setFormat("avfoundation"); grabber.start(); FFmpegFrameRecorder recorder =new FFmpegFrameRecorder(dest + ".gif", 500, 500, 0); // AV_PIX_FMT_RGB4_BYTE recorder.setPixelFormat(AV_PIX_FMT_RGB4_BYTE); recorder.setVideoCodec(AV_CODEC_ID_GIF); recorder.start(); double frameRate = grabber.getFrameRate(); AtomicInteger count = new AtomicInteger(0); do { Frame frame = grabber.grab(); recorder.record(frame); } while (count.incrementAndGet() != frameRate * 5); recorder.stop(); grabber.stop(); recorder.release(); grabber.release(); }
There is a bug in JavaCV 1.5.7. Please call FFmpegFrameGrabber.tryLoad() before start().
Duplicate of #1756
It works, but when I call grab.grab, I find that only the first few frames have data, and then all the frames are empty, and the camera is not turned off, is it still missing the necessary settings?
That's another issue that was fixed in commit https://github.com/bytedeco/javacv/commit/8d75c0a33c9a105c7da08e754179ac785bf6f788, see issue #1784. Please give it a try with the snapshots: http://bytedeco.org/builds/
on mac : org.bytedeco.javacv.FFmpegFrameGrabber$Exception: av_find_input_format() error: Could not find input format "avfoundation".