Skip to content

Instantly share code, notes, and snippets.

@happylinks
Created February 17, 2025 14:11
Show Gist options
  • Save happylinks/7ea0e1f3e0db6a8e2a410729a96ab806 to your computer and use it in GitHub Desktop.
Save happylinks/7ea0e1f3e0db6a8e2a410729a96ab806 to your computer and use it in GitHub Desktop.
ffmpeg extensions
function ffprobe_frames() {
echo "All frames:"
ffprobe -hide_banner -loglevel error -show_frames -of compact=p=0 "$1" |
awk -F'|' '{
printf " Frame:\n";
for(i=1; i<=NF; i++){
split($i, a, "=");
printf "\t%s: %s\n", a[1], a[2];
};
printf "\n";
}'
}
function ffprobe_audio_frames() {
echo "First and last audio frames:"
ffprobe -hide_banner -loglevel error -select_streams a -show_frames -of compact=p=0 "$1" |
(head -n 1 && tail -n 1) |
awk -F'|' '{
printf " Frame:\n";
for(i=1; i<=NF; i++){
split($i, a, "=");
printf "\t%s: %s\n", a[1], a[2];
};
printf "\n";
}'
}
function ffprobe_video_frames() {
echo "First and last video frames:"
ffprobe -hide_banner -loglevel error -select_streams v -show_frames -of compact=p=0 "$1" |
(head -n 1 && tail -n 1) |
awk -F'|' '{
printf " Frame:\n";
for(i=1; i<=NF; i++){
split($i, a, "=");
printf "\t%s: %s\n", a[1], a[2];
};
printf "\n";
}'
}
function ffprobe_dimensions() {
ffprobe -select_streams v -show_frames -show_entries frame=width,height -of csv "$1"
}
function ffprobe_dimensions_most() {
ffprobe -v error -select_streams v -show_frames -show_entries frame=width,height -of csv "$1" | \
awk -F',' '{print $2"x"$3}' | sort | uniq -c | sort -nr | head -n 1
}
function ffplay_side() {
ffplay -f lavfi "movie='$1':sp=1 [left]; movie='$2':sp=1 [right]; [left][right] hstack, setpts=N/FRAME_RATE/TB"
}
function ffmpeg_side() {
ffmpeg -i $1 -i $2 -filter_complex "[0:v]setpts=PTS-STARTPTS[left]; [1:v]setpts=PTS-STARTPTS[right]; [left][right]hstack" /tmp/output.mp4
}
function ffmpeg_frames() {
filename=$(basename "$1")
foldername="${filename%.*}"
mkdir -p "$foldername"
ffmpeg -i "$1" -qscale:v 2 "$foldername/${foldername}%03d.jpg"
}
function ffmpeg_av_mux() {
ffmpeg -i $1 -i $2 -c copy -map 0:a -map 1:v -shortest $3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment