我需要从rtmp或http视频流捕获屏幕截图。我想每10秒捕获一个屏幕截图,并将其另存为png或jpg文件。
我还没有找到任何为我做这件事的程序,所以我在考虑用http://www.broccoliproducts.com/softnotebook/rtmpclient/rtmpclient.php中的库用C#编写一个应用程序
不幸的是,rtmpClient库似乎只捕获rtmp流并将其保存到flv文件中,这不是我想要的。有谁知道更好的库可以帮助我吗?
发布于 2012-10-18 02:39:35
我现在找到了解决这个问题的办法。如果有人想知道,我写了一个小程序,使用rtmpdump和ffmpeg来捕获图像。
static void Main(string[] args)
{
const string rtmpDump = "rtmpdump.exe";
const string rtmpDumpArguments = "-v -r rtmp://{stream} -o 1.flv -B 1";
sRunExternalExe(rtmpDump, rtmpDumpArguments);
const string ffmpeg = "ffmpeg.exe";
const string ffmpegArguments = "-i 1.flv -ss 00:00:01 -an -r 1 -vframes 1 -s 400x300 -y 1.jpg";
RunExternalExe(ffmpeg, ffmpegArguments);
var theFile = new FileInfo("1.flv");
if (theFile.Exists)
{
File.Delete("1.flv");
}
}
public static string RunExternalExe(string filename, string arguments = null)
{
var process = new Process();
process.StartInfo.FileName = filename;
if (!string.IsNullOrEmpty(arguments))
{
process.StartInfo.Arguments = arguments;
}
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
var stdOutput = new StringBuilder();
process.OutputDataReceived += (sender, args) => stdOutput.Append(args.Data);
string stdError = null;
try
{
process.Start();
process.BeginOutputReadLine();
stdError = process.StandardError.ReadToEnd();
process.WaitForExit();
}
catch (Exception e)
{
throw new Exception("OS error while executing " + Format(filename, arguments) + ": " + e.Message, e);
}
if (process.ExitCode == 0 || process.ExitCode == 2)
{
return stdOutput.ToString();
}
else
{
var message = new StringBuilder();
if (!string.IsNullOrEmpty(stdError))
{
message.AppendLine(stdError);
}
if (stdOutput.Length != 0)
{
message.AppendLine("Std output:");
message.AppendLine(stdOutput.ToString());
}
throw new Exception(Format(filename, arguments) + " finished with exit code = " + process.ExitCode + ": " + message);
}
}
private static string Format(string filename, string arguments)
{
return "'" + filename +
((string.IsNullOrEmpty(arguments)) ? string.Empty : " " + arguments) +
"'";
}发布于 2012-10-18 01:51:27
你看过SnagIt! v11.1吗?我刚刚升级了我的副本,它将捕获视频流和相关的音频。
我不知道每10秒的屏幕截图,但我知道它有内置的计时器功能,以及隔离单个帧的能力。
可能值得一看。我想它有30天的试用期。
发布于 2012-10-18 01:59:56
如果你使用的是Windows7,它会附带一个截取屏幕的代码片段工具。
https://stackoverflow.com/questions/12940268
复制相似问题