mirror of
https://github.com/srid/nixos-config.git
synced 2025-12-26 15:04:59 +08:00
add twitter-convert
This commit is contained in:
parent
167c43b474
commit
532f335b3c
5 changed files with 40 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
self: super: {
|
||||
fuckport = self.callPackage ./fuckport.nix { };
|
||||
twitter-convert = self.callPackage ./twitter-convert { };
|
||||
nixci = flake.inputs.nixci.packages.${system}.default;
|
||||
nix-health = flake.inputs.nix-browser.packages.${system}.nix-health;
|
||||
actual = flake.inputs.actual.packages.${system}.default;
|
||||
|
|
|
|||
18
packages/twitter-convert/default.nix
Normal file
18
packages/twitter-convert/default.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{ writeShellApplication, ffmpeg-full, ... }:
|
||||
|
||||
# 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-full ];
|
||||
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"
|
||||
'';
|
||||
}
|
||||
12
packages/twitter-convert/ffmpeg_ar
Executable file
12
packages/twitter-convert/ffmpeg_ar
Executable 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")"
|
||||
8
packages/twitter-convert/ffmpeg_twitter
Executable file
8
packages/twitter-convert/ffmpeg_twitter
Executable 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue