nadermx / backgroundremover

Background Remover lets you Remove Background from images and video using AI with a simple command line interface that is free and open source.
https://www.backgroundremoverai.com
MIT License
6.7k stars 558 forks source link

File output is 0 bytes #84

Closed jagip360m closed 1 year ago

jagip360m commented 1 year ago

I run the command

backgroundremover -i "/path/to/video.mp4" -tv -o "output.mov"

the process runs but the file it outputs is 0 bytes of size.

D:\Programfiles>backgroundremover -i "D:/vid.mp4" -tv -o "ou11tput.mov" FRAME RATE DETECTED: 30/1 (if this looks wrong, override the frame rate) FRAME RATE: 30 TOTAL FRAMES: 293 WORKER 0 ONLINE WORKER FRAMERIPPER ONLINE ffmpeg version 2023-06-11-git-09621fd7d9-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers built with gcc 12.2.0 (Rev10, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint libavutil 58. 13.100 / 58. 13.100 libavcodec 60. 17.100 / 60. 17.100 libavformat 60. 6.100 / 60. 6.100 libavdevice 60. 2.100 / 60. 2.100 libavfilter 9. 8.101 / 9. 8.101 libswscale 7. 3.100 / 7. 3.100 libswresample 4. 11.100 / 4. 11.100 libpostproc 57. 2.100 / 57. 2.100 Input #0, rawvideo, from 'fd:': Duration: N/A, start: 0.000000, bitrate: 13824 kb/s Stream #0:0: Video: rawvideo (Y800 / 0x30303859), gray, 180x320, 13824 kb/s, 30 tbr, 30 tbn Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native)) Output #0, mp4, to 'C:\Users\jagip\AppData\Local\Temp\tmp_tys7i5l\matte.mp4': Metadata: encoder : Lavf60.6.100 Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p(tv, progressive), 180x320, q=2-31, 2000 kb/s, 30 fps, 15360 tbn Metadata: encoder : Lavc60.17.100 mpeg4 Side data: cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 0 vbv_delay: N/A [out#0/mp4 @ 00000213a2209180] video:244kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.858499% frame= 293 fps= 22 q=2.0 Lsize= 246kB time=00:00:09.73 bitrate= 207.4kbits/s speed=0.729x FINISHED ALL FRAMES (293)! Starting alphamerge after call

It seems to process all the frames but then outputs a blank file.

I updated the FFMPEG but that did not help.

Images work fine.

nadermx commented 1 year ago

If you try doing just the -mk does it work?

nadermx commented 1 year ago

also did you upgrade to the most recent version?

jagip360m commented 1 year ago

I tried the -mk and that worked with no problems and generated the matte correctly.

Here is the output:

FRAME RATE DETECTED: 30/1 (if this looks wrong, override the frame rate) FRAME RATE: 30 TOTAL FRAMES: 293 WORKER FRAMERIPPER ONLINE WORKER 0 ONLINE ffmpeg version 2023-06-11-git-09621fd7d9-full_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers built with gcc 12.2.0 (Rev10, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libaribcaption --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libcodec2 --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint libavutil 58. 13.100 / 58. 13.100 libavcodec 60. 17.100 / 60. 17.100 libavformat 60. 6.100 / 60. 6.100 libavdevice 60. 2.100 / 60. 2.100 libavfilter 9. 8.101 / 9. 8.101 libswscale 7. 3.100 / 7. 3.100 libswresample 4. 11.100 / 4. 11.100 libpostproc 57. 2.100 / 57. 2.100 Input #0, rawvideo, from 'fd:': Duration: N/A, start: 0.000000, bitrate: 13824 kb/s Stream #0:0: Video: rawvideo (Y800 / 0x30303859), gray, 180x320, 13824 kb/s, 30 tbr, 30 tbn Stream mapping: Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native)) Output #0, mp4, to 'C:\Jagi\output.matte.mp4': Metadata: encoder : Lavf60.6.100 Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p(tv, progressive), 180x320, q=2-31, 2000 kb/s, 30 fps, 15360 tbn Metadata: encoder : Lavc60.17.100 mpeg4 Side data: cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 0 vbv_delay: N/A [out#0/mp4 @ 0000021368c3abc0] video:244kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.858499% frame= 293 fps= 23 q=2.0 Lsize= 246kB time=00:00:09.73 bitrate= 207.4kbits/s speed=0.771x FINISHED ALL FRAMES (293)!


I pulled the most recent version yesterday of the repo and this is my first time using this application.

Then I tried to generate the .mov file with command

backgroundremover -i "vid.mp4" -tv -o "output2.mov"

And once again it resulted in the 0 byte file, Could it be that I have something wrong on generating mov files? Since the other is in mp4 format and I am using this on Windows 10.

jagip360m commented 1 year ago

I just confirmed it does generate the matte.mp4 to the temp folder.

I am quite sure the problem is when creating the end video or gif since neither works. I also tried to create an mp4 file with the command (yes I know mp4 does not support alpha) just to see if it can output a file bigger than 0 bytes. The resulting mp4 was also 0 bytes.

By the way, webM with vp8 and vp9 support would be great since the files sizes are smaller and mov files are not ideal for all use cases :)

nadermx commented 1 year ago

First thing first, submit a pull request, or let me know if you want me to do it. Where you take out all the nice code from the ffmpeg utilts, and I will push a version and you can try, then I can see into the formats..

Anyeos commented 1 year ago

Same here, 0 bytes size output file. The matte file is created under /tmp and when it finish it is removed automatically but the resulting output file is 0 bytes size. The GPU is working because it is being used in the process. All is working except the output file.

FRAME RATE DETECTED: 75/1 (if this looks wrong, override the frame rate)
FRAME RATE: 75 TOTAL FRAMES: 2455
WORKER FRAMERIPPER ONLINE
WORKER 0 ONLINE
ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 109056 kb/s
    Stream #0:0: Video: rawvideo (Y800 / 0x30303859), gray, 568x320, 109056 kb/s, 75 tbr, 75 tbn, 75 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> mpeg4 (native))
[swscaler @ 0x55f8d35de200] Warning: data is not aligned! This can lead to a speed loss
Output #0, mp4, to '/tmp/tmpkyya0uf1/matte.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: mpeg4 (mp4v / 0x7634706D), yuv420p, 568x320, q=2-31, 2000 kb/s, 75 fps, 19200 tbn, 75 tbc
    Metadata:
      encoder         : Lavc58.54.100 mpeg4
    Side data:
      cpb: bitrate max/min/avg: 0/0/2000000 buffer size: 0 vbv_delay: -1
frame= 2455 fps= 49 q=2.0 Lsize=    6413kB time=00:00:32.72 bitrate=1605.6kbits/s speed=0.649x    
video:6401kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.177281%
FINISHED ALL FRAMES (2455)!
Starting alphamerge
after call
Process finished
Anyeos commented 1 year ago

I modified the function "transparentvideo" in the file "utilities.py": The main problem is shell=True, because as I read using Shell=True pass the arguments directly to the shell. So you need one entire line as arguments array, you passed a str instead of an array with a str inside, so it was decoded as shell arguments only. And -loglevel 0 gives no stderr output at all, so you will never be notified about an error. And the return "ERROR: " part will never print something on terminal because it is a return not a print.

def transparentvideo(output, file_path,
                     worker_nodes,
                     gpu_batchsize,
                     model_name,
                     frame_limit=-1,
                     prefetched_batches=4,
                     framerate=-1):
    temp_dir = tempfile.TemporaryDirectory()
    tmpdirname = Path(temp_dir.name)
    temp_file = os.path.abspath(os.path.join(tmpdirname, "matte.mp4"))
    matte_key(temp_file, file_path,
              worker_nodes,
              gpu_batchsize,
              model_name,
              frame_limit,
              prefetched_batches,
              framerate)
    print("Starting alphamerge")
    cmd = ["ffmpeg -y -nostats -i '%s' -i '%s' -filter_complex '[1][0]scale2ref[mask][main];[main][mask]alphamerge' -c:v qtrle -shortest '%s'" % (
        file_path, temp_file, output)]
    process = sp.Popen(cmd, shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
    stdout, stderr = process.communicate()
    print('after call')

    if stderr:
        print("ERROR: %s" % stderr.decode("utf-8"))
    print("Process finished")
    try:
        temp_dir.cleanup()
    except PermissionError:
        pass
    return
nadermx commented 1 year ago

Good catch, ill fix this unless you want to pr it

El dom, 2 de jul de 2023 22:24, Anyeos @.***> escribió:

I modified the function "transparentvideo" in the file "utilities.py": The main problem is shell=True, because as I read using Shell=True pass the arguments directly to the shell. So you need one entire line as arguments array, you passed a str instead of an array with a str inside, so it was decoded as shell arguments only. And -loglevel 0 gives no stderr output at all, so you will never be notified about an error. And the return "ERROR: " part will never print something on terminal because it is a return not a print.

def transparentvideo(output, file_path, worker_nodes, gpu_batchsize, model_name, frame_limit=-1, prefetched_batches=4, framerate=-1): temp_dir = tempfile.TemporaryDirectory() tmpdirname = Path(temp_dir.name) temp_file = os.path.abspath(os.path.join(tmpdirname, "matte.mp4")) matte_key(temp_file, file_path, worker_nodes, gpu_batchsize, model_name, frame_limit, prefetched_batches, framerate) print("Starting alphamerge") cmd = ["ffmpeg -y -nostats -i '%s' -i '%s' -filter_complex '[1][0]scale2ref[mask][main];[main][mask]alphamerge' -c:v qtrle -shortest '%s'" % ( file_path, temp_file, output)] process = sp.Popen(cmd, shell=True, stdout=sp.PIPE, stderr=sp.PIPE) stdout, stderr = process.communicate() print('after call')

if stderr:
    print("ERROR: %s" % stderr.decode("utf-8"))
print("Process finished")
try:
    temp_dir.cleanup()
except PermissionError:
    pass
return

— Reply to this email directly, view it on GitHub https://github.com/nadermx/backgroundremover/issues/84#issuecomment-1617262597, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABYACXHV4RRRP6WCNKLJC3LXOJCRXANCNFSM6AAAAAAZF6CF3Y . You are receiving this because you modified the open/close state.Message ID: @.***>

xheatcodes commented 1 year ago

same err

nadermx commented 1 year ago

Please run pip install --upgrade backgroundremover