Jafea7/ctbrec-debian

Add a folder for custom postprocessing scripts?

Closed this issue · 7 comments

Mounting a folder to docker, something like /app/scripts, will be helpful.

Just add a volume mapping to your 'docker run' or docker-compare.yml

Will do. But I think it might be easier for people to modify the included scripts.

Problem is, as far as I've tried, external scripts wouldn't run, they had to be within the image along with any extra executables they need.

Also, it's not needed to modify the included scripts, they're here on GitHub, just copy them to your mapped volume and modify the copy.

Looks like I need to login the container and change the permissions of the scripts as well.

My plan is to use curl to POST the postprocessing arguments to outside the docker, which should be enough for me.
So I think include a script that "forward postprocessing arguments to a http endpoint" might be useful.

It'd be easier if you write one up and I include it in the image, would save a lot of to and fro with explanations, etc.

I am a windows user and I never wrote any shell script before, so if you have any improvement just change it.


#!/bin/sh

# send2http.sh ${absolutePath} [${modelName} ${localDateTime(YYYYMMDD-HHmmss)} ...]

file="$1"
rel=`echo ${file} | cut -c 15-`
sheet="${file%.*}.jpg"

length=`/app/ffmpeg/ffmpeg -i "$file" 2>&1 | grep "Duration" | cut -d ' ' -f 4 | sed s/,// | sed 's@\..*@@g'`
shift

args=`echo $@ | base64`

if [ -z ${CURL_GET} ]; then
    args="-F file=${rel} -F sheet=@$sheet -F duration=${length} -F argv=${args}" 
else
    args="-G --data-urlencode file=${rel} --data-urlencode duration=${length} --data-urlencode argv=${args}" 
fi

curl ${args} ${CURL_ARGS} "${HTTP_URL}"
Send a POST request to an URL with postprocessing params.

Data will be send as `multipart/form-data`

| Form Field    |                                                     |
|----------|----------------------------------------------------------|
| file     | reletive path of the recording                           |
| sheet    | the contact sheet file                                   |
| duration | recording file length, format: `hh:mm:ss`                |
| argv     | `script.params` string set in server.json, base64encoded |

USAGE:

1. Server Config
`server.json` add a new entry, the first cli params must be `${absolutePath}`, and you can add rest of what you need.

\```json
    {
      "type": "ctbrec.recorder.postprocessing.Script",
      "config": {
        "script.params": "${absolutePath} ${modelDisplayName} ${siteName} ${localDateTime(yyyyMMdd-HHmmss)}",
        "script.executable": "/app/send2http.sh"
      }
    }
\```

4. Environment Variables

|           | Usage                                 |
|-----------|---------------------------------------|
| HTTP_URL  | the url will send the http request to |
| CURL_ARGS | extra CURL arguments                  |
| CURL_GET  | Send GET requests instead, no contact sheet   |

*Use `ifconfig` to get docker host IP, usually be `172.17.0.1`*

Since my original issue was resolved, closing for now.

Send me a DM on the CTBRec Discord server in case I have any questions.