简体   繁体   English

从在线视频流中捕获屏幕截图

[英]Capture a screenshot from an online video stream

I need to capture screenshots from an rtmp or http video stream. 我需要从rtmp或http视频流中捕获屏幕截图。 I want to capture a screenshot each 10 seconds and save it as a png or jpg file. 我想每10秒捕获一次屏幕截图,并将其另存为png或jpg文件。

I havnt been able to find any programs that does this for me so I was thinking of writing an application in C# using the lib from: http://www.broccoliproducts.com/softnotebook/rtmpclient/rtmpclient.php 我没有能够找到适合我的任何程序,因此我考虑使用以下库中的lib在C#中编写应用程序: http : //www.broccoliproducts.com/softnotebook/rtmpclient/rtmpclient.php

Unfortunately it seems that the rtmpClient lib only captures rtmp streams and saves it into an flv file, which is not what I want. 不幸的是,似乎rtmpClient库仅捕获rtmp流并将其保存到flv文件中,这不是我想要的。 Anyone that knows any better libs that can help me with this? 有谁知道可以帮助我的更好的libs吗?

I found a solution to the problem now. 我现在找到了解决该问题的方法。 If someone wants to know, I wrote a small program that uses rtmpdump and ffmpeg to capture the image. 如果有人想知道,我写了一个小程序,使用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) +
            "'";
    }

You could use bash if you're on Linux (this may not be applicable to you, but hopefully will help anybody Googling), this is how I use it for our streaming product using 'rtmpdump' (apt-get install rtmpdump): 如果您使用的是Linux,则可以使用bash(这可能不适用于您,但希望对任何使用Google的人都有用),这就是我使用'rtmpdump'(apt-get install rtmpdump)将其用于流媒体产品的方式:

/scripts/rtmpsnapshot / scripts / rtmpsnapshot

#!/bin/bash
rtmpdump --live --timeout=9 -r $1 -a $2 -y $3  --stop 1 -o - | avconv -i - -s 720x404 -vframes 1 $4

called as such: 这样称呼:

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

Have you looked at SnagIt! 您是否看过SnagIt! v11.1 ? v11.1 I just upgraded my copy and it will capture video streams and associated audio. 我刚刚升级了副本,它将捕获视频流和关联的音频。

I don't know about the screenshot every 10 seconds, but I do know it has timer capabilities built in, and the ability to isolate individual frames. 我不知道每10秒截图一次,但我知道它内置了计时器功能,并且可以隔离单个帧。

Might be worth a look. 可能值得一看。 I think it comes with a 30 day trial. 我认为它具有30天的试用期。

如果您使用的是Windows 7,它将附带一个片段工具,它将捕获您的屏幕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM