M: assume i have a linux script named split-basic.sh that is used to quickly split MOV files like this: split-basic.sh input.mov output.mov start [end] i need a wrapper-use script that uses that script and/or ffmpeg (for screenshots) that prompts for user input, following these rules, assuming that the script is run inside a directory containing movie files: { ask for the video filename to use for the script; if this input is left blank, exit the script; if the named file does not exist, echo the name given (for debugging purposes) and exit the script; otherwise, store the filename base and extension for use in the rest of the script (i'll call those 'F' and 'E' respectively for the rest of this description). create a numerical variable V, initialized to 1, which will be appended to F for creation of unique filenames in the rest of the script. begin an input loop that takes three user inputs: begin point ('BEGIN'), end point ('END'), and screenshot point ('SCREEN'), executes different actions depending on whether those inputs have a value or are left empty, and increments V. the action combinations are: { if BEGIN and END are left blank { if SCREEN is blank, exit the script. otherwise, take a screenshot at the timestamp SCREEN using ffmpeg named F-SCREEN.jpg. } if BEGIN is blank, END has content { use split-basic.sh on F.E to create F-V.E from 00:00:00.000 to END. if SCREEN has content, take a screenshot at timestamp SCREEN using ffmpeg named F-V.jpg. } if BEGIN has content but END is blank { use split-basic.sh on F.E to create F-V.E from BEGIN to the movie end. if SCREEN has content, take a screenshot at timestamp SCREEN using ffmpeg named F-V.jpg. } otherwise { use split-basic.sh on F.E to create F-V.E from BEGIN to END. if SCREEN has content, take a screenshot at timestamp SCREEN using ffmpeg named F-V.jpg. } } } do not attempt to handle errors or special cases or anything similar with this script; just build the script as described.
G:
#!/bin/bash
# wrapper-use.sh
# Assumes split-basic.sh is in PATH or current directory
# Run inside a directory containing movie files
read -p "Video filename: " FILE
if [ -z "$FILE" ]; then
exit 0
fi
if [ ! -f "$FILE" ]; then
echo "$FILE"
exit 0
fi
F="${FILE%.*}"
E="${FILE##*.}"
V=1
while true; do
read -p "BEGIN: " BEGIN
read -p "END: " END
read -p "SCREEN: " SCREEN
if [ -z "$BEGIN" ] && [ -z "$END" ]; then
if [ -z "$SCREEN" ]; then
exit 0
else
ffmpeg -ss "$SCREEN" -i "$FILE" -frames:v 1 "${F}-${SCREEN}.jpg"
V=$((V+1))
continue
fi
fi
if [ -z "$BEGIN" ] && [ -n "$END" ]; then
./split-basic.sh "$FILE" "${F}-${V}.${E}" "00:00:00.000" "$END"
elif [ -n "$BEGIN" ] && [ -z "$END" ]; then
./split-basic.sh "$FILE" "${F}-${V}.${E}" "$BEGIN"
else
./split-basic.sh "$FILE" "${F}-${V}.${E}" "$BEGIN" "$END"
fi
if [ -n "$SCREEN" ]; then
ffmpeg -ss "$SCREEN" -i "$FILE" -frames:v 1 "${F}-${V}.jpg"
fi
V=$((V+1))
doneM: nice. please make another script with the same instructions, but two additions: one, split-basic.sh is definitely in PATH. two, make it so that: if V != 1 and every input is not a blank (indicating a halt of the script), it is assumed that the new BEGIN is equal to the last END.
G:
#!/bin/bash
# wrapper-use-2.sh
# Assumes split-basic.sh is in PATH
# Run inside a directory containing movie files
read -p "Video filename: " FILE
if [ -z "$FILE" ]; then
exit 0
fi
if [ ! -f "$FILE" ]; then
echo "$FILE"
exit 0
fi
F="${FILE%.*}"
E="${FILE##*.}"
V=1
LAST_END=""
while true; do
read -p "BEGIN: " BEGIN
read -p "END: " END
read -p "SCREEN: " SCREEN
# if not first pass and *all* inputs are non-blank,
# override BEGIN with the previous END
if [ "$V" -ne 1 ] && [ -n "$BEGIN" ] && [ -n "$END" ] && [ -n "$SCREEN" ]; then
BEGIN="$LAST_END"
fi
if [ -z "$BEGIN" ] && [ -z "$END" ]; then
if [ -z "$SCREEN" ]; then
exit 0
else
ffmpeg -ss "$SCREEN" -i "$FILE" -frames:v 1 "${F}-${SCREEN}.jpg"
V=$((V+1))
continue
fi
fi
if [ -z "$BEGIN" ] && [ -n "$END" ]; then
split-basic.sh "$FILE" "${F}-${V}.${E}" "00:00:00.000" "$END"
LAST_END="$END"
elif [ -n "$BEGIN" ] && [ -z "$END" ]; then
split-basic.sh "$FILE" "${F}-${V}.${E}" "$BEGIN"
else
split-basic.sh "$FILE" "${F}-${V}.${E}" "$BEGIN" "$END"
LAST_END="$END"
fi
if [ -n "$SCREEN" ]; then
ffmpeg -ss "$SCREEN" -i "$FILE" -frames:v 1 "${F}-${V}.jpg"
fi
V=$((V+1))
doneM: not quite, i think; i meant that, if V > 1 and BEGIN is left blank, instead of setting BEGIN to 00:00:00.000, set BEGIN to LAST_END.
G: Got it — that’s a clean, local change to the logic, not a new mode.
Here’s the corrected script, with only this behavioral adjustment:
split-basic.sh is in PATHV > 1 and BEGIN is blank, BEGIN
is set to LAST_END#!/bin/bash
# wrapper-use-3.sh
# Assumes split-basic.sh is in PATH
# Run inside a directory containing movie files
read -p "Video filename: " FILE
if [ -z "$FILE" ]; then
exit 0
fi
if [ ! -f "$FILE" ]; then
echo "$FILE"
exit 0
fi
F="${FILE%.*}"
E="${FILE##*.}"
V=1
LAST_END=""
while true; do
read -p "BEGIN: " BEGIN
read -p "END: " END
read -p "SCREEN: " SCREEN
# If not first segment and BEGIN is blank, chain from previous END
if [ "$V" -gt 1 ] && [ -z "$BEGIN" ]; then
BEGIN="$LAST_END"
fi
if [ -z "$BEGIN" ] && [ -z "$END" ]; then
if [ -z "$SCREEN" ]; then
exit 0
else
ffmpeg -ss "$SCREEN" -i "$FILE" -frames:v 1 "${F}-${SCREEN}.jpg"
V=$((V+1))
continue
fi
fi
if [ -z "$BEGIN" ] && [ -n "$END" ]; then
split-basic.sh "$FILE" "${F}-${V}.${E}" "00:00:00.000" "$END"
LAST_END="$END"
elif [ -n "$BEGIN" ] && [ -z "$END" ]; then
split-basic.sh "$FILE" "${F}-${V}.${E}" "$BEGIN"
else
split-basic.sh "$FILE" "${F}-${V}.${E}" "$BEGIN" "$END"
LAST_END="$END"
fi
if [ -n "$SCREEN" ]; then
ffmpeg -ss "$SCREEN" -i "$FILE" -frames:v 1 "${F}-${V}.jpg"
fi
V=$((V+1))
doneThis now behaves like a segment-chaining cutter:
00:00:00.000That matches your intent precisely.
M: again, not quite; this version will not allow an exit due to three blank inputs because BEGIN will always have content after the first loop except for in the case where i only wanted the last bit of a movie anyway.
G:
#!/bin/bash
# wrapper-use-4.sh
# Assumes split-basic.sh is in PATH
# Run inside a directory containing movie files
read -p "Video filename: " FILE
if [ -z "$FILE" ]; then
exit 0
fi
if [ ! -f "$FILE" ]; then
echo "$FILE"
exit 0
fi
F="${FILE%.*}"
E="${FILE##*.}"
V=1
LAST_END=""
while true; do
read -p "BEGIN: " BEGIN
read -p "END: " END
read -p "SCREEN: " SCREEN
# Allow "three blanks" exit exactly as originally specified
if [ -z "$BEGIN" ] && [ -z "$END" ] && [ -z "$SCREEN" ]; then
exit 0
fi
# If V > 1 and BEGIN is blank (but not all three blank), chain from LAST_END
if [ "$V" -gt 1 ] && [ -z "$BEGIN" ]; then
BEGIN="$LAST_END"
fi
if [ -z "$BEGIN" ] && [ -z "$END" ]; then
# SCREEN must have content here (otherwise we already exited above)
ffmpeg -ss "$SCREEN" -i "$FILE" -frames:v 1 "${F}-${SCREEN}.jpg"
V=$((V+1))
continue
fi
if [ -z "$BEGIN" ] && [ -n "$END" ]; then
split-basic.sh "$FILE" "${F}-${V}.${E}" "00:00:00.000" "$END"
LAST_END="$END"
elif [ -n "$BEGIN" ] && [ -z "$END" ]; then
split-basic.sh "$FILE" "${F}-${V}.${E}" "$BEGIN"
else
split-basic.sh "$FILE" "${F}-${V}.${E}" "$BEGIN" "$END"
LAST_END="$END"
fi
if [ -n "$SCREEN" ]; then
ffmpeg -ss "$SCREEN" -i "$FILE" -frames:v 1 "${F}-${V}.jpg"
fi
V=$((V+1))
done日本語(にほんご) も できる — I can do Japanese too.