bytedeco / javacv

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

Can't use vp8 in my javafx application. #1769

Closed sumit33 closed 2 years ago

sumit33 commented 2 years ago

I used h264 encoding before that worked fine. But now I want to use vp8 or vp9..I just call "libvpx" library..but it shows error..

av_guess_format() error: Could not guess output format for "" and vp8 format.

This is my code.

    grabber = new FFmpegFrameGrabber("desktop");
    grabber.setFormat("gdigrab");
    grabber.setImageWidth((int) rectangleFullScreen.getWidth());
    grabber.setImageHeight((int) rectangleFullScreen.getHeight());
    grabber.setPixelFormat(AV_PIX_FMT_YUV420P);
    grabberPixelFormat = grabber.getPixelFormat();
    grabber.setVideoCodec(AV_CODEC_ID_VP8);

    recorder = new FFmpegFrameRecorder(recorderOutput, roi.width, roi.height, 0);
    recorder.setFrameRate(fps);
    recorder.setFormat("vp8");
    recorder.setVideoCodecName("libvpx");
    recorder.setVideoOption("profile", "baseline");
    recorder.setVideoOption("tune", "zerolatency");
    recorder.setVideoOption("preset", "ultrafast");
    recorder.setVideoOption("maxrate", String.valueOf(1024 * 1024 * maxrateMbits));
    recorder.setVideoOption("bufsize", String.valueOf(1024 * 1024 * maxrateMbits));
    recorder.setVideoOption("crf", String.valueOf(crf));
    recorder.setVideoOption("g", String.valueOf(fps * 10));

    grabber.start();
    recorder.start();
saudet commented 2 years ago

I don't think "vp8" is a valid format name. Please check the docs.

sumit33 commented 2 years ago

@saudet yes,its not valid. I changed it with a valid format. But still it shows error. org.bytedeco.javacv.FrameRecorder$Exception: avcodec_open2() error -22: Could not open video codec.

saudet commented 2 years ago

There's something the codec doesn't like about your settings. Check the log for more information.

sumit33 commented 2 years ago

@saudet Sorry for the late update. I found out my problem. The jar I used for my application is not enabled with "libvpx" and also facing problems to enabled it. How can I enable "libvpx" in the jar on windows? Or can I get any jar where "libvpx" is already enabled? I'm totally new in this field. Please Help.

saudet commented 2 years ago

Please upgrade to JavaCV 1.5.7.

sumit33 commented 2 years ago

@saudet solved. The problem is for setting the wrong preset and tune for libvpx. Now it's working. What I get after doing that is an encoded byte buffer. How to decode it for saving and playing?

saudet commented 2 years ago

You can save to a file, and read back with FFmpegFrameGrabber.