โครงการนี้เป็นร่างและไม่ได้ตั้งใจที่จะใช้โดยทุกคน
vtcff เป็นห้องสมุดสำหรับการแปลงรหัสระหว่างรูปแบบวิดีโอโดยเน้นการรักษาคุณภาพและความลึกสีในท่อส่งวิดีโอ ในงานสตูดิโอวิดีโอวินาทีใช้กิกะไบต์และการประนีประนอมคุณภาพเป็นที่ต้องการน้อยที่สุด
vtcff มีแนวโน้มที่จะเพิ่มคุณภาพการเสียสละความเร็วและพื้นที่ดิสก์
vtcff เป็น wrapper สำหรับ 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.audio ffmpeg มีตัวกรองวิดีโอสองตัวสำหรับการแปลงสีและขนาดเฟรม:
scale (libswscale) มีความหลากหลายมากกว่าzscale (ZIMG) ให้คุณภาพที่คาดเดาได้มากขึ้น โดยค่าเริ่มต้น vtcff ใช้ zscale บางครั้งอาจนำไปสู่ข้อผิดพลาด "ไม่มีเส้นทางระหว่าง ColorsPaces" หากวิธีการอื่นไม่ช่วยคุณสามารถแทนที่ zscale ด้วย scale
cmd.use_zscale == True หมายถึง zscale ใช้cmd.use_zscale == False การใช้ 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 จะถูกใช้สำหรับการแปลงที่ตั้งค่า อย่างชัดเจน โดยคุณสมบัติของวัตถุ นี่เป็นสิ่งที่ดีเพราะการแปลงเหล่านี้จะมีคุณภาพสูง
อย่างไรก็ตามอาจจำเป็นต้องมีการแปลง โดยนัย ตัวอย่างเช่นก่อนที่จะประมวลผล PNG 16 บิตด้วย zscale เราจำเป็นต้องแปลงรูปแบบพิกเซลจาก rgba64be เป็น gbrap16le FFMPEG จะทำโดยอัตโนมัติด้วย libswscale โดยไม่คำนึงถึงคุณสมบัติ use_zscale
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 ()การแปลง Timelapses หรือ CGI Frame Sequences เป็นไฟล์วิดีโอที่น่าสนใจ
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 ))