2011-07-17 44 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