Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to provide a custom video background #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ahuge
Copy link

@Ahuge Ahuge commented Oct 15, 2021

This PR allows users to bring their own background image/imageSequence/video instead of the default green background.

It creates a new parameter in convert_video called bgr_source: Optional[str] = None that, when passed will attempt to load either an ImageSequenceReader, VideoReader, or an ImageReader.

I have moved the green background into a dummy class called ConstantImage which implements the Dataset interface so that it can be indexed into per frame.

This allows you to provide Video, ImageSequence, Image or ConstantColour
background sources
@Ahuge
Copy link
Author

Ahuge commented Oct 15, 2021

I don't know if you are accepting PRs on this repo. I just found this functionality useful and wanted to offer it upstream

@PeterL1n
Copy link
Owner

Right now I am very busy with other projects. I won't have time to review those pull requests. So I am just gonna leave them open for now.

@Ahuge
Copy link
Author

Ahuge commented Oct 15, 2021

All good, thanks for the awesome research!

@chenying99
Copy link

chenying99 commented Oct 31, 2021

thank you for your share

  1. the file inference.py line in 123 125:
    if (output_composition is not None) and (output_type == 'video'):
    if bgr_source is not None and os.path.isfile(bgr_source):
    if os.path.isfile(bgr_source):
    if os.path.splitext(bgr_source)[-1].lower() in [".png", ".jpg"]:
    bgr_raw = ImageReader(bgr_source, transform=transform)
    else:
    bgr_raw = VideoReader(bgr_source, transform)
    else:
    bgr_raw = ImageSequenceReader(bgr_source, transform)
    else:
    bgr_raw = ConstantImage(120, 255, 155, device=device, dtype=dtype)

the bgr' size should resize, make it equal to the source' size

  1. line in 148:
    bgr = bgr_raw[index].to(device, dtype, non_blocking=True).unsqueeze(0) # [B, T, C, H, W]

if seq_chunk>1, bgr shuld be batch, the batchsize equal to seq_chunk; and the last batch' batchsize is the remainder

  1. len(bgr_raw) should be greater than len(source),otherwise, it could throw exception
    the file inference_utils.py line 25:
    frame = self.video[idx]

@xiami1234567890
Copy link

thank you for your share

  1. the file inference.py line in 123 125:
    if (output_composition is not None) and (output_type == 'video'):
    if bgr_source is not None and os.path.isfile(bgr_source):
    if os.path.isfile(bgr_source):
    if os.path.splitext(bgr_source)[-1].lower() in [".png", ".jpg"]:
    bgr_raw = ImageReader(bgr_source, transform=transform)
    else:
    bgr_raw = VideoReader(bgr_source, transform)
    else:
    bgr_raw = ImageSequenceReader(bgr_source, transform)
    else:
    bgr_raw = ConstantImage(120, 255, 155, device=device, dtype=dtype)

the bgr' size should resize, make it equal to the source' size

  1. line in 148:
    bgr = bgr_raw[index].to(device, dtype, non_blocking=True).unsqueeze(0) # [B, T, C, H, W]

if seq_chunk>1, bgr shuld be batch, the batchsize equal to seq_chunk; and the last batch' batchsize is the remainder

  1. len(bgr_raw) should be greater than len(source),otherwise, it could throw exception
    the file inference_utils.py line 25:
    frame = self.video[idx]

thank you for your share! ! I have same question in it.When I input a background image, it always doesn't match. Do you have a solution?It would be a big breakthrough if you could help me......

@justforyourdream
Copy link

RuntimeError: The size of tensor a (3) must match the size of tensor b (4) at non-singleton dimension 2

@akashAD98
Copy link

@Ahuge @justforyourdream @chenying99 have you solved the issue? still not able to get results,
its not matching with input size,fps & duration of video ,how to fix it

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.

6 participants