blind icon indicating copy to clipboard operation
blind copied to clipboard

Blind And ImageMagick

Open cheznewa opened this issue 3 years ago • 4 comments

Hello, is possible to add command blind-imagemagick for run convert imagemagick for each frames. for example ::::::::::: blind-imagemagick -colorspace gray for each frames is :::::::: convert framesSTDIn -colorspace gray frameSTDOut

cheznewa avatar Jul 01 '21 09:07 cheznewa

You can already accomplish this using a loop and already provided tools, and you can use any external command and easily create pipelines. I don't like having commands that are specific to specific external commands, if a tool for running an external command would be added, and I currently don't thing it is a good idea, it should allow you to specify the external command.

You could implement blind-imagemagick as (with reservations for errors):

#!/bin/bash -e
# ksh may also work
read nframes width height pixfmt < <(blind-read-head)
blind-write-head $nframes $width $height $pixfmt
while { set +e; blind-next-frame $width $height $pixfmt;
                status=$?;
        set -e; } | \
      blind-to-image | \
      imagemagick "$@" | \
      blind-from-image -h -p; \
      test $status = 0; do
          :;
done # (-p for `blind-from-image` is optional)
test $status = 1

maandree avatar Jul 01 '21 09:07 maandree

Thanks, I just modify convert pam:- $@ pam:- In Line 9 But Show Two Error :::::::::: blind-imagemagick: ligne 11 : test: = : opérateur unaire attendu blind-imagemagick: ligne 14 : test: = : opérateur unaire attendu

cheznewa avatar Jul 02 '21 02:07 cheznewa

Ok, new attempt:

#!/bin/bash -e
# ksh does not work
read nframes width height pixfmt < <(blind-read-head)
blind-write-head $nframes $width $height $pixfmt
while blind-next-frame $width $height $pixfmt | \
      blind-to-image | \
      convert pam:- "$@" pam:- | \
      blind-from-image -h -p; \
      status=( ${PIPESTATUS[@]} );
      test ${status[0]} = 0; do
          test ${status[1]} = 0;
          test ${status[2]} = 0;
          test ${status[3]} = 0;
          test ${status[4]} = 0;
done # (-p for `blind-from-image` is optional)
test ${status[0]} = 1

A cosmetic imperfection here is that the commands will fail when blind-next-frame says that there are no more frames. This can be solved if you have an implementation of ifne that can peeks the input file (uses tee for pipes, MSG_PEEK for sockets, stat/pread for regular files):

#!/bin/bash -e
# ksh also works
set -o pipefail
read nframes width height pixfmt < <(blind-read-head)
blind-write-head $nframes $width $height $pixfmt
while ifne -n false; do
    blind-next-frame $width $height $pixfmt | \
    blind-to-image | \
    convert pam:- "$@" pam:- | \
    blind-from-image -h -p # (-p is optional)
    test $? = 0 # not needed if using bash
done

(It is not possible to just run the loop $nframes times, as $nframes may be 0. Tools should not depend on the value unless absolutely necessary, as it is not always set because it can be too costly.)

maandree avatar Jul 02 '21 19:07 maandree

I A Problem! I Good You Post My Script But :::::::::::::: blind-from-video without -L Option Input And Output Dont Out The Header File, So The Command blind-read-head Show An Error

cheznewa avatar Jul 28 '21 05:07 cheznewa