<div dir="ltr">Hi,<div><br></div><div>I'm trying to decode and convert a VP8 video with an alpha channel to a 32-bit RGBA for rendering in my application. The decoding with libvpx works fine, but I can't get the alpha channel through into the RGBA. Am I doing something wrong with libswscale?</div><div><br></div><div>Thanks in advance!</div><div>Craig</div><div><br></div><div><br></div><div>Here's the initialization code:</div><div><font face="monospace">    // Open video file<br>    if(avformat_open_input(&_formatCtx, _videoFile.toUtf8().constData(), nullptr, nullptr) != 0)<br>      return false; // Couldn't open file<br><br>    // Retrieve stream information<br>    if(avformat_find_stream_info(_formatCtx, nullptr) < 0)<br>      return false; // Couldn't find stream information<br><br>    // Find the first video stream<br>    for(int i = 0; i < _formatCtx->nb_streams; i++)<br>    {<br>        if(_formatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)<br>        {<br>            _videoStream=i;<br>            break;<br>        }<br>    }<br><br>    if(_videoStream == -1)<br>      return false; // Didn't find a video stream<br><br>    // Find the decoder for the video stream<br>    if(_formatCtx->streams[_videoStream]->codecpar->codec_id == AV_CODEC_ID_VP8)<br>        _codec = avcodec_find_decoder_by_name("libvpx");<br>    else if(_formatCtx->streams[_videoStream]->codecpar->codec_id == AV_CODEC_ID_VP9)<br>        _codec = avcodec_find_decoder_by_name("libvpx-vp9");<br>    else<br>        _codec = avcodec_find_decoder(_formatCtx->streams[_videoStream]->codecpar->codec_id);<br><br>    if(_codec == NULL)<br>        return false; // Codec not found<br><br>    // Copy context<br>    _codecCtx = avcodec_alloc_context3(_codec);<br>    if(avcodec_parameters_to_context(_codecCtx, _formatCtx->streams[_videoStream]->codecpar) < 0)<br>        return false; // Couldn't convert codec parameters to context<br><br>    // Open codec<br>    if(avcodec_open2(_codecCtx, _codec, nullptr) < 0)<br>        return false; // Could not open codec<br><br>    // Allocate video frame<br>    _frame = av_frame_alloc();<br>    if(_frame == nullptr)<br>        return false;<br><br>    // Allocate an AVFrame structure<br>    _frameBGRA = av_frame_alloc();<br>    if(_frameBGRA == nullptr)<br>      return false;<br><br>    int numBytes;<br>    // Determine required buffer size and allocate buffer<br>    numBytes = avpicture_get_size(AV_PIX_FMT_BGRA, _targetSize.width(), _targetSize.height());<br>    _buffer=(uint8_t *)av_malloc(numBytes * sizeof(uint8_t));<br><br>    // Assign appropriate parts of buffer to image planes in FrameBGRA<br>    avpicture_fill((AVPicture *)_frameBGRA, _buffer, AV_PIX_FMT_BGRA, _targetSize.width(), _targetSize.height());<br><br>    // initialize SWS context for software scaling<br>    _sws_ctx = sws_getContext(_codecCtx->width,<br>                              _codecCtx->height,<br>                              _codecCtx->pix_fmt,<br>                              _targetSize.width(),<br>                              _targetSize.height(),<br>                              AV_PIX_FMT_BGRA,<br>                              SWS_BILINEAR,<br>                              nullptr,<br>                              nullptr,<br>                              nullptr);</font><br></div><div><br></div><div>And here's the code in the worker thread handling the individual packets:</div><div><br></div><div><font face="monospace">    while(av_read_frame(_formatCtx, &packet) >= 0)<br>    {<br>        // Is this a packet from the video stream?<br>        if(packet.stream_index == _videoStream)<br>        {<br>            // Decode video frame<br>            avcodec_decode_video2(_codecCtx, _frame, &frameFinished, &packet);<br><br>            // Did we get a video frame?<br>            if(frameFinished)<br>            {<br>                // Convert the image from its native format to ARGB<br>                sws_scale(_sws_ctx,<br>                          (uint8_t const * const *)_frame->data,<br>                          _frame->linesize,<br>                          0,<br>                          _codecCtx->height,<br>                          _frameBGRA->data,<br>                          _frameBGRA->linesize);<br>                          <br>                // Inform the application the frame is complete<br>            }<br>        }<br><br>        // Free the packet that was allocated by av_read_frame<br>        av_packet_unref(&packet);<br>    }</font><br></div></div>