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

example --ffmpeg-config? #18

Open
Nadano opened this issue Dec 7, 2021 · 12 comments
Open

example --ffmpeg-config? #18

Nadano opened this issue Dec 7, 2021 · 12 comments
Labels
question Further information is requested

Comments

@Nadano
Copy link

Nadano commented Dec 7, 2021

Would you mind giving an example of the arguments for this option? even the default option doesn't seem to work.

@mdraw
Copy link
Member

mdraw commented Dec 10, 2021

I have tested it on my machine and it works as intended with the example configuration, given a video file example.mp4:
$ deface --ffmpeg-config='{"codec": "libx265"}' example.mp4
and
$ deface --ffmpeg-config '{"codec": "libx265"}' example.mp4
work in bash and fish.
Please double-check that you have used the correct quotation marks (single quotes outside and double quotes inside), this is important.
If this still gives you an error, can you please share the error message with me?

@Cogitarian
Copy link

There is an interesting bug: when you try to deface with quality 10 the movie output is shorter and unreadble for quicktime, but with 9 it works nicely. It might be related to imageio I guess.
deface --ffmpeg-config '{"codec": "libx264", "quality": 9}' file.mp4

@mdraw mdraw added the question Further information is requested label Jun 7, 2022
@divajsz
Copy link

divajsz commented Feb 23, 2024

deface: error: argument --ffmpeg-config: invalid loads value: '{codec: libx264}'

this is what i receive :/ Do you have any recommendation? sometimes I get the imageio error but its not az image it is an mp4 file

also

(venv) PS D:\deface-master\deface> deface 'D:\GH010144.MP4'
Input: D:\GH010144.MP4
Output: D:\GH010144_anonymized.MP4
We had to kill ffmpeg to stop it.
Could not open file D:\GH010144.MP4 as a video file with imageio. Skipping file...

am I doing something wrong? I did work with a video same codec same filetype same camera before and now it stops with this one

@mdraw
Copy link
Member

mdraw commented Feb 26, 2024

@divajsz can you share the exact command that you used with the --ffmpeg-config option?
Note that the two types of quotation marks ' and " need to be correctly placed so that the config can be parsed.
I also see you are using a Windows system, where I haven't tested this option yet. So if you don't get it to work in a Windows console, I'd suggest trying bash or some other Unix/Linux shell to run it.

I don't know what is happening in your second issue. Can you open the video with ffprobe and ffplay? In your example:

 ffprobe 'D:\GH010144.MP4'
 ffplay 'D:\GH010144.MP4'

@divajsz
Copy link

divajsz commented Mar 11, 2024

You had your point, I had no FFMPEG installed. Since this PC is part of AD I have no admin rights at night but I could get over it with the "Set-ExecutionPolicy Bypass -Scope CurrentUser -Force" to get deface to be installed and to run

but

still if I have FFMPEG installed I have the same error

"(venv) PS D:\video> deface .\GH010144.MP4
Input: .\GH010144.MP4
Output: .\GH010144_anonymized.MP4
We had to kill ffmpeg to stop it.
Could not open file .\GH010144.MP4 as a video file with imageio. Skipping file...
(venv) PS D:\video>"

how can I convince it to use imageio-ffmpeg rather then imageio? since it is a video not a photo

@divajsz
Copy link

divajsz commented Mar 11, 2024

I copied your line from above

deface --ffmpeg-config='{"codec": "libx265"}' example.mp4

gives the error :

(venv) PS D:\ video> deface --ffmpeg-config='{"codec": "libx265"}' .\GH010144.MP4
usage: deface [--output O] [--thresh T] [--scale WxH] [--preview] [--boxes] [--draw-scores] [--mask-scale M]
              [--replacewith {blur,solid,none,img,mosaic}] [--replaceimg REPLACEIMG] [--mosaicsize width]
              [--keep-audio] [--ffmpeg-config FFMPEG_CONFIG] [--backend {auto,onnxrt,opencv}]
              [--execution-provider EP] [--version] [--keep-metadata] [--help]
              [input ...]
deface: error: argument --ffmpeg-config: invalid loads value: '{codec: libx265}'

but as I said, I copied the line not to mess up with brackets ""

Btw I'm on win10 with python 3.12.2

also I tried to install onnx onnxruntime-gpuget modules but they do not get installed :/

@divajsz
Copy link

divajsz commented Mar 11, 2024

I have notices this issue:

#2

And I tried to upgrade imageio but it is already the latest:

(venv) PS D:\video> pip install --upgrade imageio
Requirement already satisfied: imageio in c:\users\.......\venv\lib\site-packages (2.34.0)
Requirement already satisfied: numpy in c:\users\.........\venv\lib\site-packages (from imageio) (1.26.4)
Requirement already satisfied: pillow>=8.3.2 in c:\users\.............\venv\lib\site-packages (from imageio) (10.2.0)
(venv) PS D:\video>

still it gives this error for the following command:
python3 -c "import imageio; next(iter(imageio.get_reader('cut.mp4')))"

output:

(venv) PS D:\video> python3 -c "import imageio; next(iter(imageio.get_reader('GH010144.mp4')))"
We had to kill ffmpeg to stop it.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\...........\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\imageio\v2.py", line 293, in get_reader
    return image_file.legacy_get_reader(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...........\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\imageio\core\legacy_plugin_wrapper.py", line 116, in legacy_get_reader
    return self._format.get_reader(self._request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...........\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\imageio\core\format.py", line 221, in get_reader
    return self.Reader(self, request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...........\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\imageio\core\format.py", line 312, in __init__
    self._open(**self.request.kwargs.copy())
  File "C:\Users\...........\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\imageio\plugins\ffmpeg.py", line 343, in _open
    self._initialize()
  File "C:\Users\...........\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\imageio\plugins\ffmpeg.py", line 494, in _initialize
    self._meta.update(self._read_gen.__next__())
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\...........\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\imageio_ffmpeg\_io.py", line 297, in read_frames
    raise IOError(fmt.format(err2))
OSError: Could not load meta information
=== stderr ===

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  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
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100

@divajsz
Copy link

divajsz commented Mar 14, 2024

@mdraw do you have any suggestion?

@divajsz
Copy link

divajsz commented Mar 20, 2024

Reinstalled with python 3.7 and deface is working fine (onnx is not installing but it is a different issue)

@divajsz
Copy link

divajsz commented Mar 21, 2024

Hi All!

I managed to set up deface in Win10 enviroment with Python 3.7 installed from the Store app. I had some ups and downs so I wanted to share a kind of manual how I got to a working deface with compiled onnx module. I have not got to CUDA yet but I'll try in the future.

So first get Python 3.7 from the store. You click it, it gets installed, so far so good. 3.12 is available but I got trouble with it (imageio gets error and deface doesn't start ) and I ended up as an other poster in the issues section so just go on with 3.7 for now.

start powershell from start menu by typeing and hit enter

create a virtual enviroment:
python -m venv venv

Since my laptop is part of a company domain I had to allow running scripts on the machine which can be made with the following
code
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

you need to use it otherwise you wont be able to activate the enviroment with this:
.\venv\Scripts\activate

install deface
python -m pip install deface

install cmake (only if you want onnx later. for comparison what takes 4-5 hours to deface with onnx it can be reduced to 70 minutes)
python -m pip install cmake

install dlib too
pip install dlib

to be able to build wheel you need visual studio community edition2022 (mine is 17.9.4) with python developement and desktop developement C++. Download and install

Then you need to setup your path otherwise wheel build will fail with error "FileTracker : error FTK1011: could not create the new file tracking log file"
To prevent this check on your path enviroment variable
$env:Path

You have a string, add up this at the end:
C:\Users......USERNAME..........\AppData\Local\Temp;c:\TEMP;
$env:Path='Your original string;:\Users\......USERNAME..........\AppData\Local\Temp\;c:\TEMP\;'

Then add these two, I've found them as a solution for the error above:
$env:TEMP ="C:\TEMP\"
$env:TMP ="C:\TEMP\"

The compiler hits the possible length of a path so you need to modify this key in the registry not to have this "file not found" error during compilation

\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled must be a DWORD 1

Then install onnx related stuff
python -m pip install onnx onnxruntime-gpu onnxruntime onnxruntime-directml

onnx is not available as binary so python will start to compile it with cmake. It takes a lot of time but at the end onnx will be installed (currently 1.15.0)

Since I could not set up cuda yet I tried I installed the directml module and it works fine. Which takes the original Execution provider CPU for 4-5 hours the directml does it for 1hours 15 minutes.

let me show you my package lists to check if you have the same (in an activated venv type pip list to see yours)

Package              Version
-------------------- ---------
cmake                3.28.3
colorama             0.4.6
coloredlogs          15.0.1
deface               1.5.0
flatbuffers          24.3.7
humanfriendly        10.0
imageio              2.34.0
imageio-ffmpeg       0.4.9
lazy_loader          0.3
mpmath               1.3.0
networkx             3.2.1
numpy                1.26.4
onnx                 1.15.0
onnxruntime          1.17.1
onnxruntime-directml 1.17.1
onnxruntime-gpu      1.17.1
opencv-python        4.9.0.80
packaging            24.0
pillow               10.2.0
pip                  24.0
protobuf             5.26.0
pyreadline3          3.4.1
scikit-image         0.22.0
scipy                1.12.0
setuptools           69.2.0
sympy                1.12
tifffile             2024.2.12
tqdm                 4.66.2
typing_extensions    4.10.0

I hope you can make it work too, if I get on with cuda I'll let you know

@StealUrKill
Copy link

I copied your line from above

deface --ffmpeg-config='{"codec": "libx265"}' example.mp4

gives the error :

(venv) PS D:\ video> deface --ffmpeg-config='{"codec": "libx265"}' .\GH010144.MP4
usage: deface [--output O] [--thresh T] [--scale WxH] [--preview] [--boxes] [--draw-scores] [--mask-scale M]
              [--replacewith {blur,solid,none,img,mosaic}] [--replaceimg REPLACEIMG] [--mosaicsize width]
              [--keep-audio] [--ffmpeg-config FFMPEG_CONFIG] [--backend {auto,onnxrt,opencv}]
              [--execution-provider EP] [--version] [--keep-metadata] [--help]
              [input ...]
deface: error: argument --ffmpeg-config: invalid loads value: '{codec: libx265}'

but as I said, I copied the line not to mess up with brackets ""

Btw I'm on win10 with python 3.12.2

also I tried to install onnx onnxruntime-gpuget modules but they do not get installed :/

So the issue is Windows and how the command line works.

You need to input it like this

deface --ffmpeg-config "{"codec": "libx265"}" example.mp4

You can check my RC branch fork that has a GUI and face recognition that gives examples for the json config in the help file. In the GUI it's not required.

@StealUrKill
Copy link

Hi All!

I managed to set up deface in Win10 enviroment with Python 3.7 installed from the Store app. I had some ups and downs so I wanted to share a kind of manual how I got to a working deface with compiled onnx module. I have not got to CUDA yet but I'll try in the future.

So first get Python 3.7 from the store. You click it, it gets installed, so far so good. 3.12 is available but I got trouble with it (imageio gets error and deface doesn't start ) and I ended up as an other poster in the issues section so just go on with 3.7 for now.

start powershell from start menu by typeing and hit enter

create a virtual enviroment:
python -m venv venv

Since my laptop is part of a company domain I had to allow running scripts on the machine which can be made with the following
code
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

you need to use it otherwise you wont be able to activate the enviroment with this:
.\venv\Scripts\activate

install deface
python -m pip install deface

install cmake (only if you want onnx later. for comparison what takes 4-5 hours to deface with onnx it can be reduced to 70 minutes)
python -m pip install cmake

install dlib too
pip install dlib

to be able to build wheel you need visual studio community edition2022 (mine is 17.9.4) with python developement and desktop developement C++. Download and install

Then you need to setup your path otherwise wheel build will fail with error "FileTracker : error FTK1011: could not create the new file tracking log file"
To prevent this check on your path enviroment variable
$env:Path

You have a string, add up this at the end:
C:\Users......USERNAME..........\AppData\Local\Temp;c:\TEMP;
$env:Path='Your original string;:\Users\......USERNAME..........\AppData\Local\Temp\;c:\TEMP\;'

Then add these two, I've found them as a solution for the error above:
$env:TEMP ="C:\TEMP\"
$env:TMP ="C:\TEMP\"

The compiler hits the possible length of a path so you need to modify this key in the registry not to have this "file not found" error during compilation

\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled must be a DWORD 1

Then install onnx related stuff
python -m pip install onnx onnxruntime-gpu onnxruntime onnxruntime-directml

onnx is not available as binary so python will start to compile it with cmake. It takes a lot of time but at the end onnx will be installed (currently 1.15.0)

Since I could not set up cuda yet I tried I installed the directml module and it works fine. Which takes the original Execution provider CPU for 4-5 hours the directml does it for 1hours 15 minutes.

let me show you my package lists to check if you have the same (in an activated venv type pip list to see yours)

Package              Version
-------------------- ---------
cmake                3.28.3
colorama             0.4.6
coloredlogs          15.0.1
deface               1.5.0
flatbuffers          24.3.7
humanfriendly        10.0
imageio              2.34.0
imageio-ffmpeg       0.4.9
lazy_loader          0.3
mpmath               1.3.0
networkx             3.2.1
numpy                1.26.4
onnx                 1.15.0
onnxruntime          1.17.1
onnxruntime-directml 1.17.1
onnxruntime-gpu      1.17.1
opencv-python        4.9.0.80
packaging            24.0
pillow               10.2.0
pip                  24.0
protobuf             5.26.0
pyreadline3          3.4.1
scikit-image         0.22.0
scipy                1.12.0
setuptools           69.2.0
sympy                1.12
tifffile             2024.2.12
tqdm                 4.66.2
typing_extensions    4.10.0

I hope you can make it work too, if I get on with cuda I'll let you know

You only want one installed. Each next install overwrites the folder they share in site-packages

onnxruntime 1.17.1
onnxruntime-directml 1.17.1
onnxruntime-gpu 1.17.1

Choose one

To get cuda you need

Cuda toolkit
Cuddn

If tensor you need the tensor rt package to add to cuddn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants