python

超轻量级php框架startmvc

python 通过视频url获取视频的宽高方式

更新时间:2020-08-13 01:12:01 作者:startmvc
这里其实是通过获取视频截图的方式获得大小的下面列举两个小demoimportcv2#引入模块获取视

这里其实是通过获取视频截图的方式获得大小的

下面列举两个小demo


import cv2 #引入模块 获取视频截图的
 
from PIL import Image #引入模块 获取图片大小
import os #引入系统命令 删除图片
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 更新数据库


#!/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 通过视频url获取视频的宽高方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

python 视频 url 宽高