google-research
39 строк · 1.1 Кб
1# coding=utf-8
2# Copyright 2024 The Google Research Authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""utils for writing video."""
17import base6418import io19import re20import PIL21import skvideo.io22
23
24def get_writer(file_name, frame_rate=30, pix_fmt='yuv420p', vcodec='libx264'):25rate = str(frame_rate)26inputdict = {'-r': rate}27outputdict = {28'-pix_fmt': pix_fmt,29'-r': rate,30'-vcodec': vcodec,31}32writer = skvideo.io.FFmpegWriter(file_name, inputdict, outputdict)33return writer34
35
36def save_image(url, path):37data = re.sub('^data:image/.+;base64,', '', url)38image = PIL.Image.open(io.BytesIO(base64.b64decode(data)))39image.save(path)40