欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Flutter使用texture_rgba_renderer實(shí)現(xiàn)桌面端渲染視頻詳解

 更新時(shí)間:2023年07月30日 09:26:39   作者:CodeOfCC  
這篇文章主要為大家介紹了Flutter如何使用texture_rgba_renderer實(shí)現(xiàn)桌面端渲染視頻,文中的示例代碼講解詳細(xì),需要的可以了解一下

前言

前面幾章介紹了flutter使用texture渲染視頻的方法,但是有個(gè)問(wèn)題就是在每個(gè)平臺(tái)都需要寫(xiě)一套原生代碼去創(chuàng)建texture,這樣對(duì)于代碼的維護(hù)是比較不利的。最好的方法應(yīng)該是一套代碼每個(gè)平臺(tái)都能運(yùn)行,筆者最近剛好找到了pub上對(duì)texture封裝的插件,直接提供dart代碼調(diào)用texture進(jìn)行rgba的渲染,當(dāng)然只支持桌面端,即Windows、Linux、Macos,但依然是很方便了。本文只實(shí)現(xiàn)了Windows、Linux的視頻渲染。

一、如何實(shí)現(xiàn)

1、添加插件

插件的地址是https://pub-web.flutter-io.cn/packages/texture_rgba_renderer。我們直接在pubspec.yaml添加依賴(lài)即可。

依賴(lài)

texture_rgba_renderer: ^0.0.16

引用

import 'package:texture_rgba_renderer/texture_rgba_renderer.dart';

2、創(chuàng)建texture

定義一個(gè)全局插件對(duì)象

final _textureRgbaRendererPlugin = TextureRgbaRenderer();

創(chuàng)建texture,得到textureId

//textureId,使用ValueNotifier方便刷新界面
ValueNotifier<int> _textureId = ValueNotifier<int>(-1);
//參數(shù)為唯一標(biāo)識(shí)符,使用當(dāng)前對(duì)象this的hashCode。
 _textureId.value = await _textureRgbaRendererPlugin.createTexture(hashCode);

3、關(guān)聯(lián)texture控件

//ValueListenableBuilder與ValueNotifier是配套使用的,方便界面刷新。
ValueListenableBuilder(
                      valueListenable: _textureId,
                      builder: (c, v, w) {
                        //關(guān)聯(lián)textureId
                        return Texture(textureId: _textureId.value);
                      })),

4、寫(xiě)入bgra

數(shù)據(jù)格式為ffmpeg的AV_PIX_FMT_BGRA

//數(shù)據(jù)地址
int adress = msg[2];
//一行數(shù)據(jù)長(zhǎng)度
int linesize = msg[3];
int width = msg[4];
int height = msg[5];
//將bgra數(shù)據(jù)寫(xiě)入texture
final ptr = await _textureRgbaRendererPlugin.getTexturePtr(hashCode);
Native.instance.onRgba(
    Pointer.fromAddress(ptr),
    Pointer.fromAddress(adress),
    height* linesize,
    width,
    height,
    linesize);

二、效果預(yù)覽

基本的一個(gè)運(yùn)行效果

三、問(wèn)題分析

texture_rgba_renderer: 0.0.16,就目前的版本來(lái)看,cpu消耗比原生寫(xiě)texture要高不少。主要原因是在dart寫(xiě)入bgra數(shù)據(jù)時(shí),插件底層先是拷貝了一次數(shù)據(jù),然后對(duì)又?jǐn)?shù)據(jù)進(jìn)行第二次逐行掃描拷貝到新的緩沖區(qū)對(duì)齊數(shù)據(jù),這些操作都是比較消耗cpu的,尤其是逐行掃描拷貝。

到此這篇關(guān)于Flutter使用texture_rgba_renderer實(shí)現(xiàn)桌面端渲染視頻詳解的文章就介紹到這了,更多相關(guān)Flutter渲染視頻內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論