asp.net C # implementation from the video screenshot program

Source: Internet
Author: User
The code is as follows Copy Code

<summary>
@ From video file screenshot, generate in folder of video files
Two predecessor configuration items are required in Web.config:
Path to 1.ffmpeg.exe file
<add key= "FFmpeg" value= "E:ffmpegffmpeg.exe"/>
2. The size of the screenshot
<add key= "catchflvimgsize" value= "240x180"/>
3. Video processing program Ffmpeg.exe
</summary>
<param name= "Vfilename" > video file address, such as:/web/flvfile/user1/00001.flv</param>
<returns> success: Return the virtual address of the picture; Failure: Returning an empty string </returns>
public string catchimg (string vfilename)
{
Gets the path of the Ffmpeg.exe, where the path is configured in web.config, such as: <add key= "FFmpeg" value= "E:ffmpegffmpeg.exe"/>
String ffmpeg=system.configuration.configurationsettings.appsettings["FFmpeg"];

if (! System.IO.File.Exists (ffmpeg)) | | (! System.IO.File.Exists (Vfilename))
{
Return "";
}

Get the picture relative path/Last store to the database path, such as:/web/flvfile/user1/00001.jpg
String flv_img = System.IO.Path.ChangeExtension (Vfilename, ". jpg");

Picture absolute path, such as: d:videowebflvfileuser1001.jpg
String flv_img_p = HttpContext.Current.Server.MapPath (flv_img);

Screenshot size, configured in web.config, such as: <add key= "catchflvimgsize" value= "240x180"/>
String flvimgsize=system.configuration.configurationsettings.appsettings["Catchflvimgsize"];

System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo (ffmpeg);
Startinfo.windowstyle = System.Diagnostics.ProcessWindowStyle.Hidden;

This is the parameter that can be combined into a ffmpeg.exe file, where the command is ffmpeg 0.4.9 debugging through
startinfo.arguments = "I" + vfilename + "-y-f image2-t 0.001-s" + flvimgsize + "" + flv_img_p

;

Try
{
System.Diagnostics.Process.Start (StartInfo);
}
Catch
{
Return "";
}

Note: After the successful capture of the image, the data from the memory cache to disk will take a long time, probably 3, 4 seconds or longer;
Here need to delay after detection, I server delay 8 seconds, that is, if more than 8 seconds picture still does not exist, that the screenshot failed;
The delay code is omitted here. If the one who knows how to capture the Ffmpeg.exe screenshot failure message, please inform, first thanks!
if (System.IO.File.Exists (flv_img_p))
{
return flv_img;
}

Return "";
}
There is a problem is that the screenshot failed after we do not get the message of failure, the problem is still waiting for the master to solve

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.