1.scrcpy开启了多台设备录屏,如果命令直接kill掉scrcpy.exe进程的话,那么会造成录屏后视频文件无法观看,没办法只能kill掉它的父进程,也就是adb进程,但scrcpy.exe的所有进程都是在同一个adb进程上运行的,如果kill掉父进程,那么所有的scrcpy的录屏进程都会停止!有没有办法,解决这个kill某台设备录屏进程且保证录屏文件完好的问题?
2.scrcpy是支持投屏和录屏的,但并不支持录音,在github上yuan码教程上说用sndcpy,不过sndcpy只支持音频转发,并不支持录音功能,有没有办法让sndcpy实现录音(不太现实,官网都说不能了),或者有没有其他的录音软件可以对连接的手机实现音频内录?
internal const int CTRL_C_EVENT = 0;
[DllImport("kernel32.dll")]
internal static extern bool GenerateConsoleCtrlEvent(uint dwCtrlEvent, uint dwProcessGroupId);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool AttachConsole(uint dwProcessId);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern bool FreeConsole();
[DllImport("kernel32.dll")]
static extern bool SetConsoleCtrlHandler(ConsoleCtrlDelegate HandlerRoutine, bool Add);
delegate Boolean ConsoleCtrlDelegate(uint CtrlType);
/// <summary>
/// 屏幕录制mp4
/// </summary>
/// <param name="p">进程名称</param>
/// <param name="device">设备</param>
/// <param name="path">保存的文件</param>
public static void Record_Mp4(Process p, string device, string path)
{
p.StartInfo.FileName = @"App\scrcpy.exe";
p.StartInfo.Arguments = $"-s "+device+" --no-display --record "+path;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
}
/// <summary>
/// 结束录制屏幕,向进程发送ctrl+c
/// </summary>
/// <param name="p">进程名称</param>
/// <returns></returns>
public static bool StopProcess(Process p)
{
if (AttachConsole((uint)p.Id))
{
SetConsoleCtrlHandler(null, true);
try
{
if (!GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0)) return false;
p.WaitForExit();
}
finally
{
SetConsoleCtrlHandler(null, false);
FreeConsole();
}
return true;
}
return false;
}