Artificial Intelligence Programming Lab(AIPLab) 討論區

Please login or register.

請輸入帳號, 密碼以及預計登入時間

新聞:

[慶賀]恭喜亞大獲《泰晤士報》亞洲最佳大學排名第83名,國內排名第十名-20170201

作者 主題: Handling Video Files  (閱讀 275 次)

admin

  • 管理員
  • Hero Member
  • *****
  • 文章: 1758
    • 檢視個人資料
Handling Video Files
« 於: 十月 15, 2019, 01:51:51 am »
ffmpeg -i "video.mov" -f image2 "video-frame%05d.png"

PyAV
程式碼: [Select]
for packet in container.demux():
    for frame in packet.decode():
        if frame.type == 'video':
            img = frame.to_image()  # PIL/Pillow image
            arr = np.asarray(img)  # numpy array
            # Do something!

MoviePy
程式碼: [Select]
from moviepy.editor import VideoFileClip
myclip = VideoFileClip("some_video.avi")

Imageio
程式碼: [Select]
import imageio
filename = '/tmp/file.mp4'
vid = imageio.get_reader(filename,  'ffmpeg')

for num, image in vid.iter_data():
    print(image.mean())

metadata = vid.get_meta_data()

OpenCV
程式碼: [Select]
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
#capture frame-by-frame
    ret , frame = cap.read()
   
    #our operation on the frame come here
    gray = cv2.cvtColor(frame , cv2.COLOR_BGR2GRAY)
   
    #display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) &0xFF ==ord('q'):  #按q键退出
    break
#when everything done , release the capture
cap.release()
cv2.destroyAllWindows()

程式碼: [Select]
import numpy as np
import cv2
cap=cv2.VideoCapture('filename.avi')#文件名及格式
while(True):
#capture frame-by-frame
    ret , frame = cap.read()
   
    #our operation on the frame come here
    gray = cv2.cvtColor(frame , cv2.COLOR_BGR2GRAY)
   
    #display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) &0xFF ==ord('q'):  #按q键退出
    break
#when everything done , release the capture
cap.release()
cv2.destroyAllWindows()

已記錄
 

SimplePortal Classic 2.0.5