update BG_Actor6

This commit is contained in:
liangsen committed 2022-09-01 11:54:15 +08:00
1 parent b6567d5902
commit de75bc60b6
14 files changed
+9497 -94

No files matched your search

+142 -70
View File
@@ -4,26 +4,60 @@ import os
import moviepy
from moviepy.editor import VideoFileClip, AudioFileClip
import os, sys
sys.path.insert(0, os.getcwd())
from common.logger import Logger
if __name__ == '__main__':
# path_raw = Path("/ssdata1/cf/data/raw/20220422/bg")
path_raw = Path("/mfs/lsen/DATA/Actor6/bg/raw-rotaion/")
path_root = Path("/mfs/lsen/DATA/Actor6/bg/processing")
vpath_videos = sorted(path_raw.glob("*.mp4"), reverse=False)
print(f"Have {len(vpath_videos)} dir files")
# path_raw = Path("/ssdata1/cf/data/raw/actor06/20220517")
# path_raw = Path("/ssdata1/cf/data/raw/actor06/20220519")
# path_root = Path("/ssdata1/lsen/DATA/Actor6/processing2")
path_raw = Path("/mfs/cf/data/raw/actor06/20220810")
path_root = Path("/mfs/lsen/DATA/Actor6/bg/processing2_0810")
path_root.mkdir(parents=True, exist_ok=True)
# set logging
logger = Logger(path_root)
# get all videos
vpath_videos = sorted(path_raw.glob("*.MP4"), reverse=False)
logger.info(f"Have {len(vpath_videos)} dir files")
IDs = [
"4R3A0204", # -> actor6, outfit2, movements_欢迎
"4R3A0205", # -> actor6, outfit2, movements_讲解
"4R3A0206", # -> actor6, outfit2, movements_展示
"4R3A0210", # -> actor6, outfit1, movements_欢迎
"4R3A0211", # -> actor6, outfit1, movements_讲解
"4R3A0213", # -> actor6, outfit1, movements_展示
"4R3A0226", # -> actor6, outfit3, movements_欢迎
"4R3A0227", # -> actor6, outfit3, movements_讲解
"4R3A0228", # -> actor6, outfit3, movements_展示
"4R3A0217", # -> actor6, outfit1, bg_withmovements_1min
"4R3A0218", # -> actor6, outfit1, bg_withmovements_3min
"4R3A0209", # -> actor6, outfit2, bg_withmovements_3min
"4R3A0232", # -> actor6, outfit3, bg_withmovements_3min
]
# IDs = ["clip_full"]
durations = 0
# for each video
for i, ipath_item in enumerate(vpath_videos):
iname = ipath_item.stem
print(f"processing {i}/{len(vpath_videos)} -> {ipath_item} ... ")
logger.info(f"processing {i}/{len(vpath_videos)}-->{iname} -> {ipath_item} ... ")
# if i > 0: continue
if iname not in IDs: continue
# if i < 40: continue
# if iname not in IDs: continue
# data path
ipath_data = path_root.joinpath(ipath_item.stem)
@@ -36,104 +70,142 @@ if __name__ == '__main__':
ipath_video.mkdir(parents=True, exist_ok=True)
ipath_audio.mkdir(parents=True, exist_ok=True)
# # # load video info & check
# if ipath_infor.exists():
# # continue
# with open(str(ipath_infor), "r") as f:
# info = json.load(f)
# nframe_info = info['nframes']
# # check frames
# nframe_real = len(list(ipath_frame.glob("*.jpg")))
# if nframe_real == nframe_info:
# print(f"\n Skip: have already done!")
# continue
# # load video info & check
if ipath_infor.exists():
# continue
with open(str(ipath_infor), "r") as f:
info = json.load(f)
nframe_info = info['nframes']
# check frames
nframe_real = len(list(ipath_frame.glob("*.jpg")))
if nframe_real == nframe_info:
logger.info(f"\n Skip: have already done!")
continue
# convert image
ipath_item_rotation = ipath_video.joinpath("video_raw_rotation.mp4")
if not ipath_item_rotation.exists():
cmd = f"ffmpeg -loglevel quiet -i {str(ipath_item)} -vf 'transpose=2' {str(ipath_item_rotation)}"
logger.info(cmd)
os.system(cmd)
# ffmpeg -i /mfs/cf/data/raw/actor06/20220810/4R3A0204.MP4
# load video
video = VideoFileClip(str(ipath_item))
print(f"video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
# video = VideoFileClip(str(ipath_item))
video = VideoFileClip(str(ipath_item_rotation))
logger.info(f"video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
if video.audio is None:
logger.info("\nERROR: audio info is None")
continue
durations += video.duration
print(f"\n\t -> Total durations = ({durations / 60 } min) ({durations / 3600 } h))")
logger.info(f"\n\t -> Total durations = ({durations / 60 } min) ({durations / 3600 } h))")
# continue
# add
# ipath_video_sub = ipath_video.joinpath("video_trim.mp4")
# if not ipath_video_sub.exists():
# cmd = f"ffmpeg -y -hide_banner -loglevel error -ss 15 -t {int(video.duration)-15.0} -i {str(ipath_item)} -vcodec copy -acodec copy {str(ipath_video_sub)}"
# cmd = f"ffmpeg -y -hide_banner -loglevel error -ss 15 -t {int(video.duration)-15.0} -i {str(ipath_item_rotation)} -vcodec copy -acodec copy {str(ipath_video_sub)}"
# os.system(cmd)
# print(f"save video > {ipath_video_sub}")
# # copy
# ipath_video_save = ipath_video.joinpath("video.mp4")
# if not ipath_video_save.exists():
# cmd = f"cp {str(ipath_item)} {str(ipath_video_save)}"
# os.system(cmd)
# print(f"save video > {ipath_video_save}")
# logger.info(f"save video > {ipath_video_sub}")
# Trim
# video = video.subclip(t_start=5.0, t_end=int(video.duration)-5.0) before 03.14
# video = video.subclip(t_start=15.0, t_end=int(video.duration)-15.0)
# video = video.subclip(t_start=5.0, t_end=60.0)
# logger.info(f"after cut video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
nframes = int(video.duration * video.fps)
# nframes = len(list(video.iter_frames()))
# print(f"after cut video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
# logger.info(f"after cut video duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
# # if fps != 50
# if video.fps != 50:
# print("FPS NOT = 50!! ")
# if fps != 50
if video.fps != 50:
logger.info("FPS NOT = 50!! ")
raise Exception(f"FPS NOT = 50!!, fps={video.fps}")
# # save sub video fps=50
# ipath_video_sub = ipath_video.joinpath("video_trim.mp4")
# if ipath_video_sub.exists():
# print("\nERROR: ipath_video_sub.exists()")
# continue
# else:
# video.write_videofile(str(ipath_video_sub), fps=50, audio=True)
# print(f"save video > {ipath_video_sub}")
# # save sub video fps=50
# ipath_video_sub = ipath_video.joinpath("video_trim.mp4")
# if ipath_video_sub.exists():
# logger.info("\nERROR: ipath_video_sub.exists()")
# continue
# else:
# video.write_videofile(str(ipath_video_sub), fps=50, audio=True)
# logger.info(f"save video > {ipath_video_sub}")
# # reload video
# video.close()
# video = VideoFileClip(str(ipath_video_sub))
# logger.info(f"video reload duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
# nframes = len(list(video.iter_frames()))
# # reload video
# video.close()
# video = VideoFileClip(str(ipath_video_sub))
# print(f"video reload duration = {video.duration}, fps = {video.fps}, (start, end)=({video.start},{video.end}), nframes={int(video.duration * video.fps)}")
# nframes = len(list(video.iter_frames()))
# get audio
audio_sub = video.audio
if audio_sub is None:
print("\nERROR: audio info is None")
logger.info("\nERROR: audio info is None")
continue
print(f"audio_sub duration = {audio_sub.duration}, fps = {audio_sub.fps}, (start, end)=({audio_sub.start},{audio_sub.end}), nframes={int(audio_sub.duration * audio_sub.fps)}")
logger.info(f"audio_sub duration = {audio_sub.duration}, fps = {audio_sub.fps}, (start, end)=({audio_sub.start},{audio_sub.end}), nframes={int(audio_sub.duration * audio_sub.fps)}")
# save audio_sub
ipath_audio_sub = ipath_audio.joinpath("audio_trim.wav")
audio_sub.write_audiofile(str(ipath_audio_sub), fps=audio_sub.fps)
print(f"save audio > {ipath_audio_sub}")
logger.info(f"save audio > {ipath_audio_sub}")
# # check fps
# if int(video.fps) != 50:
# print(f"\n Skip: fps != 50 realy fps={video.fps}, convert to 50fps")
# logger.info(f"\n Skip: fps != 50 realy fps={video.fps}, convert to 50fps")
# ipath_video_save = ipath_data.joinpath("video", f"video_50fps.mp4")
# video.write_videofile(str(ipath_video_save), fps=50.0)
# print(f"save video to > {ipath_video_save}...")
# logger.info(f"save video to > {ipath_video_save}...")
# # save video feature
# info = {"nframes": nframes,
# "fps": video.fps,
# "width": video.w,
# "height": video.h}
# save video feature
info = {"nframes": nframes,
"fps": video.fps,
"width": video.w,
"height": video.h}
# with open(str(ipath_infor), 'w+') as f:
# json.dump(info, f)
# print(info)
# print(f"save video info in -> {ipath_infor}\n")
with open(str(ipath_infor), 'w+') as f:
json.dump(info, f)
logger.info(info)
logger.info(f"save video info in -> {ipath_infor}\n")
# # save trim video
# print(f"write_images_sequence...")
# ipath_format = str(ipath_frame) + "/frame-%06d.jpg"
# video.write_images_sequence(ipath_format, fps=50)
# save trim video
logger.info(f"write_images_sequence...")
ipath_format = str(ipath_frame) + "/frame-%06d.jpg"
video.write_images_sequence(ipath_format, fps=50)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/mfs/cf/data/raw/actor06/20220810/4R3A0204.MP4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp42avc1CAEP
make :
make-eng :
model :
model-eng :
creation_time : 2022-08-10T11:04:12.000000Z
timecode : 13:19:49:04
Duration: 00:02:46.40, start: 0.000000, bitrate: 59289 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709), 1920x1080, 58961 kb/s, 50 fps, 50 tbr, 50k tbn, 100k tbc (default)
Metadata:
creation_time : 2022-08-10T11:04:12.000000Z
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 255 kb/s (default)
Metadata:
creation_time : 2022-08-10T11:04:12.000000Z
Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 1 kb/s (default)
Metadata:
creation_time : 2022-08-10T11:04:12.000000Z
timecode : 13:19:49:04