Skip to content

Instantly share code, notes, and snippets.

@Pysis868
Created February 14, 2024 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pysis868/a7db5d3e6e7d543e43705da46ba9c5be to your computer and use it in GitHub Desktop.
Save Pysis868/a7db5d3e6e7d543e43705da46ba9c5be to your computer and use it in GitHub Desktop.
videoCreateThumbnail.fish
#!/usr/bin/env fish
function videoCreateThumbnail \
--argument-names videoFile
test -z "$thumbnailSeekAmount" ;
and set thumbnailSeekAmount '0.10';
if test -z "$videoFile"
errorPrint 'No video file given; exiting...';
return 1;
end
if test ! -e "$videoFile"
errorPrint 'Video file does not exist; exiting...';
errorPrint "videoFile: $videoFile";
return 2;
end
if test -z "$videoExtensionsRegex"
errorPrint 'videoExtensionsRegex must be set; exiting...';
return 3;
end
if not string match -qr '\.'"$videoExtensionsRegex"'$' "$videoFile"
errorPrint 'Not a video file; exiting...';
errorPrint "videoExtensionsList: $videoExtensionsList";
errorPrint "videoExtensionsRegex: $videoExtensionsRegex";
return 4;
end
set outputImageFile "$videoFile.png";
if test -e "$outputImageFile"
echo 'Thumbnail file already exists; exiting...';
return;
end
set duration (
ffpre \
-show_entries 'format=duration' \
-of 'default=noprint_wrappers=1:nokey=1' \
"$videoFile"
);
set durationPart (
echo "$duration * $thumbnailSeekAmount" \
| bc
);
string match -qr '^\.' "$durationPart";
and set durationPart "0$durationPart" ;
# debugPrint "durationPart: $durationPart";
ffme \
-ss "$durationPart" \
-i "$videoFile" \
-vframes '1' \
"$outputImageFile" \
< /dev/null \
;
and echo 'Thumbnail file created; exiting...';
or echo 'Thumbnail file not created; exiting...';
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment