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

[BUG] b command doesn't work, PILImage self is "RGB" #714

Closed
lukas-buergi opened this issue Jan 27, 2025 · 1 comment
Closed

[BUG] b command doesn't work, PILImage self is "RGB" #714

lukas-buergi opened this issue Jan 27, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@lukas-buergi
Copy link
Contributor

lukas-buergi commented Jan 27, 2025

Describe the bug
The b command doesn't work for me. I have no idea why, but I found a simple fix.

To Reproduce
Steps to reproduce the behavior:

  1. Run for example ffmpeg -hide_banner -loglevel quiet -i C0040.MP4 -ss 10 -t 1 -an -f rawvideo -pix_fmt rgb24 pipe:1 | rembg b 2160 3840 | ffmpeg -f image2pipe -framerate 60 -i pipe:1 -c:v libx265 -crf 23 output.mp4
  2. See error
File "/mnt/deb67853-226b-4939-9bd1-3167199a8160/rembg/env/lib/python3.11/site-packages/rembg/commands/b_command.py", line 165, in main
    img = PILImage.frombytes("RGB", (image_width, image_height), img_bytes)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/deb67853-226b-4939-9bd1-3167199a8160/rembg/env/lib/python3.11/site-packages/PIL/Image.py", line 858, in frombytes
    if self.width == 0 or self.height == 0:
       ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'width'
  1. If you want, use pdb to investigate. It turns out that self == "RGB".

Expected behavior
The background should have been removed from the video.

OS Version:
debian 12

Rembg version:
37bbf63 (also latest version on pip has same behaviour)

Solution

import PIL
...
img = PIL.Image.frombytes("RGB", (image_width, image_height), img_bytes)

If you know why this helps, I would be glad to find out.

@lukas-buergi lukas-buergi added the bug Something isn't working label Jan 27, 2025
@calledit
Copy link
Contributor

Have the same issue.

$ cat raw_rgb24.dat| rembg b 1440 1080 | cat -> rgb.dat

File "/Users/me/main_venv/lib/python3.11/site-packages/PIL/Image.py", line 858, in frombytes
    if self.width == 0 or self.height == 0:
       ^^^^^^^^^^
AttributeError: 'str' object has no attribute 'width'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants