python 通過(guò)視頻url獲取視頻的寬高方式
更新時(shí)間:2019年12月10日 10:19:34 作者:benben0729
今天小編就為大家分享一篇python 通過(guò)視頻url獲取視頻的寬高方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
這里其實(shí)是通過(guò)獲取視頻截圖的方式獲得大小的
下面列舉兩個(gè)小demo
import cv2 #引入模塊 獲取視頻截圖的
from PIL import Image #引入模塊 獲取圖片大小
import os #引入系統(tǒng)命令 刪除圖片
video_full_path="http://qnmov.a.yximgs.com/upic/2018/06/06/12/BMjAxODA2MDYxMjQwMTZfMTkzMDUyMjRfNjU2NzMwNzI5MF8xXzM=_hd3_Bc143c8abf799984d2cc75a52de7039f0.mp4?tag=1-1530685096-h-0-xbkiau97pb-2b932528a435f1d0"
cap = cv2.VideoCapture(video_full_path)
#print(cap.isOpened())
if cap.isOpened():#正常打開
rval,frame = cap.read()
else:
rval = False
cv2.imwrite("a.jpg",frame)
img = Image.open('a.jpg')
print(type(img.size))
print(img.size[0])
print(type(img.size[0]))
my_file = "images/1.jpg"
if os.path.exists(my_file):
os.remove(my_file)
else:
print("no such file")
demo2 更新數(shù)據(jù)庫(kù)
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
from short_video import ShortVideo
import json
import re
import requests
import hashlib
import cv2
from PIL import Image
import logging
import os
try:
query = ShortVideo().select()
except:
print('操作失敗')
else:
for item in query:
shv = ShortVideo().select().where(ShortVideo.video_identify_md5 == item.video_identify_md5).get()
video_url = shv.video_url
cap = cv2.VideoCapture(video_url)
if cap.isOpened():
rval,frame = cap.read()
cv2.imwrite("images/"+str(shv.id)+".jpg",frame)
img = Image.open("images/"+str(shv.id)+".jpg")
w = img.size[0]
h = img.size[1]
shv.width_height = str(w)+'x'+str(h)
#更新完刪除文件
my_file = "images/"+str(shv.id)+".jpg"
if os.path.exists(my_file):
os.remove(my_file)
else:
logging.info("no such file")
else:
logging.info('id:'+str(shv.id)+"更新失敗")
continue
if shv.save() == 1:
print('更新成功')
else:
print('更新失敗')
以上這篇python 通過(guò)視頻url獲取視頻的寬高方式就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
keras 自定義loss損失函數(shù),sample在loss上的加權(quán)和metric詳解
這篇文章主要介紹了keras 自定義loss損失函數(shù),sample在loss上的加權(quán)和metric詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-05-05
磁盤垃圾文件清理器python代碼實(shí)現(xiàn)
幾行Python代碼打造自己的磁盤垃圾文件清理器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03
解析pandas apply() 函數(shù)用法(推薦)
這篇文章主要介紹了pandas apply() 函數(shù)用法,大家需要掌握函數(shù)作為一個(gè)對(duì)象,能作為參數(shù)傳遞給其它函數(shù),也能作為函數(shù)的返回值,具體內(nèi)容詳情跟隨小編一起看看吧2021-10-10
jupyter notebook 的工作空間設(shè)置操作
這篇文章主要介紹了jupyter notebook 的工作空間設(shè)置操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04
Python通過(guò)format函數(shù)格式化顯示值
這篇文章主要介紹了Python通過(guò)format函數(shù)格式化顯示值,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-10-10

