貫徹不要臉精神-貼個東西
import CV2
from rich.progress import Progress
import sys
def main():
? ? from_ = str(input("Enter from filename:"))#從哪里來
? ? filename = str(input("Enter save filename: "))#到哪里去
? ? fourcc = str(input("Enter fourcc: "))#編碼
? ? if(fourcc == "mp4"):fourcc = "mp4v"#MP4
? ? if(fourcc == "avi"):fourcc = "XVID"#AVI
? ? fps = int(input("Enter fps: "))#fps(注釋:我們沒有將fps省略或重復)
? ? framesize = (int(input("Enter framesize-width: ")),int(input("Enter framesize-height: ")))#寬高
? ? #iscolor = bool(input("Enter iscolor: "))#彩色
? ? outobj = CV2.VideoWriter(filename,CV2.VideoWriter.fourcc(*fourcc),fps,framesize,True)#iscolor)#輸出的元素
? ? readobj = CV2.VideoCapture(from_)#讀取的元素
? ? ret,frame = readobj.read()#預先處理一次
? ? cnt = 0#計數(shù)器
? ? af = int(readobj.get(CV2.CAP_PROP_FRAME_COUNT))#總幀數(shù)
? ? while ret:
? ? ? ? frame = CV2.resize(frame,framesize)#縮放
? ? ? ? outobj.write(frame)#寫入
? ? ? ? ret,frame = readobj.read()#讀取
? ? ? ? print(f"{cnt} / {af}")################################
? ? ? ? sys.stdout.flush()#這三段式為了顯示進度
? ? ? ? cnt += 1################################
? ? readobj.release()#釋放
? ? outobj.release()#釋放
? ? print("done")#結束標識
? ? ? ?
main()
這段代碼可以將原視頻進行"加速",縮放,無聲(滑稽),更改文件類型處理
純手搓,拉