]> git.parisson.com Git - promaster.git/commitdiff
make a better class
authoryomguy <yomguy@parisson.com>
Thu, 13 Dec 2012 20:03:30 +0000 (21:03 +0100)
committeryomguy <yomguy@parisson.com>
Thu, 13 Dec 2012 20:03:30 +0000 (21:03 +0100)
auto_fade.py
kdenlive/fade.py

index 6a0e639c76eda770465a41063d549bdf63523da6..691c5ff4702ab0446201e59639bae6ff56e75651 100644 (file)
@@ -1,10 +1,16 @@
 
 import sys
-from kdenlive.fade import KdenliveAutoFade
+from kdenlive.fade import AutoFade
+from tempfile import TemporaryFile
+
 
 if __name__ == '__main__':
     path_out = sys.argv[-1]
     path_in = sys.argv[-2]
-    fade = KdenliveAutoFade()
-    fade.run(path_in, path_out)
+
+    fade = AutoFade(path_in)
+    data = fade.run()
+    f = open(path_out, 'w')
+    f.write(data)
+    f.close()
 
index 82165efa1a45ea3d9e511e5f4e0dea5f18f89e5e..c1f14115831d71f32e494aa2e7732783f9f25067 100644 (file)
 from xmltodict2 import *
 
 
-class KdenliveAutoFade(object):
+class AutoFade(object):
+    """ Automatically applies a fade in and a fade out trasitions between each segment of a KdenLive session.
+        Each video clip needs to be splitted into one video track and an audio one ("Split audio"),
+        so that an audio fade in/out is also applied.
 
-    def __init__(self):
-        self.n_frames = 2
+        MLT files are also supported.
+    """
+
+    def __init__(self, path, frames=3):
+        self.frames = frames
+        self.path = path
+        self.session = xmltodict(self.path)
 
     def audio_fade_in(self, frame_out):
         child = {'attributes': {u'id': u'fadeout',
-        u'in': unicode(int(frame_out)-self.n_frames),
+        u'in': unicode(int(frame_out)-self.frames),
         u'out': unicode(frame_out)},
        'children': [{'attributes': {u'name': u'track'},
          'cdata': '0',
@@ -65,7 +73,7 @@ class KdenliveAutoFade(object):
     def audio_fade_out(self, frame_in):
         child = {'attributes': {u'id': u'fadein',
         u'in': unicode(frame_in),
-        u'out': unicode(int(frame_in)+self.n_frames)},
+        u'out': unicode(int(frame_in)+self.frames)},
        'children': [{'attributes': {u'name': u'track'},
          'cdata': '0',
          'name': 'property'},
@@ -99,7 +107,7 @@ class KdenliveAutoFade(object):
 
     def video_fade_in(self, frame_out):
         child = {'attributes': {u'id': u'fade_to_black',
-        u'in': unicode(int(frame_out)-self.n_frames),
+        u'in': unicode(int(frame_out)-self.frames),
         u'out': unicode(frame_out)},
        'children': [{'attributes': {u'name': u'track'},
          'cdata': '0',
@@ -129,7 +137,7 @@ class KdenliveAutoFade(object):
     def video_fade_out(self, frame_in):
         child = {'attributes': {u'id': u'fade_from_black',
         u'in': unicode(frame_in),
-        u'out': unicode(int(frame_in)+self.n_frames)},
+        u'out': unicode(int(frame_in)+self.frames)},
        'children': [{'attributes': {u'name': u'track'},
          'cdata': '0',
          'name': 'property'},
@@ -154,12 +162,11 @@ class KdenliveAutoFade(object):
 
         return child
 
-    def run(self, path_in, path_out):
+    def run(self):
         audio_count = 0
         video_count = 0
 
-        d = xmltodict(path_in)
-        for attr in d['children']:
+        for attr in self.session['children']:
             if 'playlist' in attr['name'] and 'children' in attr:
                 for att in attr['children']:
                     if 'producer' in att['attributes']:
@@ -183,9 +190,6 @@ class KdenliveAutoFade(object):
                                     att['children'] = [self.video_fade_out(frame_in)]
                                 video_count += 1
 
-        data = dicttoxml(d)
-        f = open(path_out, 'w')
-        f.write(data.encode('utf-8'))
-        f.close()
+        return dicttoxml(self.session).encode('utf-8')