Transparent video and libvlc
Posted: 05 Jan 2019 18:00
Hello!
I am trying to play transparent video using libvlc and libvlcpp.
Video is encoded from transparent PNG files using ffmpeg. Video format is VP9.
Encoding options are: ffmpeg -framerate 30 -f image2 -i %04d.png -c:v libvpx-vp9 -pix_fmt yuva420p transparent.webm
I checked with Chromium-based browser that the video contains an alpha channel.
Here is some code of playback:
Saved buffer looks like this:
It is looks like RGBA but with Alpha channel set to FF for every pixel.
I can even open this file as raw in image editor and it looks correct but with black background instead of transparent.
The question is how can I get data from libvlc with proper Alpha channel.
application output for --verbose=2: https://pastebin.com/RfJEeXYs
I am trying to play transparent video using libvlc and libvlcpp.
Video is encoded from transparent PNG files using ffmpeg. Video format is VP9.
Encoding options are: ffmpeg -framerate 30 -f image2 -i %04d.png -c:v libvpx-vp9 -pix_fmt yuva420p transparent.webm
I checked with Chromium-based browser that the video contains an alpha channel.
Here is some code of playback:
Code: Select all
...
media_ = VLC::Media(instance_, "transparent.webm", VLC::Media::FromPath);
mp_.setMedia(media_);
mp_.setVideoFormat("RGBA", 512, 512, 512 * 4); //setting video format to RGBA. Video size is 512×512; pitch is 4 bytes per pixel
mp_.setVideoCallbacks([this](void** pBuffer) -> void* {
//std::cout << "Lock callback" << std::endl;
*pBuffer = buffer_na_;
return NULL;
}, [](void*, void*const*) {
//std::cout << "Unlock callback" << std::endl;
}, [this](void*) {
//std::cout << "Display callback" << std::endl;
std::ofstream buffer_file; //Let's save buffer to file and see what is inside
buffer_file.open("buffer.raw", std::ios::binary | std::ios::out | std::ios::trunc);
buffer_file.write(reinterpret_cast<const char*>(buffer_na_), BUF_SIZE);
buffer_file.close();
});
mp_.play();
...
Code: Select all
...
00 00 00 FF 00 00 00 FF 00 00 00 FF 00 00 00 FF
...
AF 7A 33 FF AF 7A 33 FF B0 75 33 FF AC 70 2E FF
...
I can even open this file as raw in image editor and it looks correct but with black background instead of transparent.
The question is how can I get data from libvlc with proper Alpha channel.
application output for --verbose=2: https://pastebin.com/RfJEeXYs