2014-05-26 12:28:18 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2014-09-16 00:50:43 +00:00
|
|
|
: "${MPV:=mpv}"
|
|
|
|
: "${ILDETECT_MPV:=$MPV}"
|
|
|
|
: "${ILDETECT_MPVFLAGS:=--start=35% --length=35}"
|
|
|
|
: "${ILDETECT_DRY_RUN:=}"
|
|
|
|
: "${ILDETECT_QUIET:=}"
|
|
|
|
: "${ILDETECT_RUN_INTERLACED_ONLY:=}"
|
|
|
|
: "${ILDETECT_FORCE_RUN:=}"
|
2014-05-26 12:28:18 +00:00
|
|
|
|
2014-09-21 17:14:23 +00:00
|
|
|
# This script uses ffmpeg's "idet" filter for interlace detection. In the
|
|
|
|
# long run this should replace ildetect.sh+ildetect.so.
|
|
|
|
|
2014-05-26 12:28:18 +00:00
|
|
|
# exit status:
|
|
|
|
# 0 progressive
|
|
|
|
# 1 telecine
|
|
|
|
# 2 interlaced
|
|
|
|
# 8 unknown
|
|
|
|
# 16 detect fail
|
|
|
|
# 17+ mpv's status | 16
|
|
|
|
|
|
|
|
testfun()
|
|
|
|
{
|
|
|
|
$ILDETECT_MPV "$@" \
|
2023-07-07 03:33:40 +00:00
|
|
|
--vf-add=lavfi="[idet]" --msg-level=ffmpeg=v \
|
2014-05-26 12:28:18 +00:00
|
|
|
--o= --vo=null --no-audio --untimed \
|
|
|
|
$ILDETECT_MPVFLAGS \
|
|
|
|
| { if [ -n "$ILDETECT_QUIET" ]; then cat; else tee /dev/stderr; fi } \
|
2014-09-17 12:11:56 +00:00
|
|
|
| grep "Parsed_idet_0: Multi frame detection: "
|
2014-05-26 12:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
judge()
|
|
|
|
{
|
2014-09-17 12:11:56 +00:00
|
|
|
tff=0
|
|
|
|
bff=0
|
|
|
|
progressive=0
|
|
|
|
undetermined=0
|
2014-11-22 07:13:14 +00:00
|
|
|
while read -r _ _ _ _ _ _ tff1 _ bff1 _ progressive1 _ undetermined1 _; do
|
2014-09-17 12:11:56 +00:00
|
|
|
case "$tff1$bff1$progressive1$undetermined1" in
|
|
|
|
*[!0-9]*)
|
|
|
|
printf >&2 'ERROR: Unrecognized idet output: %s\n' "$out"
|
|
|
|
exit 16
|
|
|
|
;;
|
|
|
|
esac
|
2014-09-21 13:00:39 +00:00
|
|
|
tff=$((tff + tff1))
|
|
|
|
bff=$((bff + bff1))
|
|
|
|
progressive=$((progressive + progressive1))
|
|
|
|
undetermined=$((undetermined + undetermined1))
|
2014-09-17 12:11:56 +00:00
|
|
|
done <<EOF
|
2015-06-02 13:37:41 +00:00
|
|
|
$(testfun "$@" | sed 's/:/: /g')
|
2014-09-17 12:11:56 +00:00
|
|
|
EOF
|
2014-05-26 12:28:18 +00:00
|
|
|
|
|
|
|
interlaced=$((bff + tff))
|
|
|
|
determined=$((interlaced + progressive))
|
|
|
|
|
2014-09-16 00:50:43 +00:00
|
|
|
if [ "$undetermined" -gt "$determined" ] || [ "$determined" -lt 250 ]; then
|
2014-05-26 12:28:18 +00:00
|
|
|
echo >&2 "ERROR: Less than 50% or 250 frames are determined."
|
|
|
|
[ -n "$ILDETECT_FORCE_RUN" ] || exit 8
|
|
|
|
echo >&2 "Assuming interlacing."
|
2014-09-16 00:50:43 +00:00
|
|
|
if [ "$tff" -gt $((bff * 10)) ]; then
|
2014-09-16 00:51:00 +00:00
|
|
|
verdict="interlaced-tff"
|
2014-09-16 00:50:43 +00:00
|
|
|
elif [ "$bff" -gt $((tff * 10)) ]; then
|
2014-09-16 00:51:00 +00:00
|
|
|
verdict="interlaced-bff"
|
2014-05-26 12:28:18 +00:00
|
|
|
else
|
2014-09-16 00:51:00 +00:00
|
|
|
verdict="interlaced"
|
2014-05-26 12:28:18 +00:00
|
|
|
fi
|
2014-09-16 00:50:43 +00:00
|
|
|
elif [ $((interlaced * 20)) -gt "$progressive" ]; then
|
2014-05-26 12:28:18 +00:00
|
|
|
# At least 5% of the frames are interlaced!
|
2014-09-16 00:50:43 +00:00
|
|
|
if [ "$tff" -gt $((bff * 10)) ]; then
|
2014-09-16 00:51:00 +00:00
|
|
|
verdict="interlaced-tff"
|
2014-09-16 00:50:43 +00:00
|
|
|
elif [ "$bff" -gt $((tff * 10)) ]; then
|
2014-09-16 00:51:00 +00:00
|
|
|
verdict="interlaced-bff"
|
2014-05-26 12:28:18 +00:00
|
|
|
else
|
|
|
|
echo >&2 "ERROR: Content is interlaced, but can't determine field order."
|
|
|
|
[ -n "$ILDETECT_FORCE_RUN" ] || exit 8
|
|
|
|
echo >&2 "Assuming interlacing with default field order."
|
2014-09-16 00:51:00 +00:00
|
|
|
verdict="interlaced"
|
2014-05-26 12:28:18 +00:00
|
|
|
fi
|
|
|
|
else
|
2014-09-16 00:51:00 +00:00
|
|
|
# Likely progressive
|
|
|
|
verdict="progressive"
|
2014-05-26 12:28:18 +00:00
|
|
|
fi
|
|
|
|
|
2014-09-16 17:01:35 +00:00
|
|
|
printf '%s\n' "$verdict"
|
2014-05-26 12:28:18 +00:00
|
|
|
}
|
|
|
|
|
2014-07-16 14:15:12 +00:00
|
|
|
judge "$@" --vf-clr
|
2014-05-26 12:28:18 +00:00
|
|
|
case "$verdict" in
|
|
|
|
progressive)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
[ -n "$ILDETECT_RUN_INTERLACED_ONLY" ] || \
|
|
|
|
$ILDETECT_MPV "$@"
|
|
|
|
r=$?
|
2014-09-16 00:49:47 +00:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 12:28:18 +00:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
interlaced-tff)
|
2015-09-09 00:57:44 +00:00
|
|
|
judge "$@" --vf-clr --vf-pre=lavfi=\[setfield=tff\],pullup
|
2014-05-26 12:28:18 +00:00
|
|
|
case "$verdict" in
|
|
|
|
progressive)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
2015-09-09 00:57:44 +00:00
|
|
|
$ILDETECT_MPV "$@" --vf-pre=lavfi=\[setfield=tff\],pullup
|
2014-05-26 12:28:18 +00:00
|
|
|
r=$?
|
2014-09-16 00:49:47 +00:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 12:28:18 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
2015-09-09 00:57:44 +00:00
|
|
|
$ILDETECT_MPV "$@" --vf-pre=lavfi=\[setfield=tff\],yadif
|
2014-05-26 12:28:18 +00:00
|
|
|
r=$?
|
2014-09-16 00:49:47 +00:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 12:28:18 +00:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
interlaced-bff)
|
2015-09-09 00:57:44 +00:00
|
|
|
judge "$@" --vf-clr --vf-pre=lavfi=\[setfield=bff\],pullup
|
2014-05-26 12:28:18 +00:00
|
|
|
case "$verdict" in
|
|
|
|
progressive)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
2015-09-09 00:57:44 +00:00
|
|
|
$ILDETECT_MPV "$@" --vf-pre=lavfi=\[setfield=bff\],pullup
|
2014-05-26 12:28:18 +00:00
|
|
|
r=$?
|
2014-09-16 00:49:47 +00:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 12:28:18 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
2015-09-09 00:57:44 +00:00
|
|
|
$ILDETECT_MPV "$@" --vf-pre=lavfi=\[setfield=bff\],yadif
|
2014-05-26 12:28:18 +00:00
|
|
|
r=$?
|
2014-09-16 00:49:47 +00:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 12:28:18 +00:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
interlaced)
|
2014-07-15 09:10:24 +00:00
|
|
|
judge "$@" --vf-clr --vf-pre=pullup
|
2014-05-26 12:28:18 +00:00
|
|
|
case "$verdict" in
|
|
|
|
progressive)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
$ILDETECT_MPV "$@" --vf-pre=pullup
|
|
|
|
r=$?
|
2014-09-16 00:49:47 +00:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 12:28:18 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
$ILDETECT_MPV "$@" --vf-pre=yadif
|
|
|
|
r=$?
|
2014-09-16 00:49:47 +00:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 12:28:18 +00:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo >&2 "ERROR: Internal error."
|
|
|
|
exit 16
|
|
|
|
;;
|
|
|
|
esac
|