diff options
| author | Akshay Nair <phenax5@gmail.com> | 2026-06-06 16:15:14 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2026-06-06 16:43:29 +0530 |
| commit | 9fb9a94aa2d3bdb90f088f7188053374155a6715 (patch) | |
| tree | 49d1ccd866133b278a9b310e90277f0de5ee9075 /video.sh | |
| parent | 9d178c66ef3b9f50c62d05c53f1dc772cc0f25fe (diff) | |
| download | sqlite-creative-coding-9fb9a94aa2d3bdb90f088f7188053374155a6715.tar.gz sqlite-creative-coding-9fb9a94aa2d3bdb90f088f7188053374155a6715.zip | |
Add video/gif generation + add wavey example
Diffstat (limited to '')
| -rwxr-xr-x | video.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/video.sh b/video.sh new file mode 100755 index 0000000..59c5d28 --- /dev/null +++ b/video.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env sh + +set -eu + +[ $# -lt 1 ] && echo "Fuck" && exit 1; +VIDEO_ID="$1" +DB="${2:-fun.db}" + +db() { sqlite3 -tabs -noheader "$DB" "$@"; } + +frame_ppm() { + local image_id="$1" + echo "P3" + db "SELECT width, height FROM images WHERE id='$image_id'" + echo "255" + db "SELECT r,g,b FROM pixels WHERE image_id='$image_id' ORDER BY y ASC, x ASC" +} + +video_info() { + local video_id="$1" + db "SELECT fps FROM videos WHERE id='$video_id'" +} + +video_frames() { + local video_id="$1" + db "SELECT id FROM images WHERE video_id='$video_id' ORDER BY frame ASC" | while IFS= read image_id; do + frame_ppm "$image_id"; + done; +} + +save_video() { + local id="$1" + local fps="$2" + ffmpeg -y -f image2pipe -framerate "$fps" -i pipe:0 "media/$id.gif" +} + +display() { + local fps="$1"; + ffplay - -framerate "$fps" -autoexit; +} + +## Main stuff + +data="$(video_info "$VIDEO_ID")" +fps="$data" + +video_frames "$VIDEO_ID" | tee >(save_video "$VIDEO_ID" "$fps") | display "$fps" |
