欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
視頻格式轉化為FLV (C
        在上次隨筆 Asp.net FMS 開(kāi)發(fā)視頻網(wǎng)站 中,好多朋友提到其他視頻格式轉化成FLV格式的問(wèn)題,經(jīng)過(guò)網(wǎng)上搜索資料研習整理,現經(jīng)我的一點(diǎn)思路分享給大家:
        我添加了一個(gè)轉換FLV工程 VideoConvert:

         1。配置文件里添加
         

 1
 <appSettings>
 2

 3
    
<!--convert tools path-->
 4
    
<add key="FfmpegPath" value="D:\tools\"/>    
 5

 6
    
<!-- setting -->
 7
    
<add key="ThreadCount" value="5" />
 8
    
<add key="BatchSize" value="10" />
 9
    
<add key="QueueTimeout" value="20" />
10
    
<add key="TransactionTimeout" value="30" />
11
  
</appSettings>

        2。添加一個(gè)接口 

 1
using System;
 2
using System.Collections.Generic;
 3
using System.Text;
 4

 5
namespace VideoConvert
 6
{
 7
    
public interface IConvert
 8
    
{
 9

10
        
/// <summary>
11
        
/// 將視頻文件轉換為Flv格式
12
        
/// </summary>
13
        
/// <param name="sourceFile">要轉換的文件</param>
14
        
/// <returns></returns>

15
        bool Convert(string sourceFile);
16

17

18

19
        
/// <summary>
20
        
/// 獲取縮略圖
21
        
/// </summary>
22
        
/// <param name="sourceFile"></param>
23
        
/// <returns></returns>

24
        bool GetSmallImage(string sourceFile);
25
       
26

27
    }

28
}

29

3。轉換工具設定繼承 IConvert


 1
using System;
 2
using System.Collections.Generic;
 3
using System.Text;
 4
using System.Configuration;
 5

 6

 7
namespace VideoConvert
 8
{
 9
    
public class FfmpegConvert : IConvert
10
    
{
11

12

13
        
/// <summary>
14
        
/// 轉換軟件所在的路徑
15
        
/// </summary>

16
        private string ConvertTool = ConfigurationManager.AppSettings["FfmpegPath"+ "ffmpeg.exe";
17

18

19
        
/// <summary>
20
        
/// 構造函數
21
        
/// </summary>

22
        public FfmpegConvert()
23
        
{
24

25
        }

26

27

28
        
/// <summary>
29
        
/// 將視頻文件轉換為Flv格式
30
        
/// </summary>
31
        
/// <param name="sourceFile">要轉換的文件</param>
32
        
/// <returns></returns>

33
        public bool Convert(string sourceFile)
34
        
{
35
            
try
36
            
{
37
                
//文件名是否為空
38
                if (string.IsNullOrEmpty(sourceFile)) return false;
39
                
//檢測文件是否存在
40

41

42
                
string TargetFile = sourceFile.Substring(0, sourceFile.Length - 4+ ".flv";
43
                
string Argu = @"-i " + sourceFile + " -ab 56 -ar 22050 -b 500 -r 15 -s 480x360 " + TargetFile;
44

45
                System.Diagnostics.ProcessStartInfo startInfo 
= new System.Diagnostics.ProcessStartInfo(ConvertTool, Argu);
46
                System.Diagnostics.Process.Start(startInfo);
47
                System.Threading.Thread.Sleep(
6000);
48
                
return true;
49

50
            }

51
            
catch (Exception exp)
52
            
{
53
                
throw exp;
54
            }

55

56
        }

57

58

59
        
/// <summary>
60
        
/// 獲取縮略圖
61
        
/// </summary>
62
        
/// <param name="sourceFile"></param>
63
        
/// <returns></returns>

64
        public bool GetSmallImage(string sourceFile)
65
        
{
66

67
            
//文件名是否為空
68
            if (string.IsNullOrEmpty(sourceFile)) return false;
69
            
//檢測文件是否存在
70

71
            
try
72
            
{
73
                
string TargetFile = sourceFile.Substring(0, sourceFile.Length - 4+ ".jpg";
74
                
string Argu = @"-i " + sourceFile + " -y -f image2 -ss 08.010 -t 0.001 -s 352x240 " + TargetFile;
75
                System.Diagnostics.ProcessStartInfo startInfo 
= new System.Diagnostics.ProcessStartInfo(ConvertTool, Argu);
76
                System.Diagnostics.Process.Start(startInfo);
77
                System.Threading.Thread.Sleep(
6000);
78

79

80
                
//必須等待進(jìn)行完成后才能返回結果
81

82

83
                
return true;
84

85
            }

86
            
catch (Exception exp)
87
            
{
88
                
throw exp;
89
            }

90

91
        }

92

93
    }

94
}

95

   
4.


  1
using System;
  2
using System.Collections.Generic;
  3
using System.Configuration;
  4
using System.Text;
  5
using System.Threading;
  6
using System.Transactions;
  7
using VideoConvert;
  8

  9
namespace VideoConvert
 10
{
 11
    
class Program
 12
    
{
 13

 14
        
//threadCount 
 15
        private static int threadCount = int.Parse(ConfigurationManager.AppSettings["ThreadCount"]);
 16
           
 17
        
private static IConvert tool = new FfmpegConvert();
 18

 19
        
//finished count
 20
        private static int completeCount = 0;
 21

 22
        
static void Main(string[] args)
 23
        
{           
 24

 25

 26
            Thread workTicketThread;
 27
            Thread[] workerThreads 
= new Thread[threadCount];
 28

 29
            
for (int i = 0; i < threadCount; i++)
 30
            
{
 31

 32
                workTicketThread 
= new Thread(new ThreadStart(ProcessVideo));
 33

 34
                
// Make this a background thread, so it will terminate when the main thread/process is de-activated
 35
                workTicketThread.IsBackground = true;
 36
                workTicketThread.SetApartmentState(ApartmentState.STA);
 37

 38
                
// Start the Work
 39
                workTicketThread.Start();
 40
                workerThreads[i] 
= workTicketThread;
 41
            }

 42

 43
            Console.WriteLine(
"Converting begin. press Enter stop");
 44
            Console.ReadLine();
 45
            Console.WriteLine(
"cancel
");
 46

 47
            
//abort all threads
 48
            for (int i = 0; i < workerThreads.Length; i++)
 49
            
{
 50

 51
                workerThreads[i].Abort();
 52
            }

 53

 54
            Console.WriteLine();
 55
            Console.WriteLine(
" Processed" + completeCount + "video files");
 56
            Console.WriteLine(
" Process compeleted. press Enter to exit");
 57
            Console.ReadLine();
 58

 59

 60
        }

 61

 62

 63
        
/// <summary>
 64
        
/// Convert 
 65
        
/// </summary>
 66
        
/// <returns></returns>

 67
        private static void ProcessVideo()
 68
        

 69
            
 70

 71
            
while (true)
 72
            
{
 73
                
 74
                
 75
                                
 76
                    
if (!string.IsNullOrEmpty(waitConvertFile))
 77
                    
{
 78
                        
//Convert
 79
                        Console.WriteLine("start to convert file:" + waitConvertFile + "");
 80
                        
try
 81
                        
{
 82
                            
if (tool.Convert(waitConvertFile.PhysicalPath) && tool.GetSmallImage(waitConvertFile.PhysicalPath))
 83
                            
{
 84
                                completeCount
++;
 85

 86
                                
//Change waitConvertFile status if need
 87
                              
 88
                            }

 89
                        }

 90
                        
catch (Exception exp)
 91
                        
{
 92
                            
//setting Convert failure
 93
                            Console.WriteLine("文件" + waitConvertFile.VideoID + "Convert failure");
 94
                        }

 95
                        Console.WriteLine(
"文件" + waitConvertFile.VideoID + "Convert ending");
 96
                        Thread.Sleep(
1000);
 97
                    }

 98
                    Thread.Sleep(
1000 * 60);
 99

100
                             
101
                
102
                                 
103
              
104
            }
         
105

106
           
107
        }

108
    }

109
}

通過(guò)四步,我們視頻轉換工程就創(chuàng )建完了,這里的主要思路是服務(wù)器端調用視頻轉換工具 ffmpeg.exe,設置參數,通過(guò)Main來(lái)實(shí)現轉換。如果有問(wèn)題請和我聯(lián)系。
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
DotNet動(dòng)態(tài)創(chuàng )建類(lèi)
C#線(xiàn)程學(xué)習筆記七:Task詳細用法
C#中Timer使用及解決重入問(wèn)題
Youtube技術(shù)原理
C# 對文件與文件夾的操作 -- 刪除、移動(dòng)與復制
dotNET Core 3.X 依賴(lài)注入
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久