当前位置:网站首页>Ffmpeg record video, stop (vb.net, step on the pit, class library - 10)
Ffmpeg record video, stop (vb.net, step on the pit, class library - 10)
2022-07-19 10:14:00 【Xiaoyu 163】
Many tutorials on the Internet , About FFmpeg Recording video , To install Screen Capturer Recorder,
We don't need to install a big lump of things
1、 Still want to download 、 install ![]()
But we only need to use one of them 2 A component

audio_sniffer It's in the catalog :Screen Capturer Recorder\vendor\virtual-audio
Select the corresponding components according to the needs of the system , We use it by default Not x64 Of , namely x32
Extract these two after installation Selected The file can be uninstalled
Do one thing before using , stay 2 Create an application manifest file in each project , If you have only one project , All you need is an application manifest file . hold 
Replace the second line of the comment section "-->" Later ( I have replaced ) such , The main program will run as an administrator , With Restart as administrator visual studio. The purpose is register Those two components , Give Way FFmpeg distinguish , Do not change the name of the component .( Be sure to use the administrator identity )
register Code for :
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 Classnotes : You can register with sharedP Written in the same class , my sharedP It's written in VideoProcess Class
The main form first registers these two components , In order to use for others , It can simplify the operation , Let the program register itself , Can be in Form_Load Sign up for , The perform RegRec function (function, You can change to sub)
2、 On the premise of registration , We're not here FFmpeg Tested , There must be
FFmpeg -list_devices true -f dshow -i dummy

3、 Write 2 A process , It doesn't have to be a function , Because there is no value to return
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) & " Microphone array (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 FunctionYou need to use " have access to chr(34) Instead of
It is worth noting that : Because I didn't think carefully when watching others' tutorials , Cause to execute first StartRecordVid Function time ,PRec already close + dispose 了 , So that when the call stops StandardInput This error has not been redirected
This is the wrong code :
Public Function StartRecordVid(ffmpeg As String, out As String)
PRec.StartInfo.FileName = "cmd"
PRec.StartInfo.Arguments = "/c " & ffmpeg & " -f dshow -i audio=" & Chr(34) & " Microphone array (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 FunctionThis is a pit , Don't step on it
Last : Don't forget to FFmpeg All processes end the task ,
Public Function EndRecordVid()
PRec.StandardInput.WriteLine("q")
PRec.StandardInput.AutoFlush = True
' PRec.Close()
'PRec.Dispose()
PRec.Kill()
End FunctionJoin in kill Instructions , In order to move the video , Unwanted close and dispose 了 .
边栏推荐
- [C language] involves constants and variables
- FAW Toyota Asia lion's first product refresh
- 闲谈工业企业全厂信息化规划
- Story of status code
- [动态规划]DP27 跳跃游戏(二)-中等
- Relationship between standardization, normalization and regularization
- Flink入门到实战-阶段四(时间和窗口图解)
- Huawei wireless device configuration dynamic load balancing
- [Northeast Normal University] information sharing of postgraduate entrance examination and re examination
- 状态码的故事
猜你喜欢
随机推荐
SSH连接华为ModelArts notebook
壳聚糖包裹PCN224纳米粒子|金属-有机骨架Fe-MIL-88NH2|镍基MOF材料(Ni-MOF/NF)
Database overview
上学=挣钱?无需缴纳学费的神仙院校!
【OpenCV 例程200篇】233. 区域特征之矩不变量
SSH連接華為ModelArts notebook
水下机器人ROV和AUV
Scala 基础 (三):运算符和流程控制
Clwy permission management (I) -- project construction
Blender数字孪生制作教程
TLS四次握手
Huawei wireless devices are configured with static load balancing
数据包知识
Rhcsa day 1 7.11
二维数组与稀疏数组之间的转换
Cmake -- Notes
纳米银颗粒负载UiO-66|Fe3O4/Cu3(BTC)2金属有机骨架(MOF)纳米复合材料|NaGdF4:Yb,Er上转换纳米粒子@ZIF-8
JS 之 操作 String 字符串
氮杂环分子改性UiO-66-NH2|聚乙烯亚胺改性UiO-66-NH2|[email protected]@ZIF67纳米材料
Machine learning basics that can be easily introduced in 5 minutes





[email protected]载体)|UiO-66/CoSO复合材料|ZIF-67纳米晶表面修饰六咪唑环三磷腈"/>


