2010-11-30 3 views
0

こんにちはみんな。ビデオをアップロードすると、ffmpegがそれを分解してスクリーンショットを表示し、そのビデオに使用したいスクリーンショットを選択します。現在、私のサーバーは一度に3つのビデオを処理できます。欠点は、これがサーバー処理能力の多くを使い果たしていることです。 :(は、私は基本的に私は私のサーバー上で実行されているタイトルに言及したものを持っている...これはロングショットですが、ここに行く</p> <p>を、デスクトップ上の複数の動画からサムネイルを生成ffmpegのを使用して、または類似した何か

一度に複数のビデオを処理して私のデスクトップ上にスクリーンショットを生成する方法やプログラムはありますか?これが可能であれば、ここで私のスペアのコンピュータを使用してすべてを処理し、スクリーンショット/私のサーバーへのビデオ。

これは、私は基本的にサーバ上で今実行したものである。このような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

+0

問題点を正確に明確にすることはできますか? ffmpegはあなたを助けているようですが、時間がかかりすぎます。問題がffmpegが生成するファイルの数であれば、おそらくそれを制限することができます。 – korbes

答えて

0

複数の親指を取得する際の問題は時間です。これまで私は1回のスキャンで複数の親指を得ることができなかったので、3つの画像に対して3回スキャンする必要があります。

私の場合、私はビデオの時間を数秒でとり、1/4,1/2,3/4から3つの画像を得ました。しかし、長い動画の場合、これはffmpegのオフセット値を使用しても非常に遅いです。最初の10〜20秒のうちからビデオを選択できる方が良いです。

私は前処理から始めます。これはファイル検索時に画像をスキャンし、親指を作成していないものは数秒間で作成します。これは簡単な処理ですアイコンが必要なビデオがたくさんある場合を除いて、それ自体のスレッドでは目立たないので、最初の実行は遅くなります。

関数フォームと同様に、親指がうまくない場合は、オンザフライで生成された3つの親指から選択を許可します。私の場合はMDIを使用していましたので、メディアスイートのさまざまな部分を一緒に結婚することができました。したがって、下の部分は独自のフォームです。ファイルリスト 'videoList'は、ユーザーが別のフォームでディレクトリを選択したときに入力されました。

完全性のために、MediaItemとMediaTypeの列挙型を含めます。

私は自分の一時ファイルに名前を付けたやり方を無視して、後でその名前を提供するサービスと結婚するので、私はまだ作業中です。 C#では、外部プロセスで作成または変更された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 
関連する問題

 関連する問題