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

Adding -vf to ffmpeg #34

Open
PMKrol opened this issue Feb 14, 2023 · 2 comments
Open

Adding -vf to ffmpeg #34

PMKrol opened this issue Feb 14, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@PMKrol
Copy link

PMKrol commented Feb 14, 2023

Hi!

I'm trying to execute this command:

deface --thresh 0.5 --ffmpeg-config '{"codec": "libx264",
"macro_block_size": 1, "ffmpeg_params": ["-crf","18", "-vf", "vidstabtransform=input=RPRq.trf:smoothing=10,smartblur=lr=1.5:ls=-0.25:lt=-3.5:cr=0.75:cs=0.250:ct=0.5"]}' RPRq-2.mp4

to execute all those three commands at once (tested and works for ffmpeg v5:

deface --thresh 0.5 --ffmpeg-config '{"codec": "libx264",
"macro_block_size": 1, "ffmpeg_params": ["-crf","18"]}' RPRq-2.mp4
ffmpeg  -loglevel quiet -stats -i RPRq-2_anonymized.mp4 -vf vidstabtransform=input=RPRq.trf:smoothing=10 -crf 18 RPRq-3.mp4
ffmpeg -loglevel quiet -stats -i RPRq-3.mp4 -vf "smartblur=lr=1.5:ls=-0.25:lt=-3.5:cr=0.75:cs=0.250:ct=0.5" -crf 18 RPRq-4.mp4

But I'm getting this:

Input:  RPRq-2.mp4
Output: RPRq-2_anonymized.mp4
  0%|                                                                                                                                                 | 1/1797 [00:00<24:10,  1.24it/s]Traceback (most recent call last):
  File "/home/san/.local/lib/python3.8/site-packages/imageio_ffmpeg/_io.py", line 630, in write_frames
    p.stdin.write(bb)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/san/.local/bin/deface", line 8, in <module>
    sys.exit(main())
  File "/home/san/.local/lib/python3.8/site-packages/deface/deface.py", line 360, in main
    video_detect(
  File "/home/san/.local/lib/python3.8/site-packages/deface/deface.py", line 162, in video_detect
    writer.append_data(frame)
  File "/home/san/.local/lib/python3.8/site-packages/imageio/core/format.py", line 590, in append_data
    return self._append_data(im, total_meta)
  File "/home/san/.local/lib/python3.8/site-packages/imageio/plugins/ffmpeg.py", line 604, in _append_data
    self._write_gen.send(im)
  File "/home/san/.local/lib/python3.8/site-packages/imageio_ffmpeg/_io.py", line 637, in write_frames
    raise IOError(msg)
OSError: [Errno 32] Broken pipe

FFMPEG COMMAND:
/home/san/.local/lib/python3.8/site-packages/imageio_ffmpeg/binaries/ffmpeg-linux64-v4.2.2 -y -f rawvideo -vcodec rawvideo -s 960x1080 -pix_fmt rgb24 -r 29.97 -i - -an -vcodec libx264 -pix_fmt yuv420p -v warning -vf vidstabtransform=input=RPRq.trf:smoothing=10,smartblur=lr=1.5:ls=-0.25:lt=-3.5:cr=0.75:cs=0.250:ct=0.5 /media/Data/GoPro/test/RPRq-2_anonymized.mp4

FFMPEG STDERR OUTPUT:

  0%|                                                                                                                                               | 1/1797 [00:02<1:03:25,  2.12s/it]

There is no problem with rights to write to file and I don't have any other idea...

And verbose output:

deface --thresh 0.5 --ffmpeg-config '{"codec": "libx264", "macro_block_size": 1, "ffmpeg_params": ["-vf", "vidstabtransform=input=RPRq.trf:smoothing=10,smartblur=lr=1.5:ls=-0.25:lt=-3.5:cr=0.75:cs=0.250:ct=0.5", "-v", "40"]}' RPRq-2.mp4
Input:  RPRq-2.mp4
Output: RPRq-2_anonymized.mp4
  0%|                                                                                                                                                 | 1/1797 [00:00<17:38,  1.70it/s]Input #0, rawvideo, from 'pipe:':
  Duration: N/A, start: 0.000000, bitrate: 745749 kb/s
    Stream #0:0: Video: rawvideo, 1 reference frame (RGB[24] / 0x18424752), rgb24, 960x1080, 745749 kb/s, 29.97 tbr, 29.97 tbn, 29.97 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))
[Parsed_vidstabtransform_0 @ 0x6ddd080] vidstabtransform filter: init v1.1 (2015-05-16)
[Parsed_smartblur_1 @ 0x6de7a00] luma_radius:1.500000 luma_strength:-0.250000 luma_threshold:-4 chroma_radius:0.750000 chroma_strength:0.250000 chroma_threshold:0                     
[graph 0 input from stream 0:0 @ 0x6dea380] w:960 h:1080 pixfmt:rgb24 tb:100/2997 fr:2997/100 sar:0/1 sws_param:flags=2                                                                
[auto_scaler_0 @ 0x6dee280] w:iw h:ih flags:'bicubic' interl:0                                                                                                                         
[Parsed_smartblur_1 @ 0x6de7a00] auto-inserting filter 'auto_scaler_0' between the filter 'Parsed_vidstabtransform_0' and the filter 'Parsed_smartblur_1'                              
[Parsed_vidstabtransform_0 @ 0x6ddd080] Video transformation/stabilization settings (pass 2/2):
[Parsed_vidstabtransform_0 @ 0x6ddd080]     input     = RPRq.trf
[Parsed_vidstabtransform_0 @ 0x6ddd080]     smoothing = 10
[Parsed_vidstabtransform_0 @ 0x6ddd080]     optalgo   = gauss
[Parsed_vidstabtransform_0 @ 0x6ddd080]     maxshift  = -1
[Parsed_vidstabtransform_0 @ 0x6ddd080]     maxangle  = -1.000000
[Parsed_vidstabtransform_0 @ 0x6ddd080]     crop      = Keep
[Parsed_vidstabtransform_0 @ 0x6ddd080]     relative  = True
[Parsed_vidstabtransform_0 @ 0x6ddd080]     invert    = False
[Parsed_vidstabtransform_0 @ 0x6ddd080]     zoom      = 0.000000
[Parsed_vidstabtransform_0 @ 0x6ddd080]     optzoom   = Static (1)
[Parsed_vidstabtransform_0 @ 0x6ddd080]     interpol  = Bi-Linear (2)
[vidstabtransform @ 0x7ffd5bcfcd50] Final zoom: 9.524674
[auto_scaler_0 @ 0x6dee280] w:960 h:1080 fmt:rgb24 sar:0/1 -> w:960 h:1080 fmt:yuv420p sar:0/1 flags:0x4
Traceback (most recent call last):
  File "/home/san/.local/lib/python3.8/site-packages/imageio_ffmpeg/_io.py", line 630, in write_frames
    p.stdin.write(bb)
BrokenPipeError: [Errno 32] Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/san/.local/bin/deface", line 8, in <module>
    sys.exit(main())
  File "/home/san/.local/lib/python3.8/site-packages/deface/deface.py", line 360, in main
    video_detect(
  File "/home/san/.local/lib/python3.8/site-packages/deface/deface.py", line 162, in video_detect
    writer.append_data(frame)
  File "/home/san/.local/lib/python3.8/site-packages/imageio/core/format.py", line 590, in append_data
    return self._append_data(im, total_meta)
  File "/home/san/.local/lib/python3.8/site-packages/imageio/plugins/ffmpeg.py", line 604, in _append_data
    self._write_gen.send(im)
  File "/home/san/.local/lib/python3.8/site-packages/imageio_ffmpeg/_io.py", line 637, in write_frames
    raise IOError(msg)
OSError: [Errno 32] Broken pipe

FFMPEG COMMAND:
/home/san/.local/lib/python3.8/site-packages/imageio_ffmpeg/binaries/ffmpeg-linux64-v4.2.2 -y -f rawvideo -vcodec rawvideo -s 960x1080 -pix_fmt rgb24 -r 29.97 -i - -an -vcodec libx264 -pix_fmt yuv420p -v warning -vf vidstabtransform=input=RPRq.trf:smoothing=10,smartblur=lr=1.5:ls=-0.25:lt=-3.5:cr=0.75:cs=0.250:ct=0.5 -v 40 /media/Data/GoPro/test/RPRq-2_anonymized.mp4

FFMPEG STDERR OUTPUT:

  0%|                                                                                                                                                 | 1/1797 [00:01<52:42,  1.76s/it]
@PMKrol
Copy link
Author

PMKrol commented Feb 14, 2023

Also, this works:
/home/user/.local/lib/python3.8/site-packages/imageio_ffmpeg/binaries/ffmpeg-linux64-v4.2.2 -i RPRq-2.mp4 -an -vcodec libx264 -pix_fmt yuv420p -v warning -crf 18 -vf vidstabtransform=input=RPRq.trf:smoothing=10,smartblur=lr=1.5:ls=-0.25:lt=-3.5:cr=0.75:cs=0.250:ct=0.5 -v 40 /media/Data/GoPro/test/RPRq-2_anonymized-test.mp4

@mdraw mdraw added bug Something isn't working help wanted Extra attention is needed labels Mar 6, 2023
@mdraw
Copy link
Member

mdraw commented Mar 6, 2023

I have tried this with my own test video and a .trf file from a vidstabdect run. My experience is the same: With the direct ffmpeg commands it works but supplying them to the ffmpeg config args in deface crashes the process. I haven't found out why that happens either. Replacing the vidstabtransform filter with the scale=-2:360 filter doesn't crash either so there seems to be either a problem specific to the vidstabtransform filter, with 2 pass filters or with the option parsing.

I don't know if that's a real alternative for your use case but on my machine the single-pass deshake filter works fine with deface. In your example that would be:

deface --thresh 0.5 --ffmpeg-config '{"codec": "libx264", "macro_block_size": 1, "ffmpeg_params": ["-crf","18", "-vf", "deshake"]}' RPRq-2.mp4

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

No branches or pull requests

2 participants