在PowerShell中使用通过管道一起传输的ffmpeg和ffplay [英] Using ffmpeg and ffplay piped together in PowerShell

查看:399
本文介绍了在PowerShell中使用通过管道一起传输的ffmpeg和ffplay的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经将当前的视频项目从命令提示符切换到PowerShell,这样我就可以充分利用Tee-Object获得多输出代码了.

I have switched my current video project from command prompt to PowerShell so that I can take full advantage of the Tee-Object for a multi output code.

当前,我有一个可以批量工作的代码版本,但是我需要通过T型头添加一个功能.这是我第一次使用PowerShell,因此这可能是一个简单的解决方法...

Currently, I have a version of my code working in batch, but I need to add one more feature through a tee. This is my first time using PowerShell, so this is probably a simple fix...

当前,我已经弄清楚了如何在PowerShell中运行ffmpegffplay,并且我有一个批量处理程序,该程序接受ffmpeg输出并将其通过管道传输到ffplay,这很好用.我也可以在PS中通过ffplay玩游戏.在PS中,此代码有效:

Currently I have figured out how to run ffmpeg and ffplay in PowerShell, and I have a program in batch which takes an ffmpeg output and pipes it to ffplay, and this works just fine. I can also play through ffplay in PS just fine. In PS, this code works:

ffplay -video_size 1280x720 -pixel_format uyvy422 -framerate 60 -i video="Decklink Video Capture"

作为批处理,此代码可以很好地满足我的工作要求:

And as a batch, this code works fine for what I'm doing:

ffmpeg -video_size 1280x720 -pixel_format uyvy422 -framerate 60 -i video="Decklink Video Capture" -c:v libx265 -preset ultrafast -mpegts pipe: | ffplay pipe:

它将获取我想要的视频,然后通过管道将其播放到屏幕上.但是,通过PowerShell播放时,视频甚至不会弹出.我没有收到任何警告或任何警告,它似乎运行良好,但没有显示图片.

It takes the video I want and plays it through the pipe to the screen. When played through PowerShell, though, the video doesn't even pop up. I don't get any warnings or anything, and it seems to run fine, but I don't get the picture to display.

最终目标是能够在主机显示器上以全分辨率播放视频,并在网络上发布较低的比特率(如果有帮助的话).

End goal is to be able to play the video on the host display in full resolution, and publish a lower bitrate to the network, if that helps.

推荐答案

您看到奇怪行为的原因是,PowerShell中的管道工作方式与旧的cmd-解释器/控制台中的工作方式不同.基本上,它是由PowerShell解析的,然后再传递给下一个命令. 您可以在此GitHub问题中阅读更多有关启用两个本机的正在进行的工作进程以在PowerShell中传递原始字节流.

The reason you are seeing strange behavior, is that piping in PowerShell does not work the same way as in the old cmd-interpreter/console. Basically it is parsed by PowerShell before being passed on to the next command. You may read more in this GitHub issue about some of the ongoing work to enable two native processes to pass raw byte-streams in PowerShell.

如果无法仅在旧式cmd-shell中运行命令(这可能是最简单的方法),则可以使用模块

If you are unable to just run your command in a legacy cmd-shell (it would probably be the easiest way), you may use the module Use-RawPipeline.

Install-Module -Name Use-RawPipeline

然后,您可以像这样构造命令行(为了简化起见,我将参数列表简化为仅使用文件并跳过了decklink-source):

Then you can construct a command line like this (I've simplified the argument list to just to use a file and skip the decklink-source for brevity):

Invoke-NativeCommand -FilePath .\ffmpeg -ArgumentList @("-i", "C:\temp\testfile.mp4","-f","h264", "pipe:") |
Invoke-NativeCommand -FilePath .\ffplay.exe -ArgumentList @("pipe:") |
Receive-RawPipeline

如果需要向管道添加更多命令,只需在Receive-RawPipeline之前插入另一个Invoke-NativeCommand -FilePath <command>.

If you need to add more command to the pipeline, just insert another Invoke-NativeCommand -FilePath <command> before the Receive-RawPipeline.

注意:我不确定此解决方案的性能,但是我已经确认它将把ffmpeg的输出传递给ffplay并显示编码后的流.

Note: I am not sure about the performance of this solution, but I have confirmed it will pipe the output of ffmpeg to ffplay and display the encoded stream.

这篇关于在PowerShell中使用通过管道一起传输的ffmpeg和ffplay的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆