HypoX64 / DeepMosaics

Automatically remove the mosaics in images and videos, or add mosaics to them.
GNU General Public License v3.0
2.08k stars 435 forks source link

enabling PNG conversion gives worse output than JPG #73

Open suphamster opened 3 years ago

suphamster commented 3 years ago

If PNG enabled then output video gamma/colors differs much from source video and when using JPG it has the same gamma/colours.

d0ne187 commented 2 years ago

If you run the master code you can edit the util/ffmpeg.py under the image2video line to tell ffmpeg how to convert the color format. I got the parameters from google, but the result looks almost the same as the source to me using the PNG option. The line looks like this in my file: os.system('ffmpeg -y -r '+str(fps)+' -i '+imagepath+' -vcodec libx264 -crf 20 -tune film -preset slow -pix_fmt yuv420p -vf colormatrix=bt601:bt709 -sws_flags +accurate_rnd+full_chroma_int '+os.path.split(voicepath)[0]+'/video_tmp.mp4')

suphamster commented 2 years ago

Thanks, will try it. Btw how do u run from master code? I'm a noob at Python so when I run deepmosaic.py from Pyhon 3.7 (prerequisites installed of cause) directly it says that I have some missing dll's (not tells what exactly) and don't run but when run same script from VS 2019 it works fine but problem is to sent command line variables to VS 2019 like in developer's example "python deepmosaic.py --media_path ./imgs/ruoruo.jpg --model_path ./pretrained_models/mosaic/add_face.pth --gpu_id 0".

d0ne187 commented 2 years ago

I also just installed Python (3.6 in my case), then I installed Cuda 10.2, then pytorch following the instructions on their homepage for Cuda 10.2 (pip3 install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio===0.10.1+cu102 -f https://download.pytorch.org/whl/cu102/torch_stable.html) and then the prerequisites.txt (minus torchvision and torch) and then I just run the example line you posted. You also need to put the ffmpeg files (ffmpeg.exe, ffplay.exe,ffprobe.exe) into the root folder where the deepmosaic.py is located.

mirh commented 2 years ago

This is a combination of two ffmpeg bugs (please edit the title, this is about colorspace being wrong, not worse "quality" per se)

First the tool doesn't tag the final video with the proper colorspace, so poor video players have to guess it. Just about every operation targets bt.601, so you have to hope they can take the right stab, but alas divination would be easier.

Why this doesn't affect jpeg though? Because of another bug where they forget to take into account the color space/matrix when converting to full range. So, I don't have OP's source video, but I can imagine it was tagged bt.709, which is then incorrectly converted to jpg, only to be finally incorrectly "stored" in the output video file. (if the input was untagged bt.709 instead, even png would probably be fine)