Apply feltpen filter on a video using Gmic on the command line

Hello,
First of all, thanks a million for releasing this wonderful piece of software!
I am using gmic on the command line to apply effects on a video. This works fine with some filters but not others. I am especially interested in the fx_feltpen filter and tried the following:

[noel@noel-latitude5490 Saint-Médard]$ gmic -w -apply_video saint-médard-soustraction-fond-kaiber-audio-original.mp4,\"-fx_feltpen 284,40.2,2.28,0.106,18.1,2,0\",0,5,1,flo-saint-médard-felt-pen.mp4

but got the following error:

[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Display image [] in 256x256 display window [0], with auto-normalization, no fullscreen and title '[G'MIC] Window #0'.[ WARN:0@0.175] global cap_gstreamer.cpp:1426 open OpenCV | GStreamer warning: Error opening bin: unexpected reference "check_opencv" - ignoring
[ WARN:0@0.175] global cap_gstreamer.cpp:1164 isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

[gmic]-0./ Apply command '-fx_feltpen 284,40.2,2.28,0.106,18.1,2,0' on input video file 'saint-médard-soustraction-fond-kaiber-audio-original.mp4', with first frame 0, last frame 5, frame step 1 and output filename 'flo-saint-médard-felt-pen.mp4'.
  > Frame #0        
[gmic] *** Error in ./apply_video/ *** Command 'apply_stream': Specified command errored: *** Error in ./apply_video/_apply_stream/*do/(...)/*foreach/s3d/_split3d/*foreach/ *** Command 'crop': Invalid argument '0,,0,-1'.

Is there anything I am doing wrong?
Thank you very much in advance for your help.
Best,
Jerome

Has G’MIC been compiled with OpenCV (This is not done, usually)? Are the OpenCV libraries available on your system?

There are workarounds. -apply_video is a handy convenience iterator, but there are other means to process image sequences.

Thank you for your quick reply.
I am under Manjaro Linux and installed gmic from the PAMAC package manager. Opencv is installed and I see that it is in the dependencies list for the gmic binary in PAMAC (opencv2 is not installed though).
I note that other filters work fine with apply_video (cl_comic, lineart), if that makes a difference.
I am open to alternatives, if needed :slight_smile:
Best,
Jerome

OpenCV: You have it. Tried it here with a machine known not to have OpenCV and gmic has been compiled without it. Error message looks like this:

$ gmic -v + -w -apply_video cauldron.mp4,\"-fx_feltpen 284,40.2,2.28,0.106,18.1,2,0\",0,-1,1,cauldron-felt.mp4
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Increment verbosity level (set to 2).
[gmic]-0./ Display image [] in 256x256 display window [0], with auto-normalization, no fullscreen and title '[G'MIC] Window #0'.
[gmic] *** Error in ./apply_video/ *** Command 'apply_video': No OpenCV features available. Your G'MIC interpreter has not been compiled with OpenCV support.

NB: ‘cauldron.mp4’ is just a test video.
That you have used apply_video successfully in other cases also confirms that you have Opencv installed. OpenCV is not an issue.

Here is a simple-minded approach which does not involve very much G’MIC machinery, but is memory-intensive, as all frames are loaded at the same time. You appear to be processing just a few frames, though, so I do not think you will exhaust resources.

 gmic cauldron.mp4 foreach \{ -fx_feltpen. 284,40.2,2.28,0.106,18.1,2,0 \} o cauldron-felt.mp4,24,h264

I can’t debug apply_video here because I do not have OpenCV installed on this laptop; I cannot recreate the conditions where you experienced your error. However, if this simple-minded approach works, we can, perhaps, move up to more sophisticated means. Or you may be happy with this approach as is.

For cauldron.mp4 substitute your own

Hello Jérome,

I’ve tried the very same command here, on one .mp4 video, and it works for me (get some warnings from OpenCV on the terminal, but it outputs a new video file correctly).
Your issue may be then related to OpenCV unable to read the video frames for your particular video.

Just to get a better idea on what’s going on, does this command works:

gmic -w -apply_video input.mp4,\"b 5\"

?

Hi David,
Thank you for the feedback.
Yes, this last command works fine for me (on the very same video).
Jerome

Garry,
I tried your suggestion and got a very similar error related to a call to ‘crop’:

[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input all frames of file 'saint-médard-soustraction-fond-kaiber-audio-original.mp4' at position 0 (4110 images [0] = 1280x720x1x3, (...),[4109] = 1280x720x1x3).
[gmic] *** Error in ./*foreach/fx_feltpen/*foreach/(...)/*foreach/s3d/_split3d/*foreach/ *** Command 'crop': Invalid argument '0,,0,-1'.
[gmic] Command 'crop' has the following description: 

  crop (+):
      x0[%],x1[%],_boundary_conditions |
      x0[%],y0[%],x1[%],y1[%],_boundary_conditions |
      x0[%],y0[%],z0[%],x1[%],y1[%],z1[%],_boundary_conditions |
      x0[%],y0[%],z0[%],c0[%],x1[%],y1[%],z1[%],c1[%],_boundary_conditions

    Crop selected images with specified region coordinates.
    (equivalent to shortcut command 'z').

    'boundary_conditions' can be { 0=dirichlet | 1=neumann | 2=periodic | 
    3=mirror }.

    Default value: 'boundary_conditions=0'.

    Example:
      [#1] image.jpg +crop -230,-230,280,280,1 crop[0] -230,-230,280,280,0
      [#2] image.jpg crop 25%,25%,75%,75%

So this means this is not a problem when reading the video.
Maybe a problem when writing the output video ?
Could you test this :

$ gmic apply_video input.mp4,"blur 5",0,-1,1,output.mp4

If this works, then it’s a problem with the filter and to understand what is going on, it would be nice if I can download the input video to reproduce the issue on my machine (as apparently it works with other videos, so your video has something special ! ).

FYI, I’ve been able to test the video of @Jorca , and it seems the issue (at least on latest G’MIC 3.2.5) is caused by OpenCV’s VideoCapture which does not open filename with accentuated characters in it.
Renaming the file without accents makes the process work.

2 Likes