Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show decoded caption data in Caption viewer #810

Open
iamdamosuzuki opened this issue Jun 28, 2024 · 2 comments
Open

Show decoded caption data in Caption viewer #810

iamdamosuzuki opened this issue Jun 28, 2024 · 2 comments
Labels
FADGI Wishlist Items that are not within the scope of current FADGI work, but could be in scope of future funding

Comments

@iamdamosuzuki
Copy link
Contributor

I would like to have the option to view the decoded caption data in the Caption Viewer mode, rather than the raw hex values.

@iamdamosuzuki iamdamosuzuki added the FADGI Wishlist Items that are not within the scope of current FADGI work, but could be in scope of future funding label Jun 28, 2024
@dericed
Copy link
Member

dericed commented Jul 1, 2024

Hmm, I'm not sure how to get ffmpeg to do this, cc'ing @richardpl for advice.

Currently the caption values as accessible in their hexadecimal form via the metadata filter (as used at

vrecord/vrecord

Line 551 in e933bd8

CAPTION_WRITE=",readeia608=lp=1:spw=0.27,metadata=mode=print:key=lavfi.readeia608.0.cc:file=${CAPTION_TMP}"
) and then output to a file. Then a function processes that metadata output from those hex values into an scc (

vrecord/vrecord

Lines 265 to 340 in e933bd8

_eia608dump2scc(){
EIA608DUMP_IN="${1}"
SCC_OUT="${2}"
_smmm_to_hhmmssff(){
secs="$1"
echo "${secs}" | awk '{ printf "%02i:%02i:%02i:%02i\n", $1/60/60, $1/60%60, $1%60, $1%1*30 }'
}
_write_cc(){
CC="$1"
if [[ "$START" == "Y" ]] ; then
echo -n " ${CC}" >> "${SCC_OUT}"
else
echo -n " ${CC}" >> "${SCC_OUT}"
fi
START="N"
}
_write_new_cc_line(){
SCC_TIME="$(_smmm_to_hhmmssff "${SECS}")"
echo -e -n "\n\n${SCC_TIME}" >> "${SCC_OUT}"
START="Y"
}
_start_scc(){
echo -n "Scenarist_SCC V1.0" > "${SCC_OUT}"
}
_end_scc(){
echo >> "${SCC_OUT}"
}
#initialize
PREV_CC="8080"
CC_PRESENT=0
REPORT=0
_start_scc
while read METADATA_LINE ; do
if [[ "${METADATA_LINE:0:8}" == "pts_time" ]] ; then
SECS="${METADATA_LINE/pts_time:}"
REPORT=0
elif [[ "${METADATA_LINE:0:21}" == "lavfi.readeia608.0.cc" ]] ; then
CC_HEX="${METADATA_LINE/lavfi.readeia608.0.cc=}"
REPORT=1
if [[ -n "${CC_HEX}" && "${REPORT}" ]] ; then
CC="${CC_HEX:2:4}"
if { [[ "${CC}" != "8080" ]] && [[ "${PREV_CC}" == "8080" ]] ; } || { [[ "${CC}" == "9420" ]] && [[ "${PREV_CC}" != "9420" ]] ; } ; then
_write_new_cc_line
_write_cc "$CC"
elif [[ "${CC}" != "8080" ]] ; then
_write_cc "$CC"
fi
PREV_CC="$CC"
if [[ "$CC_PRESENT" == 0 ]] ; then
CC_PRESENT=1
if [[ -n "${CC_LOG}" ]] ; then
TRANSITION_TIME="$(_smmm_to_hhmmssff "${SECS}")"
_report -d "${CC_LOG} - ${TRANSITION_TIME}."
fi
TRANSITION_TIME="$(_smmm_to_hhmmssff "${SECS}")"
CC_LOG="Caption data ON: ${TRANSITION_TIME}"
fi
else
if [[ "$CC_PRESENT" == 1 ]] ; then
CC_PRESENT=0
if [[ -n "${CC_LOG}" ]] ; then
TRANSITION_TIME="$(_smmm_to_hhmmssff "${SECS}")"
_report -d "${CC_LOG} - ${TRANSITION_TIME}."
fi
TRANSITION_TIME="$(_smmm_to_hhmmssff "${SECS}")"
CC_LOG="Caption data OFF: ${TRANSITION_TIME}"
fi
PREV_CC="8080"
fi
PREV_SECS="$SECS"
fi
done < <(grep -o "pts_time:[^ ]*\|lavfi.readeia608.0.cc=[^ ]*" "${EIA608DUMP_IN}")
_end_scc
}
, this is borrowed from sccyou).

To get onscreen captions for a live input, then the output of the metadata filter would need to be sent back to ffmpeg as an additional input. I see that ffmpeg has an 608 decoder but I'm uncertain how to accept that as an input as there's no -f rawdata -c eia608 options.

@richardpl
Copy link

You could write .scc files and use .scc demuxer from libavformat, if you instead need realtime/stream solution than its more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FADGI Wishlist Items that are not within the scope of current FADGI work, but could be in scope of future funding
Projects
None yet
Development

No branches or pull requests

3 participants