Updated test and added check on conversion size
authorThierry Florac <thierry.florac@onf.fr>
Tue, 08 Sep 2015 17:01:39 +0200
changeset 9 7c73df1106b4
parent 8 e42e04460e14
child 10 9296741c1470
Updated test and added check on conversion size
src/pyams_media/process.py
--- a/src/pyams_media/process.py	Tue Sep 08 17:01:11 2015 +0200
+++ b/src/pyams_media/process.py	Tue Sep 08 17:01:39 2015 +0200
@@ -92,14 +92,18 @@
                 # extract converter output
                 logger.debug("Starting conversion process for {0!r} to {1}".format(media, media_format))
                 manager = ITransactionManager(media)
-                for loop, conversion in converter.convert(media):
-                    logger.debug("Finished FFmpeg conversion process. {0} bytes output".format(len(conversion)))
+                for width, conversion in converter.convert(media):
+                    logger.debug("Finished FFmpeg conversion process to {0}, {1} bytes output".format(media_format,
+                                                                                                      len(conversion)))
                     # add conversion in a transaction attempts loop
-                    for attempt in manager.attempts():
-                        with attempt as t:
-                            IMediaConversions(media).add_conversion(conversion, media_format, converter.format, loop)
-                        if t.status == 'Committed':
-                            break
+                    if len(conversion) > 0:
+                        for attempt in manager.attempts():
+                            with attempt as t:
+                                IMediaConversions(media).add_conversion(conversion, media_format, converter.format, width)
+                            if t.status == 'Committed':
+                                break
+                    else:
+                        logger.warning("Finished FFmpeg conversion process with **NO OUTPUT** !!!")
         finally:
             if manager is not None:
                 manager.abort()
@@ -129,11 +133,12 @@
 
     def test(self, settings):
         messages = ['Conversion process ready to handle requests.']
-        ffmpeg = shutil.which('ffmpeg')
-        if ffmpeg is None:
-            messages.append("WARNING: missing 'ffmpeg' command!")
-        else:
-            messages.append("'ffmpeg' command is available.")
+        for command in ('ffmpeg', 'ffprobe'):
+            whereis = shutil.which(command)
+            if whereis is None:
+                messages.append("WARNING: missing required command '{0}'!".format(command))
+            else:
+                messages.append("Required command '{0}' is available.".format(command))
         return [200, '\n'.join(messages)]