fix
This commit is contained in:
parent
c1a4d7383f
commit
83c8acdd2d
|
@ -185,12 +185,16 @@ class S:
|
|||
q1 = {
|
||||
"src_id": oss_src_id,
|
||||
}
|
||||
set1 = {
|
||||
"size_src": src_size,
|
||||
"resize_t": int(time.time()),
|
||||
"status": status
|
||||
}
|
||||
if status == 101:
|
||||
set1["fmt"] = "image/heic"
|
||||
logger.Info("change to heic, oss_src_id: {}".format(oss_src_id))
|
||||
up1 = {
|
||||
"$set": {
|
||||
"size_src": src_size,
|
||||
"resize_t": int(time.time()),
|
||||
"status": status
|
||||
}
|
||||
"$set": set1
|
||||
}
|
||||
bulk_reqs.append(UpdateOne(q1, up1))
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ class S:
|
|||
|
||||
old_key = safe_get_str(img, "src_id")
|
||||
old_fmt = safe_get_str(img, "fmt")
|
||||
old_status = safe_get_int(img, "status")
|
||||
new_key = old_key + "_h2j"
|
||||
|
||||
arr = old_key.split("/")
|
||||
|
@ -70,12 +71,16 @@ class S:
|
|||
q = {
|
||||
"src_id": old_key
|
||||
}
|
||||
set_ = {
|
||||
"src_id": new_key,
|
||||
"old_fmt": old_fmt,
|
||||
"fmt": "image/jpeg"
|
||||
}
|
||||
if old_status == 101:
|
||||
set_["status"] = 0
|
||||
logger.Info("change to heic, old_key: {}, new_key: {}".format(old_key, new_key))
|
||||
up = {
|
||||
"$set": {
|
||||
"src_id": new_key,
|
||||
"old_fmt": old_fmt,
|
||||
"fmt": "image/jpeg"
|
||||
}
|
||||
"$set": set_
|
||||
}
|
||||
mongo_ret = self.col_image.update_one(q, up)
|
||||
logger.Info("{}, heic2jpeg finish, new_key: {}, mongo_modify: {}".format(idx, new_key, mongo_ret.modified_count))
|
||||
|
|
|
@ -1,12 +1,112 @@
|
|||
from lib.all import *
|
||||
import ffmpy
|
||||
import cv2
|
||||
import oss2
|
||||
|
||||
input_file = "h264_origin.mp4"
|
||||
output_file = "h265_origin.mp4"
|
||||
# input_file = "h264_origin.mp4"
|
||||
# output_file = "h265_origin.mp4"
|
||||
# #
|
||||
# ff = ffmpy.FFmpeg(
|
||||
# inputs={input_file: None},
|
||||
# outputs={output_file: '-c:v libx265'}
|
||||
# )
|
||||
# #
|
||||
# ff.run()
|
||||
|
||||
ff = ffmpy.FFmpeg(
|
||||
inputs={input_file: None},
|
||||
outputs={output_file: '-c:v libx265'}
|
||||
)
|
||||
access_key_id = "LTAI5tAdu5LRvZwm4LJa21Fo"
|
||||
access_key_secret = "WGvSQsDralTfFAAxhEqLBOgbXqflHo"
|
||||
endpoint_internal = "https://oss-cn-hangzhou.aliyuncs.com"
|
||||
bucket_name = "wishpal-ironfan-media"
|
||||
|
||||
ff.run()
|
||||
|
||||
def get_video_w_h(path):
|
||||
video = cv2.VideoCapture(path)
|
||||
|
||||
width = int(video.get(cv2.CAP_PROP_FRAME_WIDTH))
|
||||
height = int(video.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
||||
|
||||
# 横屏 960 * 540
|
||||
if width > height:
|
||||
rate = float(720) / float(height)
|
||||
new_width = int(float(width) * rate)
|
||||
new_height = 720
|
||||
else:
|
||||
rate = float(720) / float(width)
|
||||
new_width = 720
|
||||
new_height = int(float(height) * rate)
|
||||
|
||||
return width, height, new_width, new_height
|
||||
|
||||
|
||||
# video_path = "bbbbb.mov"
|
||||
# print(get_video_w_h(video_path))
|
||||
|
||||
|
||||
class S:
|
||||
def __init__(self):
|
||||
self.bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint_internal, bucket_name)
|
||||
self.url_get_videos_by_status = "https://api.tiefen.fun/op/media/get_videos_by_status"
|
||||
self.url_update_video_compress = "https://api.tiefen.fun/op/media/url_update_video_compress"
|
||||
self.hw_cdn_host = "https://filecdnhw01.tiefen.fun/"
|
||||
|
||||
def save_video_from_oss(self, oss_src_id: str, local_path: str):
|
||||
return self.bucket.get_object_to_file(oss_src_id, local_path)
|
||||
|
||||
def upload_video_to_oss(self, local_path: str, oss_src_id: str):
|
||||
return self.bucket.put_object_from_file(oss_src_id, local_path)
|
||||
|
||||
def get_one_wait_compress_video(self):
|
||||
param = {
|
||||
"ids": [23431],
|
||||
"status": 0,
|
||||
"offset": 0,
|
||||
"limit": 1,
|
||||
}
|
||||
res = call_service(self.url_get_videos_by_status, param)
|
||||
data = safe_get_dict(res, "data")
|
||||
lis = safe_get_list(data, "video")
|
||||
if len(lis) > 0:
|
||||
return lis[0]
|
||||
return None
|
||||
|
||||
def proc_one(self):
|
||||
video = self.get_one_wait_compress_video()
|
||||
if not video:
|
||||
return
|
||||
|
||||
video_id = safe_get_int(video, "id")
|
||||
src_id = safe_get_str(video, "src_id")
|
||||
src_id_python_type = src_id.replace("/", "_")
|
||||
|
||||
cur_dir = os.getcwd() + "/"
|
||||
local_src_path = cur_dir + src_id_python_type
|
||||
|
||||
# 下载视频到本地
|
||||
obj = self.save_video_from_oss(src_id, local_src_path)
|
||||
content_type = safe_get_str(obj.headers, "Content-Type")
|
||||
file_size = int(safe_get_str(obj.headers, "Content-Length"))
|
||||
local_src_path_new = local_src_path
|
||||
if content_type == "video/mp4":
|
||||
local_src_path_new = local_src_path + ".mp4"
|
||||
elif content_type == "video/quicktime":
|
||||
local_src_path_new = local_src_path + ".mov"
|
||||
else:
|
||||
print("invalid content_type, id: {}, src_id: {}, content_type: {}", video_id, self.hw_cdn_host + src_id, content_type)
|
||||
return
|
||||
os.renames(local_src_path, local_src_path_new)
|
||||
|
||||
# 转成264 mp4
|
||||
input_file = local_src_path_new
|
||||
output_file = local_src_path + ".mp4"
|
||||
ff = ffmpy.FFmpeg(
|
||||
inputs={input_file: None},
|
||||
outputs={output_file: '-c:v libx264'}
|
||||
)
|
||||
ff.run()
|
||||
|
||||
print(content_type, file_size)
|
||||
print(local_src_path_new)
|
||||
|
||||
|
||||
s = S()
|
||||
s.proc_one()
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue