twitter-convert, restore minimally

This commit is contained in:
Sridhar Ratnakumar 2026-05-20 08:06:44 -04:00
parent 5a0b2b4207
commit 0e0c16c460
4 changed files with 39 additions and 0 deletions

View file

@ -33,5 +33,6 @@ in
home.packages = [
inputs.disc-scrape.packages.${pkgs.stdenv.hostPlatform.system}.default
pkgs.zellij-one
pkgs.twitter-convert
];
}

View file

@ -0,0 +1,18 @@
{ writeShellApplication, ffmpeg, ... }:
# Some useful resources for this undocumented shit:
# - https://stackoverflow.com/q/59056863/55246
# - https://gist.github.com/nikhan/26ddd9c4e99bbf209dd7
writeShellApplication {
name = "twitter-convert";
runtimeInputs = [ ffmpeg ];
meta.description = ''
Convert a video for uploading to X / Twitter.
You may need a Basic or Premium tier to upload longer videos.
'';
text = ''
export ARSCRIPT="${./ffmpeg_ar}"
${./ffmpeg_twitter} "$1"
'';
}

View file

@ -0,0 +1,12 @@
#!/bin/bash
eval $(ffprobe -v error -show_entries stream=width,height -of default=noprint_wrappers=1 "$1")
#results in e.g.
#width=300
#height=1200
echo "height=$height"$'\n'"width=$width"
newenv=$(bc <<< "width=$width; height=$height;"$'\nscale=3; aspect=width / height;\nprint "aspect=", aspect;
print "''\n'$'";\n\nif (aspect>3) { r=(height) * (aspect/3); print "height=";}
if (aspect<(1/3)) {r=(width) / (aspect/(1/3)); print "width=";}\nscale=0
if (r) { print r/1 }')
[ ! -z "$newenv" ] && echo "$newenv" && export $newenv
echo "aspect=""$(bc <<< "scale=3; $width/$height")"

View file

@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -xe
export $($ARSCRIPT "$1")
ffmpeg -i "$1" \
-filter_complex 'fps=30,format=yuv420p,pad='"ceil($width/2)*2:ceil($height/2)*2"':(ow-iw)/2:(oh-ih)/2' -c:v h264_videotoolbox -c:a aac -ac 2 -ar 44100 -r 30 \
output.mp4