在Android上的OpenGL中绘制视频帧(Drawing Video Frames in OpenGL on Android)
我目前正在研究一种在Android上通过OpenGL ES 1.0显示视频帧(作为位图)的系统。 我的问题是我无法获得超过10 fps的速度。
在做了一些测试之后,我已经确定最大的瓶颈之一是需要位图使其宽度和高度都是2的幂。例如,640x480视频必须扩展到1024x1024。 没有缩放,我已经能够获得大约40-50fps,但纹理只是显示为白色,这对我没有好处。
我知道OpenGL ES 2.0支持使用两种纹理的非强大功能,但我没有使用着色器/ 2.0中的任何新功能的经验
有什么办法可以解决这个问题吗? 与我的相比,其他视频播放如何获得如此好的表现? 我已经包含了一些代码供参考。
private Bitmap makePowerOfTwo(Bitmap bitmap) { // If one of the bitmap's resolutions is not a power of two if(!isPowerOfTwo(bitmap.getWidth()) || !isPowerOfTwo(bitmap.getHeight())) { int newWidth = nextPowerOfTwo(bitmap.getWidth()); int newHeight = nextPowerOfTwo(bitmap.getHeight()); // Generate a new bitmap which has the needed padding return Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true); } else { return bitmap; } } private static boolean isPowerOfTwo(int num) { // Check if a bitwise and of the number and itself minus one is zero return (num & (num - 1)) == 0; } private static int nextPowerOfTwo(int num) { if(num <= 0) { return 0; } int nextPowerOfTwo = 1; while(nextPowerOfTwo < num) { nextPowerOfTwo <<= 1; // Bitwise shift left one bit } return nextPowerOfTwo; }
I'm currently working on a system which displays video frames (as bitmaps) via OpenGL ES 1.0 on Android. My issue is that I have not been able to get more than about 10 fps.
After doing some testing, I've determined that one of the biggest bottlenecks is the need for the bitmap to have its width and height both be a power of 2. A 640x480 video has to be scaled up to 1024x1024, for example. Without the scaling, I've been able to get about 40-50fps, but the texture just appears white, which does me no good.
I know that OpenGL ES 2.0 supports using non-power of two textures, but I have no experience with shaders / anything else new in 2.0
Is there any way I can get around this issue? How do other video plays get such good performance in comparison to what I have? I have included some code for reference.
private Bitmap makePowerOfTwo(Bitmap bitmap) { // If one of the bitmap's resolutions is not a power of two if(!isPowerOfTwo(bitmap.getWidth()) || !isPowerOfTwo(bitmap.getHeight())) { int newWidth = nextPowerOfTwo(bitmap.getWidth()); int newHeight = nextPowerOfTwo(bitmap.getHeight()); // Generate a new bitmap which has the needed padding return Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true); } else { return bitmap; } } private static boolean isPowerOfTwo(int num) { // Check if a bitwise and of the number and itself minus one is zero return (num & (num - 1)) == 0; } private static int nextPowerOfTwo(int num) { if(num <= 0) { return 0; } int nextPowerOfTwo = 1; while(nextPowerOfTwo < num) { nextPowerOfTwo <<= 1; // Bitwise shift left one bit } return nextPowerOfTwo; }
原文:
最满意答案
Invoke-RestMethod
仅返回rss或atom-feed中的条目,如MSDN中所述 :Windows PowerShell根据数据类型格式化响应。 对于RSS或ATOM订阅源,Windows PowerShell将返回Item或Entry XML节点。 对于JavaScript Object Notation(JSON)或XML,Windows PowerShell将内容转换(或反序列化)为对象。
您可以使用
Invoke-WebRequest
读取原始xml并访问feed-element。 防爆。$xml = [xml](Invoke-WebRequest -Uri $url -Credential $credentials)
样本输出:
PS> $xml.feed xmlns : http://www.w3.org/2005/Atom title : VG ATOM Feed link : {link, link} id : http://www.vg.no/rss/feed/forsiden/?format=atom updated : 2017-03-19T18:36:56+01:00 entry : {entry, entry, entry, entry...}
Invoke-RestMethod
only returns the entries in a rss or atom-feed, as stated on MSDN:Windows PowerShell formats the response based to the data type. For an RSS or ATOM feed, Windows PowerShell returns the Item or Entry XML nodes. For JavaScript Object Notation (JSON) or XML, Windows PowerShell converts (or deserializes) the content into objects.
You can use
Invoke-WebRequest
to read the original xml and access the feed-element. Ex.$xml = [xml](Invoke-WebRequest -Uri $url -Credential $credentials)
Sample output:
PS> $xml.feed xmlns : http://www.w3.org/2005/Atom title : VG ATOM Feed link : {link, link} id : http://www.vg.no/rss/feed/forsiden/?format=atom updated : 2017-03-19T18:36:56+01:00 entry : {entry, entry, entry, entry...}
相关问答
更多-
使用PowerShell的Invoke-RestMethod的OneLogin REST API(OneLogin REST API with PowerShell's Invoke-RestMethod)[2023-06-14]
我能够让PUT工作! 如何从Invoke-RestMethod获取丰富的错误响应数据 首先,我在这里使用了这篇博文,它有一个很好的方法来检索Invoke-RestMethod或WebRequest cmdlet的完整错误消息。 在他的方法中,首先定义一个名为Failure的函数。 function Failure { $global:helpme = $body $global:helpmoref = $moref $global:result = $_.Exception.Response.GetResp ... -
我继续前进并查看了Invoke-WebRequest cmdlet代码,并发现它为什么会因此特定错误而失败。 它在调用System.Globalization.EncodingTable.GetCodePageFromName失败。 编码作为参数传递给该函数,并通过Content-Type头从cmdlet中检索编码。 在这个服务器的情况下,Content-Type作为Content-Type: application/xml; charset="UTF-8"在响应中被发回Content-Type: appl ...
-
Powershell Invoke-RestMethod缺少cookie值(Powershell Invoke-RestMethod missing cookie values)[2022-03-01]
我已经把它搞砸了(最后 - 非常痛苦) - 我必须建立自己的cookie: $CSRF = Invoke-RestMethod -Uri ($Uri+'csrf-token') -Method Get -Credential $Creds -ContentType 'application/json' -SessionVariable websession -MaximumRedirection 0 $CSRFToken = $CSRF.tokenValue # Capture cookie $cookie ... -
读取由Invoke-RestMethod返回的PowerShell对象(Reading powershell objects returned by Invoke-RestMethod)[2022-11-18]
$req = Invoke-RestMethod $request $warranties = $req.AssetWarrantyResponse.AssetEntitlementData[0] $dellasset = $req.AssetWarrantyResponse.productheaderdata $req = Invoke-RestMethod $request $warranties = $req.AssetWarrantyResponse.AssetEntitlementData[0 ... -
Invoke-SqlCmd确实如此,它使用给定的参数执行外部sclcmd 。 替代方案: Import-Module SQLPS # Create connection to server using Integrated Security $ServerName = "localhost" $DBname = "master" $sqlConn = New-Object -Type:Microsoft.SqlServer.Management.Common.ServerConnection -Argum ...
-
我没有你的意见,所以我不能100%肯定这会完美,但我相信你会追求: Invoke-RestMethod ... | ConvertFrom-Json | Where-Object { $_.Name -eq $env:ComputerName } | Select-Object -ExpandProperty ID I don't have your input, so I can't be 100% sure this will work perfectly, but I be ...
-
将流从Invoke-RestMethod写入PowerShell中的映像文件(Write stream got from Invoke-RestMethod to image file in PowerShell)[2022-12-10]
使用-OutFile开关: $url = "http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b" Invoke-RestMethod $url -OutFile somefile.png 您也可以使用Invoke-WebRequest而不是Invoke-RestMethod 。 Use -OutFile switch: $url = "http://cdn.sstatic.net/stackoverflow/img/spr ... -
使用PowerShell Invoke-RestMethod将Zip上传到Phonegap(Uploading Zip to Phonegap Using PowerShell Invoke-RestMethod)[2022-03-31]
Invoke-RestMethod -Uri https://build.phonegap.com/api/v1/apps/:id -Headers @{Authorization='Basic username-and-password-in-base64'} -Method Put -InFile "www.zip" username-and-password-in-base64是您的Adobe / PhoneGap Build用户名和密码,组合成一个字符串“username:password”,并使 ... -
Invoke-RestMethod仅返回rss或atom-feed中的条目,如MSDN中所述 : Windows PowerShell根据数据类型格式化响应。 对于RSS或ATOM订阅源,Windows PowerShell将返回Item或Entry XML节点。 对于JavaScript Object Notation(JSON)或XML,Windows PowerShell将内容转换(或反序列化)为对象。 您可以使用Invoke-WebRequest读取原始xml并访问feed-element。 防爆。 ...
-
内容类型 Invoke-RestMethod -Method Post -Uri $url -Body $body -ContentType 'application/json' 如果dyn.com期待正确的内容类型,这可能是问题。 根据Invoke-RestMethod上的文档: 如果省略此参数且请求方法为POST,则Invoke-RestMethod将内容类型设置为“application / x-www-form-urlencoded”。 否则,在呼叫中未指定内容类型。 ConvertTo-JSON ...