1
0
Fork 0
cc-stuff/convert-video.sh

43 lines
1.2 KiB
Bash
Raw Permalink Normal View History

2024-09-15 05:36:41 +03:00
#!/usr/bin/bash
set -e
export TMP_DIR="$(mktemp -d)";
cleanup() {
rm -fr "${TMP_DIR}";
}
trap cleanup EXIT
export URL="$1";
export NAME="$2";
export BASE_URL="$3"
if [ -z "${BASE_URL}" ]; then
export BASE_URL="CHANGEME";
fi
mkdir -p "${NAME}"
export ORIG="$(pwd)";
cd "${TMP_DIR}"
yt-dlp "${URL}" -S "+height:720" -f "b" -o "${NAME}"
2024-09-15 05:36:41 +03:00
ffmpeg -i $2* -filter_complex "[0:a]channelsplit=channel_layout=stereo[left][right]" -map '[left]' -f s8 -ac 1 -ar 48k "${ORIG}/${NAME}/left.s8" -map '[right]' -f s8 -ac 1 -ar 48k "${ORIG}/${NAME}/right.s8"
2024-09-15 05:36:41 +03:00
ffmpeg -i $2* -vf fps=20 frame%04d.png
rm $2*
2024-09-15 06:56:29 +03:00
ls frame*.png | parallel 'echo {}; python3 ${ORIG}/cc-pic.py -W 164 -H 81 -p full {} ${ORIG}/${NAME}/{.}.cpi'
2024-09-15 05:36:41 +03:00
rm frame*.png
cd "${ORIG}"
export FRAME_COUNT="$(ls ${NAME}/*.cpi | wc -l)";
#'{"frame_time": 0.05,"frame_count": ${FRAME_COUNT},"video": "${BASE_URL}/${NAME}/frame%04d.cpi","audio": {"l": "${BASE_URL}/${NAME}/left.s8", "r": "${BASE_URL}/${NAME}/right.s8"}}' > "${NAME}/${NAME}.json"
2024-09-15 06:56:29 +03:00
printf '{"frame_time": 0.05, "frame_count": %d, "video": "%s", "audio": {"l": "%s", "r": "%s"}}\n' "${FRAME_COUNT}" "${BASE_URL}/${NAME}/frame%04d.cpi" "${BASE_URL}/${NAME}/left.s8" "${BASE_URL}/${NAME}/right.s8" > "${NAME}/${NAME}.json"