从在线视频流中截取屏幕截图

5
我需要从rtmp或http视频流中捕捉屏幕截图。我想每10秒捕捉一个屏幕截图,并将其保存为png或jpg文件。
我找不到任何可以为我完成此操作的程序,因此我考虑使用C#编写应用程序,使用以下库: http://www.broccoliproducts.com/softnotebook/rtmpclient/rtmpclient.php 不幸的是,rtmpClient库只捕捉rtmp流并将其保存为flv文件,这不是我想要的。 有人知道更好的库可以帮助我吗?
4个回答

5
我现在找到了解决问题的方法。如果有人想知道,我写了一个小程序来使用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) +
            "'";
    }

1
谢谢。看起来这个命令是让rtmpdump在ffmpeg从那一秒长的视频中取出一帧之前下载一秒钟的视频。看起来rtmpdump不支持仅下载一个视频帧,但我认为可以通过更改rtmpdump源代码,在第一个VIDEODATA数据包后停止下载:https://www.adobe.com/content/dam/Adobe/en/devnet/flv/pdfs/video_file_format_spec_v10.pdf - Andrew Smart

2
如果您使用Linux,可以使用bash(如果不适用于您,请忽略此方法),以下是我如何在我们的流媒体产品中使用“rtmpdump”(apt-get install rtmpdump)的方式:
/scripts/rtmpsnapshot
#!/bin/bash
rtmpdump --live --timeout=9 -r $1 -a $2 -y $3  --stop 1 -o - | avconv -i - -s 720x404 -vframes 1 $4

被称为:

/scripts/rtmpsnapshot rtmp://myserver.com/applicationname/ applicationname streamname /tmp/mysnapshot.jpg

0

你看过SnagIt! v11.1吗?我刚刚升级了我的版本,它可以捕捉视频流和相关音频。

我不知道每10秒截屏的功能,但我知道它内置了定时器功能和隔离单个帧的能力。

也许值得一看。我想它有30天的试用期。


-4
如果你使用的是Windows 7操作系统,它自带一个片段工具可以截取屏幕。

@Default - 它被称为“片段工具”,哈哈,可以在附件中找到。 - Icemanind
@icemanind:在我的电脑上,它被称为“截图工具”。但是如何配置该工具以每10秒拍摄一次屏幕截图呢?还是OP每次都要点击和拖动? - Patrick
@Patrick:我认为你不能配置它自动截屏。你必须手动完成。 - Icemanind

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接