当前位置:网站首页>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了。
边栏推荐
- 硫化镉负载MIL-125(Ti)|链霉亲和素(SA)-锆基卟啉MOF复合材料([email protected])|壳核结构Clwy permission management (I) -- project construction
- 【摸鱼神器】UI库秒变低代码工具——表单篇(二)子控件
- PTA 1037 change at Hogwarts
- CLWY权限管理(二)--- 用户模块
- Implement word segmentation for text and draw word cloud
- Week 1: introduction to deep learning and foundation of pytorch
- Idea stuck and reported an error: UI was frozen for xxxxx MS problem solving
- FAW Toyota Asia lion's first product refresh
- 空天地海协同应用综述
猜你喜欢

文件操作的底层原理(inode与软硬链接,文件的时间属性)

状态码的故事

Microsoft OneNote 教程,如何在 OneNote 中插入数学公式?

金属有机骨架/碳化氮纳米片(UiO-66/HOCN)复合材料|MIL-101负载Au-Pd合金纳米粒子|化学试剂mof定制

mof定制产品|N-K2Ti4O9/g-C3N4/UiO-66三元复合材料|纸基Au-AgInSe2-ZIF-8纳米复合材料

Learning summary of MySQL advanced Chapter 11: locate SQL methods with slow execution and analyze the use of query statement explain

【MySQL】MySQL的增删查改(进阶)

纳米银颗粒负载UiO-66|Fe3O4/Cu3(BTC)2金属有机骨架(MOF)纳米复合材料|NaGdF4:Yb,Er上转换纳米粒子@ZIF-8

TLS four handshakes

mof定制材料|超薄MOF纳米带|磁性Fe3O4 @Cd-MOF纳米复合材料|ZIF-8/石墨烯复合纳米颗粒
随机推荐
Clwy permission management (I) -- project construction
2022.07.14 暑假集训 个人排位赛(九)
Blender数字孪生制作教程
SSH連接華為ModelArts notebook
纳米银颗粒负载UiO-66|Fe3O4/Cu3(BTC)2金属有机骨架(MOF)纳米复合材料|NaGdF4:Yb,Er上转换纳米粒子@ZIF-8
Conversion between two-dimensional array and sparse array
数据湖(十二):Spark3.1.2与Iceberg0.12.1整合
Talking about the informatization planning of industrial enterprises
PTA 1037 change at Hogwarts
上学=挣钱?无需缴纳学费的神仙院校!
金纳米粒子修饰MIL-101骨架材料(AuNPs/MIL-101)/负载COF-TpPa-1(Au NPs/COF-TpPa-1)|齐岳试剂
流量排名100W网站
Online education knowledge payment website source code system + live broadcast + applet, installation tutorial
【东北师范大学】考研初试复试资料分享
[C language] a brief introduction to the first C language program and data type
硫化铜纳米粒/ZIF-8复合材料([email protected]载体)|UiO-66/CoSO复合材料|ZIF-67纳米晶表面修饰六咪唑环三磷腈
通信工程论文 通信网络中故障数据优化检测仿真研究
sqli-labs(less-11)
文件操作的底层原理(inode与软硬链接,文件的时间属性)
Clwy authority management (II) -- user module