mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
save a video with h264 vcodec for video_super_resolution pipeline
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/11327516
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user