gpt4 book ai didi

PowerShell FFMPEG 图像提取直接到系统绘图图像

转载 作者:行者123 更新时间:2023-12-04 23:10:24 28 4
gpt4 key购买 nike

在过去的 48 小时里,我一直在绞尽脑汁……我很少提出问题,但我正处于崩溃的边缘。希望高手能帮忙。
问题:我需要从视频中提取图像(不保存文件)并允许我使用 PowerShell 的系统绘图包来操作它。

$ffmpeg = "C:\ffmpeg\bin\ffmpeg.exe"
$input = "C:\Users\Username\Desktop\test.mp4"
$screenshot = & $ffmpeg -i $input -ss 3 -vframes 1 -c:v bmp -f image2pipe -


##Not having issues with getting FFMPEG to pipe to a variable
##The output looks to be UTF8, but I can't convert it to a memory stream for System Drawing
##All examples I've found are using a file written to disk...I don't want to write a file


##Issues start here:
$enc = [system.Text.Encoding]::UTF8
$utf_screenshot = $enc.GetBytes($screenshot)
$base64_screenshot = [System.Convert]::ToBase64String($utf_screenshot)
$ms = new-object System.IO.MemoryStream($base64_screenshot)
$img = [system.drawing.Image]::FromStream($ms)

我对文件编码不是很精通......
任何帮助将不胜感激 - 谢谢!

最佳答案

我终于想通了......这是答案:

$ffmpeg = "C:\ffmpeg\bin\ffmpeg.exe"
$input = "C:\test.mp4"
$image = & $ffmpeg -i $input -ss 3 -vframes 1 -c:v bmp -f image2pipe -



$bytes = [system.Text.Encoding]::Default.GetBytes($image)
$stream = new-object System.IO.MemoryStream(,$bytes)
$image = [system.drawing.Image]::FromStream($stream)


write-host $image.Height
write-host $image.Width

关于PowerShell FFMPEG 图像提取直接到系统绘图图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70723880/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com