当前位置:网站首页>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 了 .
边栏推荐
- [Northeast Normal University] information sharing of postgraduate entrance examination and re examination
- 在线教育知识付费网站源码系统+直播+小程序,安装教程
- mof定制产品|N-K2Ti4O9/g-C3N4/UiO-66三元复合材料|纸基Au-AgInSe2-ZIF-8纳米复合材料
- 565. 数组嵌套 / 剑指 Offer II 001. 整数除法
- How to deploy agent separately on the monitoring host -- wgcloud
- 数组模拟队列
- 状态码的故事
- 【附下载】带你使用frp实现内网穿透详细教程!
- D. Mark and Lightbulbs
- 数据包知识
猜你喜欢
随机推荐
网络安全学习(千锋网络安全笔记)1--搭建虚拟机
FAW Toyota Asia lion's first product refresh
CLWY权限管理(三)--- 用户组模块
上學=掙錢?無需繳納學費的神仙院校!
[200 opencv routines] 233 Moment invariants of regional features
【C语言】浅涉第一个C语言程序及数据类型
Flink entry to practice - stage 5 (processing function)
文件操作的底层原理(inode与软硬链接,文件的时间属性)
Run yolov3 on Huawei modelarts_ coco_ detection_ dynamic_ AIPP sample
TP5 judgment request mode
【vulnhub靶场】PRIME:1打靶过程记录
硫化镉负载MIL-125(Ti)|链霉亲和素(SA)-锆基卟啉MOF复合材料([email protected])|壳核结构
SSH连接华为ModelArts notebook
【原创】Magisk+Shamiko过APP ROOT检测
浏览器的故事
PTA 1037 change at Hogwarts
TLS four handshakes
Rocky基础之正则表达式
Huawei wireless devices are configured with static load balancing
氨基的金属-有机骨架材料Fe-MOF,Fe-MIL-88NH2|Zr基金属-有机骨架催化剂(Pt-UiO-66)|齐岳生物









