Updated Readme

This commit is contained in:
2026-06-29 09:51:27 +03:00
parent 4a90885527
commit d9ed47aaba
2 changed files with 19 additions and 28 deletions
+7 -10
View File
@@ -24,7 +24,7 @@ pip install -r requirements(3.12).txt
## Usage:
```
python .\rembg_video.py [-h] [--help] [-o] [--model] [--workers] [--smooth] [--read-ahead] [--write-buffer] input
python .\rembg_video.py [-h] [--help] [-o] [--model] [--workers] [--smooth] [--smooth-workers] [--buffer-size] input
```
<style>
table {
@@ -52,9 +52,13 @@ th:nth-child(2) {
<div style="display: flex; gap: 20px; align-items: flex-start;">
<table>
<tr><th colspan="2">Optional Arguments:</th></tr>
<tr><td>-o</td><td>Output Path</td></tr>
<tr><td>-h --help</td><td>Show Help</td></tr>
<tr><td>-o</td><td>Output path</td></tr>
<tr><td>-h --help</td><td>Show help</td></tr>
<tr><td>--model</td><td>Choose model for rembg</td></tr>
<tr><td>--workers</td><td>Number of concurrent process workers</td></tr>
<tr><td>--smooth</td><td>Size of window for temporal smoothing</td></tr>
<tr><td>--smooth-workers</td><td>Number of CPU threads for temporal smoothing</td></tr>
<tr><td>--buffer-size</td><td>Set size of processing buffer</td></tr>
</table>
<table>
@@ -62,10 +66,3 @@ th:nth-child(2) {
<tr><td>input</td><td>Input Video</td></tr>
</table>
</div>
optional arguments:
-h, --help show this help message and exit
-o Set output path (Default: export/output.mov)
-
Tip: [Alpha matting can be used to refine the results](https://github.com/danielgatis/rembg#advance-usage)
+11 -17
View File
@@ -41,16 +41,10 @@ parser.add_argument(
help="Temporal mask smoothing window size in frames (default: 3, 0 to disable)",
)
parser.add_argument(
"--read-ahead",
"--buffer-size",
type=int,
default=8,
help="Number of frames to read ahead into buffer (default: 8)",
)
parser.add_argument(
"--write-buffer",
type=int,
default=8,
help="Number of processed frames to buffer before writing (default: 8)",
help="Set maximum number of frames in buffer (default: 8)",
)
parser.add_argument(
"--smooth-workers",
@@ -75,9 +69,9 @@ def is_oom_error(exc):
)
def image_to_png_bytes(image):
def image_to_bytes(image):
with io.BytesIO() as buffer:
image.save(buffer, format="PNG")
image.save(buffer, format="BMP")
return buffer.getvalue()
@@ -99,7 +93,7 @@ def remove_with_fallback(image_bytes, session, scales=(1.0, 0.8, 0.6, 0.4)):
Image.Resampling.LANCZOS,
)
with io.BytesIO() as buffer:
resized.save(buffer, format="PNG")
resized.save(buffer, format="BMP")
scaled_bytes = buffer.getvalue()
scaled_output = remove(scaled_bytes, session=session)
@@ -107,11 +101,11 @@ def remove_with_fallback(image_bytes, session, scales=(1.0, 0.8, 0.6, 0.4)):
scaled_output_bytes = bytes(scaled_output)
elif isinstance(scaled_output, np.ndarray):
with io.BytesIO() as buffer:
Image.fromarray(scaled_output).save(buffer, format="PNG")
Image.fromarray(scaled_output).save(buffer, format="BMP")
scaled_output_bytes = buffer.getvalue()
elif isinstance(scaled_output, Image.Image):
with io.BytesIO() as buffer:
scaled_output.save(buffer, format="PNG")
scaled_output.save(buffer, format="BMP")
scaled_output_bytes = buffer.getvalue()
else:
raise RuntimeError(
@@ -126,7 +120,7 @@ def remove_with_fallback(image_bytes, session, scales=(1.0, 0.8, 0.6, 0.4)):
output_full = original.copy()
output_full.putalpha(alpha)
return image_to_png_bytes(output_full)
return image_to_bytes(output_full)
except Exception as exc:
last_exc = exc
@@ -185,8 +179,8 @@ try:
args.model, providers=["CUDAExecutionProvider", "CPUExecutionProvider"]
)
read_queue = Queue(maxsize=args.read_ahead)
write_queue = Queue(maxsize=args.write_buffer)
read_queue = Queue(maxsize=args.buffer_size)
write_queue = Queue(maxsize=args.buffer_size)
errors = []
active_processors = [
args.workers
@@ -280,7 +274,7 @@ try:
# overwriting processed_dir in place. Overlapping windows mean a
# frame can be a *read* dependency for several write_idx tasks;
# writing in place risked one thread reading a file while another
# was mid-save on it (truncated/corrupt PNG -> shape errors).
# was mid-save on it (truncated/corrupt BMP -> shape errors).
smoothed_dir = processed_dir + "_smoothed"
if not os.path.isdir(smoothed_dir):
os.mkdir(smoothed_dir)