2014-05-26 14:28:18 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2014-09-16 02:50:43 +02:00
|
|
|
: "${MPV:=mpv}"
|
|
|
|
: "${ILDETECT_MPV:=$MPV}"
|
|
|
|
: "${ILDETECT_MPV:=$MPV}"
|
|
|
|
: "${ILDETECT_MPVFLAGS:=--start=35% --length=35}"
|
|
|
|
: "${ILDETECT_DRY_RUN:=}"
|
|
|
|
: "${ILDETECT_QUIET:=}"
|
|
|
|
: "${ILDETECT_RUN_INTERLACED_ONLY:=}"
|
|
|
|
: "${ILDETECT_FORCE_RUN:=}"
|
|
|
|
: "${MAKE:=make}"
|
2014-05-26 14:28:18 +02:00
|
|
|
|
|
|
|
# exit status:
|
|
|
|
# 0 progressive
|
|
|
|
# 1 telecine
|
|
|
|
# 2 interlaced
|
|
|
|
# 8 unknown
|
|
|
|
# 16 detect fail
|
|
|
|
# 17+ mpv's status | 16
|
|
|
|
|
|
|
|
testfun()
|
|
|
|
{
|
|
|
|
$ILDETECT_MPV "$@" \
|
2014-07-15 11:10:24 +02:00
|
|
|
--vf-add=lavfi="[idet]" --msg-level ffmpeg=v \
|
2014-05-26 14:28:18 +02:00
|
|
|
--o= --vo=null --no-audio --untimed \
|
|
|
|
$ILDETECT_MPVFLAGS \
|
|
|
|
| { if [ -n "$ILDETECT_QUIET" ]; then cat; else tee /dev/stderr; fi } \
|
|
|
|
| grep "Parsed_idet_0: Multi frame detection: " | tail -n 1
|
|
|
|
}
|
|
|
|
|
|
|
|
judge()
|
|
|
|
{
|
2014-09-16 02:49:09 +02:00
|
|
|
out="$(testfun "$@")"
|
2014-05-26 14:28:18 +02:00
|
|
|
|
|
|
|
tff=${out##* TFF:}; tff=${tff%% *}
|
|
|
|
bff=${out##* BFF:}; bff=${bff%% *}
|
|
|
|
progressive=${out##* Progressive:}; progressive=${progressive%% *}
|
|
|
|
undetermined=${out##* Undetermined:}; undetermined=${undetermined%% *}
|
|
|
|
|
|
|
|
case "$tff$bff$progressive$undetermined" in
|
|
|
|
*[!0-9]*)
|
|
|
|
echo >&2 "ERROR: Unrecognized idet output: $out"
|
|
|
|
exit 16
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
interlaced=$((bff + tff))
|
|
|
|
determined=$((interlaced + progressive))
|
|
|
|
|
2014-09-16 02:50:43 +02:00
|
|
|
if [ "$undetermined" -gt "$determined" ] || [ "$determined" -lt 250 ]; then
|
2014-05-26 14:28:18 +02: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 02:50:43 +02:00
|
|
|
if [ "$tff" -gt $((bff * 10)) ]; then
|
2014-05-26 14:28:18 +02:00
|
|
|
verdict=interlaced-tff
|
2014-09-16 02:50:43 +02:00
|
|
|
elif [ "$bff" -gt $((tff * 10)) ]; then
|
2014-05-26 14:28:18 +02:00
|
|
|
verdict=interlaced-bff
|
|
|
|
else
|
|
|
|
verdict=interlaced
|
|
|
|
fi
|
2014-09-16 02:50:43 +02:00
|
|
|
elif [ $((interlaced * 20)) -gt "$progressive" ]; then
|
2014-05-26 14:28:18 +02:00
|
|
|
# At least 5% of the frames are interlaced!
|
2014-09-16 02:50:43 +02:00
|
|
|
if [ "$tff" -gt $((bff * 10)) ]; then
|
2014-05-26 14:28:18 +02:00
|
|
|
verdict=interlaced-tff
|
2014-09-16 02:50:43 +02:00
|
|
|
elif [ "$bff" -gt $((tff * 10)) ]; then
|
2014-05-26 14:28:18 +02:00
|
|
|
verdict=interlaced-bff
|
|
|
|
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."
|
|
|
|
verdict=interlaced
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Likely progrssive.
|
|
|
|
verdict=progressive
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$verdict"
|
|
|
|
}
|
|
|
|
|
2014-07-16 16:15:12 +02:00
|
|
|
judge "$@" --vf-clr
|
2014-05-26 14:28:18 +02:00
|
|
|
case "$verdict" in
|
|
|
|
progressive)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
[ -n "$ILDETECT_RUN_INTERLACED_ONLY" ] || \
|
|
|
|
$ILDETECT_MPV "$@"
|
|
|
|
r=$?
|
2014-09-16 02:49:47 +02:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 14:28:18 +02:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
interlaced-tff)
|
2014-07-15 11:10:24 +02:00
|
|
|
judge "$@" --vf-clr --vf-pre=pullup --field-dominance=top
|
2014-05-26 14:28:18 +02:00
|
|
|
case "$verdict" in
|
|
|
|
progressive)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
$ILDETECT_MPV "$@" --vf-pre=pullup --field-dominance=top
|
|
|
|
r=$?
|
2014-09-16 02:49:47 +02:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 14:28:18 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
$ILDETECT_MPV "$@" --vf-pre=yadif --field-dominance=top
|
|
|
|
r=$?
|
2014-09-16 02:49:47 +02:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 14:28:18 +02:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
interlaced-bff)
|
2014-07-15 11:10:24 +02:00
|
|
|
judge "$@" --vf-clr --vf-pre=pullup --field-dominance=bottom
|
2014-05-26 14:28:18 +02:00
|
|
|
case "$verdict" in
|
|
|
|
progressive)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
$ILDETECT_MPV "$@" --vf-pre=pullup --field-dominance=bottom
|
|
|
|
r=$?
|
2014-09-16 02:49:47 +02:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 14:28:18 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
$ILDETECT_MPV "$@" --vf-pre=yadif --field-dominance=bottom
|
|
|
|
r=$?
|
2014-09-16 02:49:47 +02:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 14:28:18 +02:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
interlaced)
|
2014-07-15 11:10:24 +02:00
|
|
|
judge "$@" --vf-clr --vf-pre=pullup
|
2014-05-26 14:28:18 +02:00
|
|
|
case "$verdict" in
|
|
|
|
progressive)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
$ILDETECT_MPV "$@" --vf-pre=pullup
|
|
|
|
r=$?
|
2014-09-16 02:49:47 +02:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 14:28:18 +02:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
[ -n "$ILDETECT_DRY_RUN" ] || \
|
|
|
|
$ILDETECT_MPV "$@" --vf-pre=yadif
|
|
|
|
r=$?
|
2014-09-16 02:49:47 +02:00
|
|
|
[ $r -eq 0 ] || exit $((r | 16))
|
2014-05-26 14:28:18 +02:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo >&2 "ERROR: Internal error."
|
|
|
|
exit 16
|
|
|
|
;;
|
|
|
|
esac
|