From d7749a064a28c3c7a11a8791a8b7bc0036fe617a Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Wed, 7 May 2025 17:18:36 +0200 Subject: checkpoint --- bin/extra/alarm | 30 ++++++++++++++++++++++++++++++ bin/extra/compress_discord | 37 +++++++++++++++++++++++++++++++++++++ bin/extra/discord_compress | 37 ------------------------------------- 3 files changed, 67 insertions(+), 37 deletions(-) create mode 100755 bin/extra/alarm create mode 100755 bin/extra/compress_discord delete mode 100755 bin/extra/discord_compress (limited to 'bin/extra') diff --git a/bin/extra/alarm b/bin/extra/alarm new file mode 100755 index 0000000..f7a417f --- /dev/null +++ b/bin/extra/alarm @@ -0,0 +1,30 @@ +#!/bin/sh + +if [ "$1" ] +then + AlarmTime="$1" +else + >&2 printf 'time: ' + AlarmTime="$(head -n 1)" +fi +[ "$AlarmTime" ] || exit 1 + +AlarmTimeSeconds="$(date -d "$AlarmTime" '+%s')" +[ "$AlarmTimeSeconds" ] || exit 1 + +TimeNowSeconds="$(date '+%s')" +SecondsToSleep="$((AlarmTimeSeconds - TimeNowSeconds))" +>&2 printf 'now: %s\n' "$(date '+%T')" + + +if [ "$SecondsToSleep" -gt 0 ] +then + >&2 printf 'Sleeping %s seconds...\n' "$SecondsToSleep" + sleep "$SecondsToSleep" >/dev/null 2>&1 +else + >&2 printf 'Not sleeping\n' +fi + +>&2 printf 'press [q] to quit ' +mpv --loop --volume=100 --msg-level=all=no --resume-playback=no ~/sync/share/sounds/pomo.aac 2>/dev/null +>&2 printf '\n' diff --git a/bin/extra/compress_discord b/bin/extra/compress_discord new file mode 100755 index 0000000..eacc364 --- /dev/null +++ b/bin/extra/compress_discord @@ -0,0 +1,37 @@ +#!/bin/sh + +# Compresses a video to a target size, for configuration see VARIABLES +# From: https://trac.ffmpeg.org/wiki/Encode/H.264#Two-PassExample +# +# $1: input file + +# VARIABLES +video_codec="libx264" +audio_codec="aac" +audio_bitrate="96" +target_size="8" + +MEGABIT="8388" + +# Main + +input="$1" +if [ -z "$input" ] +then + >&2 printf 'Usage: discord_compress \n' + exit 1 +fi + +duration="$(date -u -d @"$(ffprobe -show_entries format=duration -v quiet -of csv="p=0" -i "$input")" +'%s')" + +video_bitrate="$(((target_size * MEGABIT / duration) - audio_bitrate))" +[ "$video_bitrate" ] || exit 1 + +common_args="-hide_banner -v quiet -stats -y -hwaccel auto -i $input -c:v $video_codec -b:v ${video_bitrate}K" + +set -ex + +ffmpeg $common_args -pass 1 -an -f null /dev/null +ffmpeg $common_args -pass 2 -c:a "$audio_codec" -b:a "${audio_bitrate}K" compressed_"${input%.*}".mp4 + +rm -f ffmpeg2pass*.log* diff --git a/bin/extra/discord_compress b/bin/extra/discord_compress deleted file mode 100755 index eacc364..0000000 --- a/bin/extra/discord_compress +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -# Compresses a video to a target size, for configuration see VARIABLES -# From: https://trac.ffmpeg.org/wiki/Encode/H.264#Two-PassExample -# -# $1: input file - -# VARIABLES -video_codec="libx264" -audio_codec="aac" -audio_bitrate="96" -target_size="8" - -MEGABIT="8388" - -# Main - -input="$1" -if [ -z "$input" ] -then - >&2 printf 'Usage: discord_compress \n' - exit 1 -fi - -duration="$(date -u -d @"$(ffprobe -show_entries format=duration -v quiet -of csv="p=0" -i "$input")" +'%s')" - -video_bitrate="$(((target_size * MEGABIT / duration) - audio_bitrate))" -[ "$video_bitrate" ] || exit 1 - -common_args="-hide_banner -v quiet -stats -y -hwaccel auto -i $input -c:v $video_codec -b:v ${video_bitrate}K" - -set -ex - -ffmpeg $common_args -pass 1 -an -f null /dev/null -ffmpeg $common_args -pass 2 -c:a "$audio_codec" -b:a "${audio_bitrate}K" compressed_"${input%.*}".mp4 - -rm -f ffmpeg2pass*.log* -- cgit v1.2.3-70-g09d2