2010-11-30 56 views
0

傢伙你好的東西,這是一個長鏡頭,但在這裏不用生成縮略圖...從桌面上多部影片,使用的ffmpeg,或類似

我基本上是我在我的服務器上運行的標題提及。當我上傳視頻時,ffmpeg會對其進行解壓縮並提供截圖,然後選擇我想用於該視頻的截圖。目前,我的服務器一次可以處理3個視頻。不利的一面是,這消耗了很多服務器處理能力。 :(

有沒有一種方法或程序可以一次處理多個視頻並在我的桌面上生成截圖?如果可以的話,我可以在這裏使用我的備用計算機來處理所有內容,然後上傳截圖/視頻到我的服務器。

這是我基本都在服務器上正在運行。kayweb.com.au/blogs/Web-Development/Generating-screenshots-using-FFmpeg

這樣的事情,但是這個縮略圖生成把一切都變成一個形象。我需要能夠選擇與縮略圖我想用 http://www.tothepc.com/archives/make-movie-caps-screenshots-with-free-video-thumbnails-maker/

任何人有任何建議?

+0

如何挑選特定視頻幀作爲縮略圖使用?選擇一個足夠好的隨機畫面,還是你想選擇一個最具代表性的視頻? – misha 2010-11-30 05:38:59

回答

0

獲取多個拇指的問題是時間。到目前爲止,我還沒有能夠從單次掃描中獲得多個大拇指,所以這意味着我必須對三個圖像進行三次掃描。

在我的情況下,我花了幾秒鐘的視頻時間,然後從1/4,1/2和3/4中獲得三個圖像。但對於長視頻來說,這太慢了,即使使用ffmpeg的偏移值。如果您可以從視頻的前10到20秒內進行選擇,則會更好。

因此,我從一個預處理開始,在文件搜索時掃描圖像,然後任何沒有創建的拇指創建一個從幾秒鐘到視頻,這是一個快速的過程並且在它自己的主題中並不是很明顯,除非有很多視頻需要圖標,所以第一次運行會很慢。

然後和函數形式一樣,如果拇指不是很好,我允許從我的3個大拇指中進行選擇,這些大拇指是動態生成的。就我而言,我使用MDI,因此我可以將媒體套件的各個部分結合在一起。所以下面的部分是它自己的一個表單,當用戶以另一種形式選擇一個目錄時,文件列表'videoList'已被填充。

只是爲了完整性,我將包括我的MediaItem和MediaType枚舉。

忽略我命名我的臨時文件的方式,我仍在處理這個問題,因爲我將在稍後提供名稱的服務。您可以使用C#中相同的文件來獲取問題,這些文件只是在外部進程中創建或修改的,所以您確實需要一些巧妙的文件使用約定。

public partial class ThumbSelector : Form 
{ 
    public List<MediaItem> videoList = new List<MediaItem>(); 
    private Random ra = new Random(); 
    int iCount = 1; 

    public ThumbSelector() 
    { 
     InitializeComponent(); 
    } 

    public void FillList() 
    { 
     if(videoList.Count() < 1) 
      return; 
     //only get mp4 files 
     var videosOnly = from n in videoList 
         where n.mainType == MediaMainType.MMT_VIDEO 
         select n; 
     lbVideoList.Items.Clear(); 
     foreach (MediaItem mi in videosOnly) 
     { 
      lbVideoList.Items.Add(mi.shortName); 
     } 
    } 

    private void lbVideoList_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if(lbVideoList.SelectedItems.Count < 1) 
      return; 
     CreateThumbs(lbVideoList.SelectedItems[0].ToString()); 
    } 

    private void CreateThumbs(string fShortName) 
    { 
     string sourceVideoName; 
     int sourceLength = 0; 
     int quarter = 0; 
     int half = 0; 
     int threequarter = 0; 
     string destDir = @"C:\Users\robert\dwhelper\VideoIcons"; 

     string ffPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\ffmpeg.exe"; 

     var sname = (from n in videoList 
        where n.shortName == fShortName 
        select n).First(); 
     sourceVideoName = sname.fullName; 
     sourceLength = GetVideoLength(ffPath, sourceVideoName); 

     quarter = sourceLength/4; 
     half = sourceLength/2; 
     threequarter = quarter * 3; 
     Image im1; 
     Image im2; 
     Image im3; 
     string n1; 
     string n2; 
     string n3; 


     while (File.Exists(string.Concat(destDir, @"\", "x1_", iCount.ToString(), ".jpg"))) 
     { 
      ++iCount; 
     } 
     n1 = string.Concat("x1_", iCount.ToString(), ".jpg"); 
     ++iCount; 
     while (File.Exists(string.Concat(destDir, @"\", "x2_", iCount.ToString(), ".jpg"))) 
     { 
      ++iCount; 
     } 
     n2 = string.Concat("x2_", iCount.ToString(), ".jpg"); 
     ++iCount; 
     while (File.Exists(string.Concat(destDir, @"\", "x3_", iCount.ToString(), ".jpg"))) 
     { 
      ++iCount; 
     } 
     n3 = string.Concat("x3_", iCount.ToString(), ".jpg"); 

     pic1.Image = null; 
     pic2.Image = null; 
     pic3.Image = null; 


     CreateThumbs(sname, quarter, n1); 
     im1 = Image.FromFile(string.Concat(destDir, @"\", n1)); 
     pic1.Image = im1; 
     CreateThumbs(sname, half, n2); 
     im2 = Image.FromFile(string.Concat(destDir, @"\", n2)); 
     pic2.Image = im2; 
     CreateThumbs(sname, threequarter, n3); 
     im3 = Image.FromFile(string.Concat(destDir, @"\", n3)); 
     pic3.Image = im3; 

    } 

    private void CreateThumbs(MediaItem mi, int timeIn, string outName) 
    { 
     this.Cursor = Cursors.WaitCursor; 
     Process pth; 
     string destDir = @"C:\Users\robert\dwhelper\VideoIcons"; 
     string sourceFile; 
     string destFile; 
     string ffPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\ffmpeg.exe"; 
     string strCommand; 
     string fullCommand; 
     string[] ssplit; 

     sourceFile = mi.fullName; 
     ssplit = mi.shortName.Split('.'); 
     destFile = string.Concat(destDir, "\\", outName); 

     strCommand = string.Concat(
      " -i \"", sourceFile, "\" -r 1 -ss ", timeIn.ToString(), " -t 00:00:01 -f image2 \"", destFile, "\""); 

     fullCommand = string.Concat(ffPath, strCommand); 

     pth = new Process(); 
     pth.StartInfo.FileName = ffPath; 
     pth.StartInfo.Arguments = strCommand; 
     pth.StartInfo.UseShellExecute = false; 
     pth.StartInfo.CreateNoWindow = true; 

     pth.Start(); 
     pth.WaitForExit(); 

     this.Cursor = Cursors.Default; 

    } 

    private int GetVideoLength(string ffmpeg, string sourceFile) 
    { 
     //exec('start C:\Inetpub\ffmpeg\ffmpeg -i "D:/Jaime-flex.wmv" 2>&1 | grep "Duration" | cut -d " " -f 4 - | sed s/,//', $output); 
     string result = ""; 
     string strCommand = string.Concat(
       " -i \"", sourceFile, "\" 2>"); 
     Process pth = new Process(); 
     pth.StartInfo.FileName = ffmpeg; 
     pth.StartInfo.Arguments = strCommand; 
     pth.StartInfo.UseShellExecute = false; 
     pth.StartInfo.CreateNoWindow = true; 
     pth.StartInfo.RedirectStandardOutput = true; 
     pth.StartInfo.RedirectStandardError = true; 
     pth.Start(); 


     pth.WaitForExit(); 
     //result = pth.StandardOutput.ReadToEnd(); 
     //result = pth.StandardError.ReadToEnd(); 
     string str = ""; 
     string[] ssplit; 
     char[] splitChars = new char[] { '.', ' ' }; 
     int seconds = 0; 
     while (!pth.StandardError.EndOfStream) 
     { 
      str = pth.StandardError.ReadLine(); 
      if (str.Contains("Duration")) 
      { 
       ssplit = str.Split(splitChars); 
       seconds = GetSeconds(ssplit[3]); 
      } 
     } 
     return seconds; 
    } 

    private int GetSeconds(string p) 
    { 
     string[] ssplit = p.Split(':'); 
     int ho = Convert.ToInt32(ssplit[0]) * 120; 
     int mi = Convert.ToInt32(ssplit[1]) * 60; 
     int se = Convert.ToInt32(ssplit[2]); 

     return ho + mi + se; 
    } 

} 
public class MediaItem 
{ 
    public string shortName { get; set; } 
    public string fullName { get; set; } 
    public string iconName { get; set; } 
    public MediaMainType mainType { get; set; } 
    public MediaSubType subType { get; set; } 
    public long length { get; set; } 
} 
public enum MediaMainType 
{ 
    MMT_VIDEO = 0, MMT_IMAGE, MMT_ICON, MMT_NOTMEDIA 
} 
public enum MediaSubType 
{ 
    MST_JPG = 0, MST_GIF, MST_BMP, MST_PNG, MST_MP4, MST_WMV, MST_FLV, MST_NOTMEDIA 
3 
相關問題