update actor5 and infer_folder_live

This commit is contained in:
liangsen committed 2022-05-10 10:47:54 +08:00
1 parent 854609dd0c
commit dac314c9a5
34 files changed
+2810 -658

No files matched your search

+1 -91
View File
@@ -361,97 +361,7 @@
]
}
],
"source": [
"\n",
"path_frame_reference = path_root.joinpath(fname, \"frames\", f\"\")\n",
"\n",
"for i in range(len(peaks_filter)-1):\n",
"\n",
" idx_beg = peaks_filter[i]\n",
" idx_end = peaks_filter[i+1]\n",
" print(f\"processing the peak {idx_beg}, range=[{idx_beg},{idx_end}]\")\n",
"\n",
"\n",
" nsize = idx_end - idx_beg + 1\n",
" duration = nsize/50\n",
" duration_pad = nsize//50 + 1\n",
"\n",
" nframe_pad = duration_pad * 50 - nsize\n",
"\n",
" if idx_beg == 3739:\n",
" nframe_pad_head = 0\n",
" nframe_pad_tail = nframe_pad\n",
" elif idx_end == 3739:\n",
" nframe_pad_head = nframe_pad\n",
" nframe_pad_tail = 0\n",
" else:\n",
" nframe_pad_head = nframe_pad // 2\n",
" nframe_pad_tail = nframe_pad - nframe_pad_head\n",
"\n",
"\n",
" print(f\"nframes = {nsize}, duration={duration}, duration_pad = {duration_pad}, need padding {nframe_pad / 2}\")\n",
" print(f\"nframe_pad_head= {nframe_pad_head}, nframe_pad_tail={nframe_pad_tail}\")\n",
" \n",
" # select head images\n",
" input_files = []\n",
" if nframe_pad_head > 0:\n",
" ipath_beg = path_root.joinpath(fname, \"video\", f\"{idx_beg:06}\", \"interpolated_frames\")\n",
"\n",
" choice = []\n",
" for k in range(1, nframe_pad_head):\n",
" idx_choice = int(k * (31/(nframe_pad_head)) + 0.5)\n",
" choice.append(idx_choice)\n",
" choice.append(32)\n",
"\n",
" # writer to file (need reversed)\n",
" for k in reversed(choice):\n",
" kpath_choice = ipath_beg.joinpath(f\"frame_{k:03d}.jpg\")\n",
" input_files.append(kpath_choice)\n",
" print(f\"len={len(choice)} = {choice}\")\n",
" \n",
" # head-tail \n",
" input_files += [ str(path_frames.joinpath(f\"frame-{k:06d}.jpg\")) for k in range(idx_beg, idx_end+1)]\n",
"\n",
" # tail-renference\n",
" if nframe_pad_tail > 0:\n",
" ipath_tail = path_root.joinpath(fname, \"video\", f\"{idx_end:06}\", \"interpolated_frames\")\n",
" \n",
" choice = []\n",
" for k in range(1, nframe_pad_tail):\n",
" idx_choice = int(k * (31/(nframe_pad_tail)) + 0.5)\n",
" choice.append(idx_choice)\n",
" choice.append(32)\n",
"\n",
" # writer to file\n",
" for k in choice:\n",
" kpath_choice = ipath_beg.joinpath(f\"frame_{k:03d}.jpg\")\n",
" input_files.append(kpath_choice)\n",
" print(f\"len={len(choice)} = {choice}\")\n",
"\n",
" \n",
" # write to files\n",
" # write to a input.txt \n",
" print(f\" total have {len(input_files)} files, duration = {len(input_files)/50}\")\n",
" file_tmp = tempfile.NamedTemporaryFile(suffix='.txt')\n",
" with open(file_tmp.name, 'w') as fwriter:\n",
" for kpath in input_files:\n",
" fwriter.write(f\"file {kpath} \\n\")\n",
"\n",
"\n",
" # render to video\n",
" # concate to a video \n",
" ipath_save = path_root.joinpath(fname, \"video\", f\"split_{i:02d}_interplote.mp4\")\n",
" cmd = f\"ffmpeg -y -r 50 -f concat -safe 0 -i {str(file_tmp.name)} -c:v libx264 -pix_fmt yuv420p -loglevel error {str(ipath_save)}\"\n",
" print(cmd)\n",
" # os.system(cmd)\n",
"\n",
" file_tmp.close()\n",
" break\n",
" # make 32 padding \n",
" # resampling\n",
" \n",
" # concate_video(path_frames, peaks_filter[i], peaks_filter[i+1], ipath_save)\n"
]
"source": []
},
{
"cell_type": "code",