The former company used a video capture feature in the production of a podcast system (Web program).
Below is the screenshot catchimg method, can be from most of the video file screenshot success, we can test;
If the screenshot is unsuccessful, it is mostly due to problems with the video itself, such as coding standards or adding a secret.
But the screenshot from the online recorded video of the FLV file has not been found to have failed;
<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:\ffmpeg\ffmpeg.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:\ffmpeg\ffmpeg.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:\Video\Web\FlvFile\User1\0001.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 "";
}
Pending issues:
Is that I can't capture the screenshot from the Ffmpeg.exe message ~
I do not know can see this log of the expert can have a way to obtain, I can only detect whether the picture is generated to judge the success, but the time is slow, because this test program let users to wait about 4, 5 seconds time.