Previous companies are making a podcast System (WebProgram), Used from the video function.
Below is the catchimg method, which can be successfully obtained from most video files. You can test it;
If the video fails, it is mostly due to video problems, such as encoding standards or encryption.
However, no failure has been found in the FLV file of the online recording video;
/// <Summary>
/// @ From the video file, generated in the folder where the video file is located
/// Two pre-configuration items are required in Web. config:
/// 1.ffmpeg.exe file path
/// <Add key = "FFMPEG" value = "E: \ FFMPEG \ ffmpeg.exe"/>
/// 2. Size
/// <Add key = "catchflvimgsize" value = "240x180"/>
/// 3.video processing program ffmpeg.exe
/// </Summary>
/// <Param name = "vfilename"> video file address, for example,/web/flvfile/user1/pai1.flv</param>
/// <Returns> success: the virtual address of the image is returned; Failure: An empty string is returned. </returns>
Public String catchimg (string vfilename)
{
// Obtain the path of ffmpeg.exe. The path is configured in Web. config, for example, <add key = "FFMPEG" value = "E: \ FFMPEG \ ffmpeg.exe"/>
String FFMPEG = system. configuration. configurationsettings. deleettings ["FFMPEG"];
If ((! System. Io. file. exists (FFMPEG) | (! System. Io. file. exists (vfilename )))
{
Return "";
}
// Obtain the relative path of the image/the path stored in the database, for example,/web/flvfile/user1/snapshot 1.jpg
String flv_img = system. Io. Path. changeextension (vfilename, ". jpg ");
// Absolute path of the image, for example, D: \ video \ WEB \ flvfile \ user1 \ 0001.jpg
String flv_img_p = httpcontext. Current. server. mappath (flv_img );
// Configure the size in Web. config, for example, <add key = "catchflvimgsize" value = "240x180"/>
String flvimgsize = system. configuration. configurationsettings. receivettings ["catchflvimgsize"];
System. Diagnostics. processstartinfo startinfo = new system. Diagnostics. processstartinfo (FFMPEG );
Startinfo. windowstyle = system. Diagnostics. processwindowstyle. hidden;
// This part combines the parameters required by the ffmpeg.exe file. The command passes
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 image is intercepted successfully, it takes a long time to write data from the memory cache to the disk, which may take 3, 4 seconds or longer;
/// This operation requires latency before detection. My server latency is 8 seconds. That is, if the image does not exist for more than 8 seconds, it is considered as a failure;
/// The latency is omitted hereCode.If there is a message indicating how to catch ffmpeg.exe failure, please let me know. Thank you!
If (system. Io. file. exists (flv_img_p ))
{
Return flv_img;
}
Return "";
}
Naturally, I cannot catch the failed message from ffmpeg.exe ~
I wonder if you can find a way to achieve this. Currently, I can only check whether the image is generated to determine whether it is successful or not, but the time is slow, because this detection program allows users to wait about 4 or 5 seconds.
ArticleSource: http://wangjikun3.bokee.com/viewdiary.23403120.html