Skip to content

Commit 3d06ca8

Browse files
authored
Merge pull request #24 from amiaopensource/sccyou-ffmpeg
Sccyou ffmpeg
2 parents 66663ed + fba7760 commit 3d06ca8

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

sccyou

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
# sccyou
33
# script to apply the readeia608 filter and interpret the results in order to create an scc (and optionally an srt) output from standard definition video files which contain EIA 608 data
44
# thanks to Paul Mahol, Ben Turkus
5-
# Copyright (c) 2019-2022, Dave Rice, see License.txt
5+
# Copyright (c) 2019-2024, Dave Rice, see License.txt
66

77
VERSION="0.2"
88

99
SEARCH_FIRST_X_SECONDS_FOR_CAPTION_LINE=20
1010

11+
SCRIPTDIR="$(dirname "${0}")"
1112
FFMPEG_INPUT_OPTIONS+=(-v 0)
1213
FFPROBE_INPUT_OPTIONS+=(-v 0)
1314

@@ -44,6 +45,12 @@ $(basename "${0}") ${VERSION}
4445
Information about the scc format is available at http://www.theneitherworld.com/mcpoodle/SCC_TOOLS/DOCS/
4546
4647
Dependencies: ffmpeg 4.3 or later
48+
49+
-F <path> (provide a custom ffmpeg path. ffprobe is presumed to neighbor ffmpeg)
50+
51+
If an ffmpeg binary is provided with the '-F <path>' option that will be used,
52+
else if an ffmpeg binary exists within the same directory of sccyou, that will
53+
be used. Else it will use $(which ffmpeg).
4754
4855
How tos:
4956
@@ -101,15 +108,15 @@ _hhmmssmmm_to_hhmmssff(){
101108
}
102109

103110
_get_line(){
104-
LINE_SELECT="$(ffmpeg -i "${MOVIE}" -vf "readeia608=lp=1:spw=${SPW},metadata=mode=print:key=lavfi.readeia608.0.line" -t "${SEARCH_FIRST_X_SECONDS_FOR_CAPTION_LINE}" -f null - 2>&1 | grep -o "lavfi.readeia608.0.line=[0-9]*" | cut -d= -f2 | sort | uniq -c | sort -n -r | head -n 1 | awk '{print $2}')"
111+
LINE_SELECT="$("${FFMPEG_PATH}" -i "${MOVIE}" -vf "readeia608=lp=1:spw=${SPW},metadata=mode=print:key=lavfi.readeia608.0.line" -t "${SEARCH_FIRST_X_SECONDS_FOR_CAPTION_LINE}" -f null - 2>&1 | grep -o "lavfi.readeia608.0.line=[0-9]*" | cut -d= -f2 | sort | uniq -c | sort -n -r | head -n 1 | awk '{print $2}')"
105112
}
106113

107114
_get_cc(){
108115
# this function tests for the presence of caption data on the specified line, if the result is non-empty then there are captions read
109116
LINE="${1}"
110117
SPW=0.27
111118
AMOUNT_TO_REPORT=10
112-
CC_SELECT="$(ffmpeg -i "${MOVIE}" -vf "format=rgb24,crop=iw:1:0:${LINE},readeia608=spw=${SPW},metadata=mode=print:key=lavfi.readeia608.0.cc" -t "${SEARCH_FIRST_X_SECONDS_FOR_CAPTION_LINE}" -f null - 2>&1 | grep -o "lavfi.readeia608.0.cc=0x[A-F0-9]*" | cut -d= -f2 | head -n "${AMOUNT_TO_REPORT}" | xargs)"
119+
CC_SELECT="$("${FFMPEG_PATH}" -i "${MOVIE}" -vf "format=rgb24,crop=iw:1:0:${LINE},readeia608=spw=${SPW},metadata=mode=print:key=lavfi.readeia608.0.cc" -t "${SEARCH_FIRST_X_SECONDS_FOR_CAPTION_LINE}" -f null - 2>&1 | grep -o "lavfi.readeia608.0.cc=0x[A-F0-9]*" | cut -d= -f2 | head -n "${AMOUNT_TO_REPORT}" | xargs)"
113120
}
114121

115122
_get_caption_settings(){
@@ -168,7 +175,7 @@ _end_scc(){
168175
echo >> "${SCC_OUT}"
169176
}
170177

171-
while getopts ":hsyo:l:t:v" OPT ; do
178+
while getopts ":hsyo:l:t:vF:" OPT ; do
172179
case "${OPT}" in
173180
h) _usage ; exit 0 ;;
174181
s) SRT_OUTPUT="y" ;;
@@ -177,20 +184,37 @@ while getopts ":hsyo:l:t:v" OPT ; do
177184
l) LINE_SELECT_USER="${OPTARG}" ;;
178185
t) SEARCH_FIRST_X_SECONDS_FOR_CAPTION_LINE="${OPTARG}" ;;
179186
v) unset FFMPEG_INPUT_OPTIONS ; unset FFPROBE_INPUT_OPTIONS ;;
187+
F) FFMPEG_PATH="${OPTARG}" ;;
180188
*) echo "bad option -${OPTARG}" ; _usage ; exit 1 ;;
181189
esac
182190
done
183191
shift $(( OPTIND - 1 ))
184192

193+
# if FFMPEG_PATH wasn't provided as an argument then see if one is installed
194+
if [[ -z "${FFMPEG_PATH}" ]] ; then
195+
FFMPEG_GUESS="${SCRIPTDIR}/ffmpeg"
196+
if [[ -x "${FFMPEG_GUESS}" ]] ; then
197+
FFMPEG_PATH="${FFMPEG_GUESS}"
198+
else
199+
FFMPEG_PATH="$(which ffmpeg)"
200+
fi
201+
fi
202+
FFPROBE_GUESS="$(dirname "${FFMPEG_PATH}")/ffprobe"
203+
if [[ -x "${FFPROBE_GUESS}" ]] ; then
204+
FFPROBE_PATH="${FFPROBE_GUESS}"
205+
else
206+
FFPROBE_PATH="$(which ffprobe)"
207+
fi
208+
185209
FFMPEG_INPUT_OPTIONS+=(-hide_banner)
186210
FFPROBE_INPUT_OPTIONS+=(-hide_banner)
187211

188-
if [[ "${@}" == "" ]] ; then
212+
if [[ "${*}" == "" ]] ; then
189213
_usage
190214
exit
191215
fi
192216

193-
while [[ "${@}" != "" ]] ; do
217+
while [[ "${*}" != "" ]] ; do
194218
MOVIE="${1}"
195219
if [[ -n "${OUTPUT_DIR}" ]] ; then
196220
MOVIE_BN="$(basename "${MOVIE}")"
@@ -258,12 +282,12 @@ while [[ "${@}" != "" ]] ; do
258282
PREV_CC="8080"
259283
fi
260284
PREV_SECS="$SECS"
261-
done < <(ffprobe "${FFPROBE_INPUT_OPTIONS[@]}" -sexagesimal -f lavfi -i movie="${MOVIE},format=rgb24,crop=iw:1:0:${LINE_SELECT},readeia608=lp=1:spw=${SPW}" -show_entries frame=best_effort_timestamp_time:frame_tags=lavfi.readeia608.0.cc -of csv)
285+
done < <("${FFPROBE_PATH}" "${FFPROBE_INPUT_OPTIONS[@]}" -sexagesimal -f lavfi -i movie="${MOVIE},format=rgb24,crop=iw:1:0:${LINE_SELECT},readeia608=lp=1:spw=${SPW}" -show_entries frame=best_effort_timestamp_time:frame_tags=lavfi.readeia608.0.cc -of csv)
262286
TRANSITION_TIME="$(_hhmmssmmm_to_hhmmssff "${PREV_SECS}")"
263287
_report -d "${CC_LOG} - ${TRANSITION_TIME}."
264288
_end_scc
265289
if [[ "${SRT_OUTPUT}" == "y" ]] ; then
266-
ffmpeg "${FFMPEG_INPUT_OPTIONS[@]}" -i "${SCC_OUT}" "${SRT_OUT}"
290+
"${FFMPEG_PATH}" "${FFMPEG_INPUT_OPTIONS[@]}" -i "${SCC_OUT}" "${SRT_OUT}"
267291
fi
268292

269293
_report -d "Done with ${MOVIE}. We hope you like ${SCC_OUT}."

0 commit comments

Comments
 (0)