当前位置:网站首页>FFmpeg录制视频、停止(VB.net,踩坑,类库——10)
FFmpeg录制视频、停止(VB.net,踩坑,类库——10)
2022-07-17 11:45:00 【小虞163】
网上的好多教程,关于FFmpeg录制视频的,要安装Screen Capturer Recorder,
我们其实不需要去安装一大坨的东西
1、还是要下载、安装![]()
但是我们只需要用到其中的2个组件

audio_sniffer是在目录:Screen Capturer Recorder\vendor\virtual-audio
根据系统需要选择相应的组件,我们默认使用非x64的,即x32
安装后提取这两个选中的文件就可以卸载了
在使用之前先干一件事,在2个项目中分别新建一个应用程序清单文件,如果你只有一个项目,就只需要一个应用程序清单文件。把
注释部分的第二行替换 "-->"后面的内容(我已经替换好了)这样,主程序就会以管理员身份运行,以管理员身份重新启动visual studio。目的是注册那两个组件,让FFmpeg识别,组件的名字不要改动。(一定要使用管理员身份)
注册的代码:
Public Class RegDll
Public Function RegRec()
VideoProcess.SharedP("C:\WINDOWS\system32\cmd.exe", "/c /q regsvr32 /u " & Application.StartupPath & "\screen-capture-recorder.dll", True)
VideoProcess.SharedP("C:\WINDOWS\system32\cmd.exe", "/c /q regsvr32 " & Application.StartupPath & "\screen-capture-recorder.dll", True)
VideoProcess.SharedP("C:\WINDOWS\system32\cmd.exe", "/c /q regsvr32 /u " & Application.StartupPath & "\audio_sniffer.dll", True)
VideoProcess.SharedP("C:\WINDOWS\system32\cmd.exe", "/c /q regsvr32 " & Application.StartupPath & "\audio_snifferr.dll", True)
End Function
Public Shared Function SharedP(s As String, Arguments As String, nowindow As Boolean)
Dim p As New Process
p.StartInfo.FileName = s
p.StartInfo.Arguments = Arguments
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = nowindow
p.Start()
p.WaitForExit()
p.StandardError.ReadToEnd()
Return p.StandardError.ReadToEnd()
p.Close()
p.Dispose()
End Function
End Class注:可以把注册和sharedP 写在同一个类里,我的sharedP写在了VideoProcess类中
主窗体先注册这两个组件,为了在给别人用的时候,可以实现操作简单化,让程序自己注册,可以在Form_Load时注册,即执行RegRec函数(function,可以改成sub)
2、在注册的前提下,我们就不在FFmpeg测试了,肯定有了
FFmpeg -list_devices true -f dshow -i dummy

3、写2个过程,不一定要是函数,因为没有可以返回的值
Public PRec As New Process
Public Function StartRecordVid(ffmpeg As String, out As String)
PRec.StartInfo.FileName = "cmd"
PRec.StartInfo.Arguments = "/c " & ffmpeg & " -f dshow -i audio=" & Chr(34) & "麦克风阵列 (Conexant SmartAudio HD)" & Chr(34) & " -f dshow -i audio=" & Chr(34) & "virtual-audio-capturer" & Chr(34) & " -filter_complex amix=inputs=2:duration=first:dropout_transition=0 -f dshow -i video=" & Chr(34) & "screen-capture-recorder" & Chr(34) & " -pix_fmt yuv420p " & out & " -y"
PRec.StartInfo.UseShellExecute = False
PRec.StartInfo.CreateNoWindow = true
'PRec.StartInfo.RedirectStandardOutput = True
'PRec.StartInfo.RedirectStandardError = True
PRec.StartInfo.RedirectStandardInput = True
PRec.Start()
PRec.EnableRaisingEvents = True
End Function
Public Function EndRecordVid()
PRec.StandardInput.WriteLine("q")
PRec.StandardInput.AutoFlush = True
PRec.Close()
PRec.Dispose()
End Function输入的时候需要用到 " 可以使用chr(34)代替
值得注意的是:由于在看别人的教程时没有细致考虑,导致先执行StartRecordVid函数时,PRec已经close + dispose了,以至于在调用停止的时候显示StandardInput尚未重定向这个错误
这是错误的代码:
Public Function StartRecordVid(ffmpeg As String, out As String)
PRec.StartInfo.FileName = "cmd"
PRec.StartInfo.Arguments = "/c " & ffmpeg & " -f dshow -i audio=" & Chr(34) & "麦克风阵列 (Conexant SmartAudio HD)" & Chr(34) & " -f dshow -i audio=" & Chr(34) & "virtual-audio-capturer" & Chr(34) & " -filter_complex amix=inputs=2:duration=first:dropout_transition=0 -f dshow -i video=" & Chr(34) & "screen-capture-recorder" & Chr(34) & " -pix_fmt yuv420p " & out & " -y"
PRec.StartInfo.UseShellExecute = False
PRec.StartInfo.CreateNoWindow = true
'PRec.StartInfo.RedirectStandardOutput = True
'PRec.StartInfo.RedirectStandardError = True
PRec.StartInfo.RedirectStandardInput = True
PRec.Start()
PRec.EnableRaisingEvents = True
PRec.Close()
PRec.Dispose()
End Function
Public Function EndRecordVid()
PRec.StandardInput.WriteLine("q")
PRec.StandardInput.AutoFlush = True
End Function这是一个坑,不要去踩哦
最后:不要忘记把FFmpeg所有的进程全部结束任务,
Public Function EndRecordVid()
PRec.StandardInput.WriteLine("q")
PRec.StandardInput.AutoFlush = True
' PRec.Close()
'PRec.Dispose()
PRec.Kill()
End Function加入kill指令,以便移动视频,不需要close 和dispose了。
边栏推荐
- 506.相对名次
- 华为无线设备配置动态负载均衡
- FAW Toyota Asia lion's first product refresh
- PTA 1037 change at Hogwarts
- CLWY权限管理(三)--- 用户组模块
- 一种基于Grubbs和孤立森林的多维序列异常检测方法
- Clwy permission management (III) -- user group module
- [Download] take you to use FRP to achieve intranet penetration detailed tutorial!
- 数组模拟队列
- 6G空天地一体化网络高空平台基站下行频谱效率研究
猜你喜欢

【C语言】字符串、转义字符及注释

Huawei wireless device configuration dynamic load balancing
[email protected]|[email protected]<"/>卟啉包裹型金属有机框架材料[email protected]|[email protected]<

Clwy permission management (III) -- user group module
![[C language] shallow selection, circular statements, functions and arrays](/img/5e/39dd5595528b5cc0e59b538fecfd85.png)
[C language] shallow selection, circular statements, functions and arrays
![[C language] a brief introduction to the first C language program and data type](/img/59/9a90d94c4735d80402cda72ac6f2e6.png)
[C language] a brief introduction to the first C language program and data type

Relationship between standardization, normalization and regularization

Build a server environment with node+express

Es restful operation

高性能IO框架库libevent(三):libevent框架函数概述
随机推荐
【分离式超图像分类平台】使用深度学习中那些令人兴奋的模型搭建图像分类平台
氮杂环分子改性UiO-66-NH2|聚乙烯亚胺改性UiO-66-NH2|[email protected]@ZIF67纳米材料
纳米银颗粒负载UiO-66|Fe3O4/Cu3(BTC)2金属有机骨架(MOF)纳米复合材料|NaGdF4:Yb,Er上转换纳米粒子@ZIF-8
Build a server environment with node+express
QT学习日记17——Qt数据库
How to correctly execute jedis unit test
mof定制材料|NH(2)-UiO66/rGO氧化石墨烯纳米复合材料|负载亚甲基蓝的ZIF-90纳米粒子
上学=挣钱?无需缴纳学费的神仙院校!
[Download] take you to use FRP to achieve intranet penetration detailed tutorial!
CLWY权限管理(三)--- 用户组模块
状态码的故事
【森城市】GIS数据漫谈(四)— 坐标系统
Cmake -- Notes
Chapter 4 - first order multi-agent system consistency - > pilot follow system consistency [program code]
[C language] shallow selection, circular statements, functions and arrays
【C语言】浅涉常量、变量
Regular expression of rocky basis
金属有机骨架/碳化氮纳米片(UiO-66/HOCN)复合材料|MIL-101负载Au-Pd合金纳米粒子|化学试剂mof定制
【vulnhub靶场】PRIME:1打靶过程记录
The module created by yourself uses CMD to open the report modulenotfounderror: no module named solution