1
protected void Button1_Click(object sender, EventArgs e)
2
{
3
string FFmpegArguments = @" -i D:\离歌.wmv -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 D:\离歌.flv ";
4
//ProcessStartInfo info = new ProcessStartInfo("D:/ffmpeg/ffmpeg", FFmpegArguments);
5
//Process.Start(info);
6
7
Process p = new Process(); //Process類有一個StartInfo屬性,這個是ProcessStartInfo類,包括了一些屬性和方法,下面我們用到了他的幾個屬性:
8
p.StartInfo.FileName = "D:/ffmpeg/ffmpeg.exe";//設定程序名
9
p.StartInfo.Arguments = FFmpegArguments; //設定程式執行參數
10
p.StartInfo.UseShellExecute = false; //關閉Shell的使用
11
p.StartInfo.RedirectStandardInput = true; //重定向標準輸入
12
p.StartInfo.RedirectStandardOutput = true; //重定向標準輸出
13
p.StartInfo.RedirectStandardError = true; //重定向錯誤輸出
14
p.StartInfo.CreateNoWindow = true; //設置不顯示窗口
15
p.Start(); //啟動
16
//p.StandardInput.WriteLine(FFmpegArguments);//也可以用這種方式輸入要執行的命令
17
//p.StandardInput.WriteLine("exit"); //不過要記得加上Exit要不然下一行程式執行的時候會當機
18
}
19
20
/// 视频(avi,mov等等格式)转换为flv格式视频
21
/// </summary>
22
/// <param name="FromName">被转换的视频文件</param>
23
/// <param name="ExportName">转换flv后的文件名</param>
24
/// <param name="ExportName">视频大小的尺寸</param>
25
/// <returns></returns>
26
public string VideoConvertFlv(string FromName,string ExportName,string WidthAndHeight)
27
{
28
string ffmpeg=@"D:\ffmpeg\ffmpeg.exe";
29
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
30
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
31
//startInfo.Arguments = " -i " + Server.MapPath(FromName) + " -ab 56 -ar 22050 -b 500 -r 15 -s "+WidthAndHeight+" "+Server.MapPath(ExportName);
32
startInfo.Arguments = " -i " + FromName + " -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + " " + ExportName;
33
try
34
{
35
System.Diagnostics.Process.Start(startInfo);
36
return ExportName;
37
}
38
catch(Exception err)
39
{
40
return err.Message;
41
}
42
}
43
44
/// <summary>
45
/// 从视频画面中截取一帧画面为图片
46
/// </summary>
47
/// <param name="VideoName">视频文件pic/guiyu.mov</param>
48
/// <param name="WidthAndHeight">图片的尺寸如:240*180</param>
49
/// <param name="CutTimeFrame">开始截取的时间如:"1"</param>
50
/// <returns></returns>
51
public string GetPicFromVideo(string VideoName,string WidthAndHeight,string CutTimeFrame)
52
{
53
54
string ffmpeg=@"C:Inetpubwwwrootdemopic fmpeg.exe";
55
string PicName =Server.MapPath(Guid.NewGuid().ToString().Replace("-","")+".jpg");
56
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
57
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
58
startInfo.Arguments = " -i " + Server.MapPath(VideoName) + " -y -f image2 -ss "+CutTimeFrame+" -t 0.001 -s " + WidthAndHeight + " " + PicName ;
59
try
60
{
61
System.Diagnostics.Process.Start(startInfo);
62
return PicName;
63
}
64
catch(Exception err)
65
{
66
return err.Message;
67
}
68
}

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68
