bytedeco/javacv

Could not get pixel format for color format 'bgra' range 'unknown'.

Open

#2,209 opened on Mar 26, 2024

View on GitHub
 (9 comments) (0 reactions) (0 assignees)Java (1,583 forks)batch import
bughelp wantedquestion

Repository metrics

Stars
 (6,985 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

Hello!

I'm trying to record an HEVC video with transparency/alpha channel.

I tried recording with VP9 & YUVA420P, it works fine, but with HEVC & BGRA, it leads to the error below:

[hevc_videotoolbox @ 0x15182bc50] Could not get pixel format for color format 'bgra' range 'unknown'.
Exception in thread "main" org.bytedeco.javacv.FFmpegFrameRecorder$Exception: avcodec_open2() error -22: Could not open video codec. (For more details, make sure FFmpegLogCallback.set() has been called.)
        at org.bytedeco.javacv.FFmpegFrameRecorder.startUnsafe(FFmpegFrameRecorder.java:791)
        at org.bytedeco.javacv.FFmpegFrameRecorder.start(FFmpegFrameRecorder.java:437)
        at louiscad.ComposeToVideoKt.recordComposable-vZmvyCw(ComposeToVideo.kt:100)

Here's what I'm setting in the code prior to calling start() on the FFmpegFrameRecorder:

frameRecorder.also {
    it.format = "mov"
    it.videoCodec = avcodec.AV_CODEC_ID_HEVC
    it.pixelFormat = avutil.AV_PIX_FMT_BGRA
}

Am I missing something? Is JavaCv failing to set something that ffmpeg needs?

With the following command, I'm able to convert my VP9 video to HEVC, but this extra step is very costly when I need to record long videos.

ffmpeg -c:v libvpx-vp9 -i input.webm -c:v hevc_videotoolbox -allow_sw 1 -alpha_quality 0.75 -vtag hvc1 -movflags +faststart output1.mov

I hope someone can help. Thank you in advance, and have a nice day!

Contributor guide