Flatron
Flatron

Reputation: 687

Capture a screenshot from an online video stream

I need to capture screenshots from an rtmp or http video stream. I want to capture a screenshot each 10 seconds and save it as a png or jpg file.

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

Unfortunately it seems that the rtmpClient lib only captures rtmp streams and saves it into an flv file, which is not what I want. Anyone that knows any better libs that can help me with this?

Upvotes: 5

Views: 7781

Answers (4)

Ashley Hindle
Ashley Hindle

Reputation: 21

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):

/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

Upvotes: 2

Flatron
Flatron

Reputation: 687

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.

    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) +
            "'";
    }

Upvotes: 5

Icemanind
Icemanind

Reputation: 48696

If you are using Windows 7, it comes with a snippet tool that will capture your screen.

Upvotes: -5

Randy Minder
Randy Minder

Reputation: 48432

Have you looked at SnagIt! 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.

Might be worth a look. I think it comes with a 30 day trial.

Upvotes: 0

Related Questions