Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert uploaded video and get a screenshot from this file?

I'm building a cms and I want users to be able to upload videos but I'm not familiar with video upload & conversion. Is there an example or has anybody coded a solution like this? I heard about ffmpeg but I don't know how to integrate it with asp.net.

As simple solution I can make my clients upload flv files but then I would still need to get a screenshot from that fvl.

Thanks

like image 281
HasanG Avatar asked Apr 21 '10 10:04

HasanG


People also ask

How can I convert video to image?

Upload any type of video and it will generate a list of JPG (JPEG) images. Upload your video, select size and frames per second, choose the part of the video you want to convert, and click "Convert to JPG!" button. The tool will display a sequence of JPG images and allow you to download them in a zip archive.


2 Answers

Answering author's question:

Does ffmpeg requires to be installed server side or just exe is enough?

ffmpeg.exe will be enough, no installation is required.

The code below gets a screenshot on captureTime on video specified by videoFilename variable, and saves it to the imageFilename path.

Process ffmpeg = new Process();
ffmpeg.EnableRaisingEvents = true;
ffmpeg.StartInfo = new ProcessStartInfo
{
    FileName = this.ffmpegPath,
    Arguments = string.Format(
        "-i \"{0}\" -an -y -s 320x240 -ss {1} -vframes 1 -f image2 \"{2}\"",
        this.videoFilename,
        DateTime.MinValue.Add(this.captureTime).ToString("HH:mm:ss:ff", CultureInfo.InvariantCulture),
        this.imageFilename
    ),
    WorkingDirectory = this.workingDirectory,
    UseShellExecute = false,
    RedirectStandardError = true,
    RedirectStandardOutput = true,
    WindowStyle = ProcessWindowStyle.Hidden
};

ffmpeg.Start();
ffmpeg.WaitForExit(this.timeout);
like image 148
Oleks Avatar answered Sep 20 '22 15:09

Oleks


I've used ffmpeg, but I found it easier to just use the pre-compiled .exe version. So in the backend, I would just launch ffmpeg.exe with the required command-line arguments to do the conversion, let it run and when it was finished the completed file was all ready to go.

like image 2
Dean Harding Avatar answered Sep 18 '22 15:09

Dean Harding