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

前端 未结 3 1277
无人共我
无人共我 2021-02-04 19:51

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 li

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-04 20:28

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

提交回复
热议问题