Skip to content

Instantly share code, notes, and snippets.

@alonsoir
Created January 21, 2025 11:55
Show Gist options
  • Save alonsoir/14b87c203826ebd68c6ef5282c660611 to your computer and use it in GitHub Desktop.
Save alonsoir/14b87c203826ebd68c6ef5282c660611 to your computer and use it in GitHub Desktop.

(attendance-system-py3.10) ┌<▸> ~/g/attendance_system └➤ ./video_to_gif.sh Uso: ./video_to_gif.sh ruta/al/video.mp4 [nombre_del_gif] (attendance-system-py3.10) ┌<▪> ~/g/attendance_system └➤ ./video_to_gif.sh output.mp4 ffmpeg version 7.1 Copyright (c) 2000-2024 the FFmpeg developers built with Apple clang version 16.0.0 (clang-1600.0.26.4) configuration: --prefix=/usr/local/Cellar/ffmpeg/7.1_4 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox libavutil 59. 39.100 / 59. 39.100 libavcodec 61. 19.100 / 61. 19.100 libavformat 61. 7.100 / 61. 7.100 libavdevice 61. 3.100 / 61. 3.100 libavfilter 10. 4.100 / 10. 4.100 libswscale 8. 3.100 / 8. 3.100 libswresample 5. 3.100 / 5. 3.100 libpostproc 58. 3.100 / 58. 3.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'output.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf61.7.100 Duration: 00:00:23.20, start: 0.000000, bitrate: 1339 kb/s Stream #0:00x1: Video: h264 (High 4:2:2) (avc1 / 0x31637661), yuv422p(progressive), 1600x900, 1336 kb/s, 30 fps, 30 tbr, 15360 tbn (default) Metadata: handler_name : VideoHandler vendor_id : [0][0][0][0] encoder : Lavc61.19.100 libx264 File 'output.gif' already exists. Overwrite? [y/N] y Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> gif (native)) Press [q] to stop, [?] for help [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89b0dd0000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89e8200000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89e8138000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89e9888000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89e9898000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89e98a8000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89e98b8000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a8448000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a8458000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a8468000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a8478000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a8488000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a8498000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a84a8000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a84b8000] No accelerated colorspace conversion found from yuv422p to bgr8. [swscaler @ 0x7f89d8f28000] [swscaler @ 0x7f89a84c8000] No accelerated colorspace conversion found from yuv422p to bgr8. Output #0, gif, to 'output.gif': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf61.7.100 Stream #0:0(und): Video: gif, bgr8(pc, gbr/unknown/unknown, progressive), 1600x900, q=2-31, 200 kb/s, 30 fps, 100 tbn (default) Metadata: handler_name : VideoHandler vendor_id : [0][0][0][0] encoder : Lavc61.19.100 gif [out#0/gif @ 0x7f89e3706440] video:49621KiB audio:0KiB subtitle:0KiB other streams:0KiB global headers:0KiB muxing overhead: 0.000039% frame= 696 fps=109 q=-0.0 Lsize= 49621KiB time=00:00:23.20 bitrate=17521.3kbits/s speed=3.62x
Conversión completada: output.gif

#!/bin/bash
# Función para instalar ffmpeg
install_ffmpeg() {
echo "Instalando ffmpeg..."
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Para distribuciones basadas en Debian/Ubuntu
sudo apt update
sudo apt install -y ffmpeg
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Para macOS
brew install ffmpeg
elif [[ "$OSTYPE" == "cygwin" ]]; then
# Para Cygwin (Windows)
echo "Cygwin no soporta la instalación automática de ffmpeg."
exit 1
elif [[ "$OSTYPE" == "msys" ]]; then
# Para Git Bash (Windows)
echo "Por favor, instala ffmpeg manualmente en Windows."
exit 1
else
echo "Sistema operativo no soportado."
exit 1
fi
}
# Verificar si ffmpeg está instalado
if ! command -v ffmpeg &> /dev/null; then
install_ffmpeg
fi
# Comprobar si se ha proporcionado el archivo de video
if [ -z "$1" ]; then
echo "Uso: $0 ruta/al/video.mp4 [nombre_del_gif]"
exit 1
fi
# Asignar la ruta del video y el nombre del gif (si se proporciona)
VIDEO_PATH="$1"
GIF_NAME="${2:-$(basename "$VIDEO_PATH" .mp4)}.gif"
# Convertir el video a GIF usando ffmpeg
ffmpeg -i "$VIDEO_PATH" "$GIF_NAME"
echo "Conversión completada: $GIF_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment