【问题标题】:Capture a screenshot from an online video stream从在线视频流中捕获屏幕截图
【发布时间】:2012-10-17 17:48:38
【问题描述】:

我需要从 rtmp 或 http 视频流中截取屏幕截图。我想每 10 秒捕获一次屏幕截图并将其保存为 png 或 jpg 文件。

我找不到任何可以为我执行此操作的程序,因此我正在考虑使用以下库在 C# 中编写应用程序: http://www.broccoliproducts.com/softnotebook/rtmpclient/rtmpclient.php

不幸的是,rtmpClient 库似乎只捕获 rtmp 流并将其保存到 flv 文件中,这不是我想要的。 任何知道可以帮助我的更好的库的人吗?

【问题讨论】:

    标签: c# video-streaming video-capture rtmp image-capture


    【解决方案1】:

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

    【讨论】:

    • 谢谢。看起来这个命令 rtmpdump 在 ffmpeg 从第二个长视频中取出一帧之前下载一秒视频。看起来 rtmpdump 不支持只下载一个视频帧,但我认为可以通过将 rtmpdump 源更改为在第一个 VIDEODATA 数据包后停止:adobe.com/content/dam/Adobe/en/devnet/flv/pdfs/…
    【解决方案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
    

    【讨论】:

      【解决方案3】:

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

      我不知道每 10 秒的屏幕截图,但我知道它内置了计时器功能,并且能够隔离各个帧。

      可能值得一看。我认为它带有 30 天的试用期。

      【讨论】:

        【解决方案4】:

        如果您使用的是 Windows 7,它带有一个 sn-p 工具,可以捕获您的屏幕。

        【讨论】:

        • @Default - 它被称为“片段工具”,哈哈,它可以在附件中找到。
        • @icemanind:在我的电脑上它被称为“截图工具”。但是如何配置该工具以每 10 秒截屏一次?还是 OP 应该每次都为自己单击和拖动?
        • @Patrick:我认为您不能将其配置为自动截屏。您必须手动完成。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-20
        相关资源
        最近更新 更多