]> git.parisson.com Git - telemeta.git/commitdiff
fix kdenlive marker parsing (for 1 producer id only)
authoryomguy <yomguy@parisson.com>
Thu, 7 Feb 2013 09:54:09 +0000 (10:54 +0100)
committeryomguy <yomguy@parisson.com>
Thu, 7 Feb 2013 09:54:09 +0000 (10:54 +0100)
telemeta/forms/media.py
telemeta/util/kdenlive/session.py

index 2fec286e95f5afed77f36b0aac05abf0a912c425..0a902734c0c6e34aadbe235a3d374c3d0efd49c0 100644 (file)
@@ -47,7 +47,8 @@ class MediaFondsRelatedForm(ModelForm):
         model = MediaFondsRelated
 
 class MediaCorpusForm(ModelForm):
-    children = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple, queryset=MediaCollection.objects.all())
+    children = forms.ModelMultipleChoiceField(widget=forms.CheckboxSelectMultiple,
+                                              queryset=MediaCollection.objects.all())
 
     class Meta:
         model = MediaCorpus
index 2b726acf6878382e17a00dc5372878ee424b095b..f50812d0ec9878be93c49a1ab3222f00b6160bd9 100644 (file)
@@ -53,6 +53,23 @@ class KDEnLiveSession(object):
        def entries_sorted(self):
                return sorted(self.entries(), key=lambda k: int(k['in']), reverse=False)
 
+       def entries_video_seconds(self):
+               fps = float(self.profile()['frame_rate_num'])
+               entries = []
+               for entry in self.entries_sorted():
+                       if 'video' in entry['producer']:
+                               entries.append({'in': int(entry['in'])/fps, 'out': int(entry['out'])/fps })
+               return entries
+
+       def cuts(self, entries):
+               i = 0
+               cuts = [0, ]
+               for entry in entries:
+                       if i > 0:
+                               cuts.append(cuts[i-1] + int(entries[i]['in'])-int(entries[i-1]['out']))
+                       i += 1
+               return cuts
+
        def first_video_frame(self):
                return int(self.entries_sorted()[0]['in'])
 
@@ -65,13 +82,27 @@ class KDEnLiveSession(object):
                markers = []
                fps = float(self.profile()['frame_rate_num'])
                first_frame_seconds = self.first_video_frame()/fps
+               entries = self.entries_video_seconds()
+               cuts = self.cuts(entries)
+
                for attr in self.session['children']:
                        if 'kdenlivedoc' in attr['name']:
                                for att in attr['children']:
                                        if 'markers' in att['name'] and 'children' in att.keys():
                                                for at in att['children']:
                                                        if 'marker' in at['name']:
-                                                               time = float(at['attributes']['time'].replace(',','.')) - first_frame_seconds
+                                                               time = float(at['attributes']['time'].replace(',','.'))
+                                                               j = 0
+                                                               offset = 0
+                                                               for entry in entries:
+                                                                       if time > entry['in'] and time < entry['out']:
+                                                                               if j != 0:
+                                                                                       offset = cuts[j]
+                                                                                       break
+                                                                       j += 1
+                                                               time = time - entries[0]['in'] - offset
                                                                at['attributes']['time'] = time
                                                                markers.append(at['attributes'])
+
                return markers
+