diff --git a/modelscope/pipelines/cv/video_super_resolution_pipeline.py b/modelscope/pipelines/cv/video_super_resolution_pipeline.py index 261f9bdb..87b73346 100644 --- a/modelscope/pipelines/cv/video_super_resolution_pipeline.py +++ b/modelscope/pipelines/cv/video_super_resolution_pipeline.py @@ -2,6 +2,8 @@ # originally Apache 2.0 License and publicly avaialbe at # https://github.com/ckkelvinchan/RealBasicVSR/blob/master/inference_realbasicvsr.py import math +import os +import subprocess import tempfile from typing import Any, Dict, Optional, Union @@ -140,6 +142,7 @@ class VideoSuperResolutionPipeline(Pipeline): def postprocess(self, inputs: Dict[str, Any], **kwargs) -> Dict[str, Any]: output_video_path = kwargs.get('output_video', None) + demo_service = kwargs.get('demo_service', True) if output_video_path is None: output_video_path = tempfile.NamedTemporaryFile(suffix='.mp4').name @@ -152,4 +155,13 @@ class VideoSuperResolutionPipeline(Pipeline): video_writer.write(img.astype(np.uint8)) video_writer.release() - return {OutputKeys.OUTPUT_VIDEO: output_video_path} + if demo_service: + assert os.system( + 'ffmpeg -version' + ) == 0, 'ffmpeg is not installed correctly, please refer to https://trac.ffmpeg.org/wiki/CompilationGuide.' + output_video_path_for_web = output_video_path[:-4] + '_web.mp4' + convert_cmd = f'ffmpeg -i {output_video_path} -vcodec h264 -crf 5 {output_video_path_for_web}' + subprocess.call(convert_cmd, shell=True) + return {OutputKeys.OUTPUT_VIDEO: output_video_path_for_web} + else: + return {OutputKeys.OUTPUT_VIDEO: output_video_path} diff --git a/tests/pipelines/test_video_super_resolution.py b/tests/pipelines/test_video_super_resolution.py index 1768df2c..0da18dd7 100644 --- a/tests/pipelines/test_video_super_resolution.py +++ b/tests/pipelines/test_video_super_resolution.py @@ -16,7 +16,7 @@ class VideoSuperResolutionTest(unittest.TestCase, DemoCompatibilityCheck): def setUp(self) -> None: self.task = Tasks.video_super_resolution self.model_id = 'damo/cv_realbasicvsr_video-super-resolution_videolq' - self.test_video = 'data/test/videos/000.mp4' + self.test_video = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/videos/000.mp4' @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') def test_run_by_direct_model_download(self):