该项目是草稿,不打算任何人使用。
vtcff是一个库,用于在视频格式之间转码,重点是保持视频生产管道中的质量和色彩深度。在录音室任务中,视频秒占据了千兆字节,而质量妥协是最不可取的。
vtcff倾向于最大化质量,牺牲速度和磁盘空间。
vtcff实际上是ffmpeg的包装器,这是有史以来最不直观的视频工具。
$ pip3 install vtcff此命令将安装软件包,但不能安装FFMPEG本身。
$ pip3 install git+https://github.com/rtmigo/vtcff_py@staging#egg=vtcff import subprocess
from vtcff import FfmpegCommand , Scale , Transpose , Hevc
cmd = FfmpegCommand ()
cmd . src_file = '/path/to/source.mov'
cmd . dst_file = '/path/to/target.mov'
# set set some filters
cmd . scale = Scale ( 1920 , 1080 )
cmd . transpose = Transpose . CLOCKWISE
# set compression format
cmd . dst_codec_video = Hevc ( mbps = 100 )
# run command
subprocess . check_call ( list ( cmd )) import subprocess , os
from vtcff import FfmpegCommand , Prores
cmd = FfmpegCommand ()
cmd . src_file = 'source.mov'
cmd . dst_file = 'target.mov'
cmd . dst_codec_video = Prores ()
print ( str ( cmd ))
# ffmpeg -i source.mov -codec:v prores_ks target.mov
print ( list ( cmd ))
# ['ffmpeg', '-i', 'source.mov', '-codec:v', 'prores_ks', 'target.mov']
# running in different ways:
os . system ( str ( cmd ))
subprocess . run ( list ( cmd ))该对象允许您手动指定FFMPEG参数。以这种方式给出的参数优先于对象生成的参数。
from vtcff import FfmpegCommand
cmd = FfmpegCommand ()
# set arguments as string
cmd . custom . video . string = "-codec:v libx265"
cmd . custom . video . string += "-x265-params lossless=1"
# or as list
cmd . custom . video . list = [ "-codec:v" , "libx265" ]
cmd . custom . video . list . extend ([ "-x265-params" , "lossless=1" ]) cmd.custom包含四个字段,可以独立修改。
在-i source之前要插入的论点:
custom.before_i -i source要插入的论点:
custom.after_icustom.videocustom.audioffmpeg有两个用于颜色和框架尺寸转换的视频过滤器:
scale (libswscale)更通用zscale (Zimg)提供了更可预测的质量默认情况下, vtcff使用zscale 。有时可能会导致错误“色彩空间之间没有路径”。如果其他方法无济于事,则可以简单地用scale替换zscale 。
cmd.use_zscale == True表示使用zscalecmd.use_zscale == False Means使用scale from vtcff import FfmpegCommand , Scale
cmd = FfmpegCommand ()
assert cmd . use_zscale == True # by default, it's 'zscale' (zimg)
cmd . use_zscale = False # switching to 'scale' (libswscale)
# properties affected:
cmd . scale = Scale ( 1920 , 1080 )
cmd . src_color_space = 'bt709'
cmd . dst_color_space = 'bt2020ncl'
cmd . src_range_full = True
cmd . dst_range_full = False use_zscale=True ,意味着zimg将用于由对象属性明确设置的转换。这很好,因为这些转换将是高质量的。
但是,也可能需要隐式转换。例如,在使用zscale处理16位PNG之前,我们需要将像素格式从rgba64be转换为gbrap16le 。无论使用use_zscale属性如何,FFMPEG都将使用libswscale自动进行。
from vtcff import FfmpegCommand , Scale , Crop
# crop 10 pixels, then scale
a = FfmpegCommand ()
a . crop = Crop ( left = 10 )
a . scale = Scale ( 1920 , 1080 )
# scale, then crop 10 pixels
b = FfmpegCommand ()
b . scale = Scale ( 1920 , 1080 )
b . crop = Crop ( left = 10 ) from vtcff import FfmpegCommand , Scale
cmd = FfmpegCommand ()
# set height to 1080, automatically compute width
cmd . scale = Scale ( - 1 , 1080 )
# set height to 1080, select the width as the closest factor
# of two to the proportional size
cmd . scale = Scale ( - 2 , 1080 ) from vtcff import FfmpegCommand
cmd = FfmpegCommand ()
# Full/Data/PC range to Limited/Video/TV
cmd . src_range_full = True
cmd . dst_range_full = False
# rec.709 to rec.2020
cmd . src_color_space = 'bt709'
cmd . dst_color_space = 'bt2020ncl' from vtcff import FfmpegCommand , Prores , ProresProfile
cmd = FfmpegCommand ()
# by default it will encode to ProRes 4:2:2
cmd . dst_codec_video = Prores ()
# encode to ProRes 4:2:2 HQ instead
cmd . dst_codec_video = Prores ( profile = ProresProfile . HQ ) from vtcff import FfmpegCommand , Hevc , VcPreset
cmd = FfmpegCommand ()
# ideal quality
cmd . dst_codec_video = Hevc ( lossless = True )
# best for bitrate quality
cmd . dst_codec_video = Hevc ( near_lossless = True , mbps = 100 )
# default quality
cmd . dst_codec_video = Hevc ( mbps = 100 )
# all modes can be tweaked with optional speed presets:
cmd . dst_codec_video = Hevc ( mbps = 100 ,
preset = VcPreset . N7_SLOW )默认情况下, near_lossless设置为最慢的VcPreset.N10_PLACEBO ,因为我们正在尝试最大程度地提高质量。您可能需要选择更快的预设,以便结果在一生之内出现。
默认情况下, lossless设置为最快的VcPreset.N1_ULTRAFAST ,因为我们在这里不会失去任何质量。所得的大小将与PRORES HQ/XQ大致相当,并且编码时间合理。
可以在不重新编码的情况下复制媒体流,而不会造成质量损失。
但是,可能会损失元数据 - 例如,有关颜色范围和颜色空间的信息。
from vtcff import FfmpegCommand , VideoCopy , NoAudio
cmd = FfmpegCommand ()
# changing container from mp4 to mov
cmd . src_file = "source.mp4"
cmd . dst_file = "source.mov"
# keeping video, removing audio
cmd . dst_codec_video = VideoCopy ()
cmd . dst_codec_audio = NoAudio ()将时间表或CGI框架序列转换为PRORES VIDEO文件。
import subprocess
from vtcff import FfmpegCommand , Prores , ProresProfile
cmd = FfmpegCommand ()
# input directory will be automatically transformed
# to a pattern like '/my/dir_with_frames/img_%04.png'
cmd . src_file = '/my/dir_with_frames'
cmd . src_fps = 29.97
cmd . dst_file = '/videos/timelapse.mov'
cmd . dst_codec_video = Prores ( profile = ProresProfile . HQ )
# images usually have Full/Data/PC color range,
# but most NLEs assume that videos have Limited/Video/TV range
cmd . src_range_full = True
cmd . dst_range_full = False
# we will treat sRGB like Rec.709,
# although it's a little sad
cmd . src_color_space = 'bt709'
cmd . dst_color_space = 'bt709'
# run command
subprocess . check_call ( list ( cmd ))