Add choice of video resolutions for instance owner
authorvijeth-aradhya <vijthaaa@gmail.com>
Tue, 20 Jun 2017 11:58:34 +0000 (17:28 +0530)
committervijeth-aradhya <vijthaaa@gmail.com>
Tue, 20 Jun 2017 11:58:34 +0000 (17:28 +0530)
The instance owner can choose from the list of available resolutions.
['144p', '240p', '360p', '480p', '720p', '1080p']
Also, the default resolution is now set to 480p and the instance owner
can choose the default resolution from that list as well.

mediagoblin/media_types/video/config_spec.ini
mediagoblin/media_types/video/processing.py

index 98714f56ce48e9caa98d9b7462e4e414cda6e902..e899eff53160032e8eb225f75272731a2cb01453 100644 (file)
@@ -12,6 +12,14 @@ vorbis_quality = float(default=0.3)
 # Autoplay the video when page is loaded?
 auto_play = boolean(default=False)
 
+# List of resolutions that the video should be transcoded to
+# Choose among ['144p', '240p', '360p', '480p', '720p', '1080p'],
+# preferrably in the order of transcoding.
+available_resolutions = string_list(default=list('480p', '360p', '720p'))
+
+# Default resolution of video
+default_resolution = string(default='480p')
+
 [[skip_transcode]]
 mime_types = string_list(default=list("video/webm"))
 container_formats = string_list(default=list("Matroska"))
index 4da1ad23387600595fb26fe1b7a270a958ab8e2d..2a6a716f0fcc6cbe9976400529e8404f10958fe8 100644 (file)
@@ -549,6 +549,10 @@ class VideoProcessingManager(ProcessingManager):
 
     def workflow(self, entry, feed_url, reprocess_action, reprocess_info=None):
 
+        video_config = mgg.global_config['plugins'][MEDIA_TYPE]        
+        def_res = video_config['default_resolution']
+        priority_num = len(video_config['available_resolutions']) + 1
+
         entry.state = u'processing'
         entry.save()
 
@@ -562,18 +566,22 @@ class VideoProcessingManager(ProcessingManager):
         if 'thumb_size' not in reprocess_info:
             reprocess_info['thumb_size'] = None
 
-        transcoding_tasks = group([
-            main_task.signature(args=(entry.id, '480p', ACCEPTED_RESOLUTIONS['480p']),
-                                kwargs=reprocess_info, queue='default',
-                                priority=5, immutable=True),
-            complimentary_task.signature(args=(entry.id, '360p', ACCEPTED_RESOLUTIONS['360p']),
-                                         kwargs=reprocess_info, queue='default',
-                                         priority=4, immutable=True),
-            complimentary_task.signature(args=(entry.id, '720p', ACCEPTED_RESOLUTIONS['720p']),
-                                         kwargs=reprocess_info, queue='default',
-                                         priority=3, immutable=True),
-        ])
-
+        tasks_list = [main_task.signature(args=(entry.id, def_res,
+                                          ACCEPTED_RESOLUTIONS[def_res]),
+                                          kwargs=reprocess_info, queue='default',
+                                          priority=priority_num, immutable=True)]
+
+        for comp_res in video_config['available_resolutions']:
+            if comp_res != def_res:
+                priority_num += -1
+                tasks_list.append(
+                    complimentary_task.signature(args=(entry.id, comp_res,
+                                                 ACCEPTED_RESOLUTIONS[comp_res]),
+                                                 kwargs=reprocess_info, queue='default',
+                                                 priority=priority_num, immutable=True)
+                )
+
+        transcoding_tasks = group(tasks_list)
         cleanup_task = processing_cleanup.signature(args=(entry.id,),
                                                     queue='default', immutable=True)