هذا المشروع هو مسودة وليس المقصود استخدامه من قبل أي شخص.
vtcff هي مكتبة للانتقال بين تنسيقات الفيديو مع التركيز على الحفاظ على الجودة وعمق اللون في خطوط إنتاج الفيديو. في مهام الاستوديو ، تأخذ ثواني الفيديو gigabytes وتوافق الجودة على الأقل أمر مرغوب فيه.
يميل 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.audio يحتوي ffmpeg على مرشحين للفيديو لتحويلات حجم اللون والإطار:
scale (libswscale) أكثر تنوعاzscale (ZIMG) جودة أكثر قابلية للتنبؤ بشكل افتراضي ، يستخدم vtcff zscale . في بعض الأحيان قد يؤدي إلى خطأ "لا يوجد مسار بين Colorspaces". إذا لم تساعد الطرق الأخرى ، فيمكنك ببساطة استبدال zscale scale .
cmd.use_zscale == True يعني استخدام zscalecmd.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 ()تحويل التوقيتات أو تسلسل إطارات CGI إلى ملف فيديو Pror.
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 ))