|
@@ -5,6 +5,8 @@ import hashlib
|
|
import ffmpeg
|
|
import ffmpeg
|
|
import os
|
|
import os
|
|
import oss2
|
|
import oss2
|
|
|
|
+from model.sql_models import DB
|
|
|
|
+from config import using_config as db_config
|
|
|
|
|
|
|
|
|
|
def change_format(video_url, file_md5=None):
|
|
def change_format(video_url, file_md5=None):
|
|
@@ -14,6 +16,34 @@ def change_format(video_url, file_md5=None):
|
|
rsp = requests.get(video_url)
|
|
rsp = requests.get(video_url)
|
|
with open(input_file, 'wb') as f:
|
|
with open(input_file, 'wb') as f:
|
|
f.write(rsp.content)
|
|
f.write(rsp.content)
|
|
|
|
+
|
|
|
|
+ # 获取视频---matedata-title
|
|
|
|
+ video_info_input = ffmpeg.probe(input_file)['format']
|
|
|
|
+ video_title = ''
|
|
|
|
+ try:
|
|
|
|
+ if 'zx' in video_info_input['tags']['title']:
|
|
|
|
+ video_title = video_info_input['tags']['title']
|
|
|
|
+ except:
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+ if video_title[:2] == 'zx':
|
|
|
|
+ # 如果有这一类数据,数据库比对matedata,获取download_path,等其他信息
|
|
|
|
+ db_qc = DB(config=db_config.quchen_text)
|
|
|
|
+ sql = '''
|
|
|
|
+ select download_path ,video_meta_data ,size,video_length ,byte_rate ,
|
|
|
|
+ width ,height ,type
|
|
|
|
+ from video_info
|
|
|
|
+ where video_meta_data='{}'
|
|
|
|
+ '''.format(video_title)
|
|
|
|
+ cursor = db_qc.session.execute(sql)
|
|
|
|
+ lines = []
|
|
|
|
+ for line in cursor.fetchall():
|
|
|
|
+ lines.append(line)
|
|
|
|
+ if len(lines) > 0:
|
|
|
|
+ logging.info(video_url + ' 视频已经存在')
|
|
|
|
+ cloud_filepath, metadata_title, video_size, duration, bit_rate, width, height, format = lines[0]
|
|
|
|
+ return cloud_filepath, metadata_title, video_size, duration, bit_rate, width, height, format
|
|
|
|
+
|
|
if not file_md5:
|
|
if not file_md5:
|
|
file_md5 = hashlib.md5(rsp.content).hexdigest()
|
|
file_md5 = hashlib.md5(rsp.content).hexdigest()
|
|
logging.info(file_md5) # ac3ee699961c58ef80a78c2434efe0d0
|
|
logging.info(file_md5) # ac3ee699961c58ef80a78c2434efe0d0
|
|
@@ -33,11 +63,9 @@ def change_format(video_url, file_md5=None):
|
|
height = int(video_stream['height'])
|
|
height = int(video_stream['height'])
|
|
|
|
|
|
logging.info('视频时长:{} 视频大小:{} 视频比特率:{} 视频宽:{} 视频长:{}'.format(duration, video_size, bit_rate, width, height))
|
|
logging.info('视频时长:{} 视频大小:{} 视频比特率:{} 视频宽:{} 视频长:{}'.format(duration, video_size, bit_rate, width, height))
|
|
-
|
|
|
|
cloud_filepath = 'video/{}.mp4'.format(metadata_title)
|
|
cloud_filepath = 'video/{}.mp4'.format(metadata_title)
|
|
-
|
|
|
|
- video_format=video_url.split('.')[-1]
|
|
|
|
- format='mp4' if len(video_format)>4 else video_format
|
|
|
|
|
|
+ video_format = video_url.split('.')[-1]
|
|
|
|
+ format = 'mp4' if len(video_format) > 4 else video_format
|
|
|
|
|
|
# 上传视频
|
|
# 上传视频
|
|
update_to_aliyun(local_filepath=output_file, cloud_filepath=cloud_filepath)
|
|
update_to_aliyun(local_filepath=output_file, cloud_filepath=cloud_filepath)
|
|
@@ -49,11 +77,12 @@ def change_format(video_url, file_md5=None):
|
|
|
|
|
|
|
|
|
|
def update_to_aliyun(local_filepath, cloud_filepath):
|
|
def update_to_aliyun(local_filepath, cloud_filepath):
|
|
- # TODO:之后oss相关密码信息写入config
|
|
|
|
- access_key_id = os.getenv('OSS_TEST_ACCESS_KEY_ID', 'LTAI5tGAUywhGk8xDuXosquq')
|
|
|
|
- access_key_secret = os.getenv('OSS_TEST_ACCESS_KEY_SECRET', 'VMVfRv6DdSYuBipIMU5UdtHBYB0Jjb')
|
|
|
|
- bucket_name = os.getenv('OSS_TEST_BUCKET', 'zx-media-database')
|
|
|
|
- endpoint = os.getenv('OSS_TEST_ENDPOINT', 'http://oss-cn-hangzhou.aliyuncs.com')
|
|
|
|
|
|
+ logging.info('准备上传视频')
|
|
|
|
+ oss_config = db_config.oss_config
|
|
|
|
+ access_key_id = os.getenv('OSS_TEST_ACCESS_KEY_ID', oss_config['OSS_TEST_ACCESS_KEY_ID'])
|
|
|
|
+ access_key_secret = os.getenv('OSS_TEST_ACCESS_KEY_SECRET', oss_config['OSS_TEST_ACCESS_KEY_SECRET'])
|
|
|
|
+ bucket_name = os.getenv('OSS_TEST_BUCKET', oss_config['OSS_TEST_BUCKET'])
|
|
|
|
+ endpoint = os.getenv('OSS_TEST_ENDPOINT', oss_config['OSS_TEST_ENDPOINT'])
|
|
|
|
|
|
# 创建Bucket对象,所有Object相关的接口都可以通过Bucket对象来进行
|
|
# 创建Bucket对象,所有Object相关的接口都可以通过Bucket对象来进行
|
|
bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)
|
|
bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name)
|
|
@@ -71,9 +100,29 @@ def update_to_aliyun(local_filepath, cloud_filepath):
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
- import threading
|
|
|
|
- for i in range(100):
|
|
|
|
- x_thread=threading.Thread(target=change_format,args=('http://wxsnsdy.wxs.qq.com/131/20210/snssvpdownload/SH/reserved/ads_svp_video__0b53qybncaaciaadpfl53jqbrbqe2gdafuka.f110002.mp4?dis_k=2982f4fc3f191cb6199045ca072ed033&dis_t=1618995038&m=beb8a2fd5980bb6fb4f9cef486546338',))
|
|
|
|
- x_thread.start()
|
|
|
|
-
|
|
|
|
- change_format('http://wxsnsdy.wxs.qq.com/131/20210/snssvpdownload/SH/reserved/ads_svp_video__0b53qybncaaciaadpfl53jqbrbqe2gdafuka.f110002.mp4?dis_k=2982f4fc3f191cb6199045ca072ed033&dis_t=1618995038&m=beb8a2fd5980bb6fb4f9cef486546338')
|
|
|
|
|
|
+ # import threading
|
|
|
|
+ #
|
|
|
|
+ # for i in range(100):
|
|
|
|
+ # x_thread = threading.Thread(target=change_format, args=(
|
|
|
|
+ # 'http://wxsnsdy.wxs.qq.com/131/20210/snssvpdownload/SH/reserved/ads_svp_video__0b53qybncaaciaadpfl53jqbrbqe2gdafuka.f110002.mp4?dis_k=2982f4fc3f191cb6199045ca072ed033&dis_t=1618995038&m=beb8a2fd5980bb6fb4f9cef486546338',))
|
|
|
|
+ # x_thread.start()
|
|
|
|
+
|
|
|
|
+ import logging
|
|
|
|
+ from logging import handlers
|
|
|
|
+
|
|
|
|
+ logging.basicConfig(
|
|
|
|
+ handlers=[
|
|
|
|
+ logging.handlers.RotatingFileHandler('video_process.log',
|
|
|
|
+ maxBytes=10 * 1024 * 1024,
|
|
|
|
+ backupCount=5,
|
|
|
|
+ encoding='utf-8')
|
|
|
|
+ , logging.StreamHandler() # 供输出使用
|
|
|
|
+ ],
|
|
|
|
+ level=logging.INFO,
|
|
|
|
+ format="%(asctime)s - %(levelname)s %(filename)s %(funcName)s %(lineno)s - %(message)s"
|
|
|
|
+ )
|
|
|
|
+ # change_format(
|
|
|
|
+ # 'https://zx-media-database.oss-cn-hangzhou.aliyuncs.com/video/zx_beb8a2fd5980bb6fb4f9cef486546338.mp4',
|
|
|
|
+ # file_md5='beb8a2fd5980bb6fb4f9cef486546338')
|
|
|
|
+ change_format(
|
|
|
|
+ 'http://wxsnsdy.wxs.qq.com/131/20210/snssvpdownload/SH/reserved/ads_svp_video__0b53qybncaaciaadpfl53jqbrbqe2gdafuka.f110002.mp4?dis_k=2982f4fc3f191cb6199045ca072ed033&dis_t=1618995038&m=beb8a2fd5980bb6fb4f9cef486546338')
|