massive rewrite using flake-parts
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
33
pkgs/customscripts/src/compress
Normal file
33
pkgs/customscripts/src/compress
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p ffmpeg
|
||||
|
||||
target_video_size_KB="$2"
|
||||
origin_duration_s=$(ffprobe -v error -show_streams -select_streams a "$1" | grep -Po "(?<=^duration\=)\d*\.\d*")
|
||||
echo $origin_duration_s
|
||||
origin_audio_bitrate_kbit_s=$(ffprobe -v error -pretty -show_streams -select_streams a "$1" | grep -Po "(?<=^bit_rate\=)\d*\.\d*")
|
||||
target_audio_bitrate_kbit_s=$origin_audio_bitrate_kbit_s
|
||||
target_video_bitrate_kbit_s=$(\
|
||||
awk \
|
||||
-v size="$target_video_size_KB" \
|
||||
-v duration="$origin_duration_s" \
|
||||
-v audio_rate="$target_audio_bitrate_kbit_s" \
|
||||
'BEGIN { print ( ( size * 8.0 ) / ( 1.048576 * duration ) - audio_rate ) }')
|
||||
|
||||
ffmpeg \
|
||||
-y \
|
||||
-i "$1" \
|
||||
-c:v libx264 \
|
||||
-b:v "$target_video_bitrate_kbit_s"k \
|
||||
-pass 1 \
|
||||
-an \
|
||||
-f mp4 \
|
||||
/dev/null \
|
||||
&& \
|
||||
ffmpeg \
|
||||
-i "$1" \
|
||||
-c:v libx264 \
|
||||
-b:v "$target_video_bitrate_kbit_s"k \
|
||||
-pass 2 \
|
||||
-c:a aac \
|
||||
-b:a "$target_audio_bitrate_kbit_s"k \
|
||||
"$3"
|
Reference in New Issue
Block a user