2011-07-17 42 views
0

我是一個很長的視頻流,但不幸的是,它的形式是1000個15秒長的隨機命名剪輯。我想根據兩個15s剪輯的「相似度」來重建原始視頻,這回答了「剪輯2中的活動看起來像剪輯1的擴展」的問題。剪輯之間有很小的差距---幾百毫秒左右。如果它們足夠好,我也可以手動修復結果,所以結果不一定是完美的。確定連續的視頻剪輯

+0

這些文件是什麼格式? –

+0

剪輯1的結尾是否與剪輯2的開始有關,反之亦然? –

+0

加里:是的,剪輯只是被切碎,但相應的結束和開始幀應該非常接近。 lou:重要嗎?我可以將它們轉碼成ffmpeg支持的任何東西。 – pavpanchekha

回答

0

一個非常簡單的方法可以是:

的(a)創建一個自動過程來提取每個視頻剪輯的第一和最後幀在已知的圖像格式(例如JPG),並根據它們命名視頻剪輯名稱,例如如果你有視頻剪輯:

clipA.avi,clipB.avi,clipC.avi

您可以創建以下幀圖像:

clipA_first.jpg,clipA_last.jpg,clipB_first.jpg ,clipB_last.jpg,clipC_first.jpg,clipC_last.jpg

(b)中分選 「算法」:

1. Create a 'Clips' list of Clip-Records containing each: 

(a) clip-name (string) 
(b) prev-clip-name (string) 
(c) prev-clip-diff (float) 
(d) next-clip-name (string) 
(e) next-clip-diff (float) 

2. Apply the following processing: 

for Each ClipX having ClipX.next-clip-name == "" do: 
{ 
    ClipX.next-clip-diff = <a big enough number>; 
    for Each ClipY having ClipY.prev-clip-name == "" do: 
    { 
     float ImageDif = ImageDif(ClipX.last-frame.jpg, ClipY.first_frame.jpg); 
     if (ImageDif < ClipX.next-clip-diff) 
     { 
      ClipX.next-clip-name = ClipY.clip-name; 
      ClipX.next-clip-diff = ImageDif; 
     } 
    } 
    Clips[ClipX.next-clip-name].prev-clip-name = ClipX.clip-name; 
    Clips[ClipX.next-clip-name].prev-clip-diff = ClipX.next-clip-diff; 
} 

3. Scan the Clips list to find the record(s) with no <prev-clip-name> or 
    (if all records have a <prev-clip-name> find the record with the max <prev-clip-dif>. 
    This is a good candidate(s) to be the first clip in sequence. 

4. Begin from the clip(s) found in step (3) and rename the clip-files by adding 
    a 5 digits number (00001, 00002, etc) at the beginning of its filename and going 
    from aClip to aClip.next-clip-name and removing the clip from the list. 

5. Repeat steps 3,4 until there are no clips in the list. 

6. Voila! You have your sorted clips list in the form of sorted video filenames! 
    ...or you may end up with more than one sorted lists (if you have enough 
    'time-gap' between your video clips). 

非常簡單...但我認爲它可以有效的...

PS1:關於ImageDif()函數:您可以創建一個新的DifImage,這是圖片ClipX.last幀的區別.jpg,ClipY.first_frame.jpg,然後將DifImage的所有像素合計爲單個浮點值ImageDif value。如果總和大於某個限制,您還可以優化流程以中止差異(或總和流程):您實際上對小差異感興趣。大於(實驗)限制的值意味着2個圖像差別很大,以至於2個剪輯不能彼此相鄰。 PS2:複雜度的排序算法順序必須大約爲O(n * log(n)),因此對於1000個視頻剪輯,它將執行大約3000個圖像比較(或者如果您優化算法並且允許它找不到一些剪輯匹配)

+0

ImageDiff的實現是關鍵。簡單地減去圖像不起作用,因爲相機可能正在平移。 – pavpanchekha

+0

如果相機平移速度非常快,或者您有相當數量的時間間隔,它可能無法正常工作,但對於正常的幀序列,它可能足以爲您提供正確的序列。請記住:我們對零差異不感興趣,但差異很小。我認爲測試這個的唯一方法是部分實現它:手動提取2幀(在它們之間有0,1,2,3幀)並手動計算差異以查看DifImage的外觀。 –

+0

是的,我試過了---差距可能是幾百毫秒,所以這真的會引起差異。在這些間隙中相機關閉,有些還有時會出現色彩平衡問題。 – pavpanchekha