Skip to content

Cut pow/resume and postprocess video - #225

Merged
kostarion merged 9 commits into
anima_stablefrom
cut_pow/resume_and_postprocess_video
May 10, 2023
Merged

kostarion merged 9 commits into
anima_stablefrom
cut_pow/resume_and_postprocess_video

Conversation

@kostarion

@kostarion kostarion commented May 9, 2023 •

Copy link
Copy Markdown
Contributor
  1. resume option in gradio notebook
  • Default behaviour is the same -- all generated frames from the previous run will be deleted when press render button. But if resume option is selected, the animation will be continued from the last existing frame if resume_from=-1, or any specific positive frame number.
  • These two parameters are the first one in the Input tab, because they kind of overwrite init image, but it's up for discussion
  1. Postprocessing can be done for any specified videofile
  • Frames are extracted to a 'frames' subdirectory near the videofile; then processed just like a generated frames project dir.
  • I've decided to go with videofiles and not directories because it's more universal and a directory way obliges to have specific image name format in it.
  • This is also the first two options in the Post tab because it is input, but it's also up for a discussion.
  • Gradio components File and UploadButton allow to use file manager to navigate to a video instead of specifying its path, but for some reason they both were freezing the notebook rendering for me. I haven't tried running it in colab, and haven't played around it much, but decided to go for a simpler (although a bit less convenient) solution, especially since the video_input_path is a Text also.
  1. upscale frames in correct order

Comment on lines +211 to +233
def extract_frames_from_video(video_path: str, frames_subdir: str='frames'):
"""
Extracts all frames from a video to a subdirectory of the video's parent folder.
:param video_path: A path to the video.
:param frames_subdir: Name of the subdirectory to save the frames into.
:return: The frames subdirectory path.
"""
out_dir = os.path.join(os.path.dirname(video_path), frames_subdir)
if not os.path.exists(out_dir):
os.mkdir(out_dir)

cmd = [
'ffmpeg',
'-i', video_path,
os.path.join(out_dir, "frame_%05d.png"),
]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
_, stderr = process.communicate()
if process.returncode != 0:
raise RuntimeError(stderr)

return out_dir

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create_video_from_frames lives in animation.py and I think it would make sense to have frames -> video and video -> frames both live in the same place.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should move create_video_from_frames to utils then?

Comment thread src/stability_sdk/animation_ui.py Outdated
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@kostarion
kostarion merged commit b2224d3 into anima_stable May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants