Skip to content

Instantly share code, notes, and snippets.

@ajmas
Last active January 5, 2024 03:40
Show Gist options
  • Save ajmas/63b40dee8e52958ef2b9d1f6839193c2 to your computer and use it in GitHub Desktop.
Save ajmas/63b40dee8e52958ef2b9d1f6839193c2 to your computer and use it in GitHub Desktop.

Revisions

  1. ajmas revised this gist Jan 5, 2024. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion webp2mp4.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,10 @@
    #!/bin/sh

    ## Quick script to convert webp files to mp4. Makes use of webpmux, ImageMagick and ffmpeg

    input=$1
    output_base=/tmp
    output_file=output.mp4
    regex="Number of frames: ([0-9]+)"
    info=`webpmux -info "$1"`

    @@ -19,6 +22,6 @@ then
    done

    # Take the frames and assemble the MP4. We need to tune the FPS, since right now it is hardcoded
    ffmpeg -framerate 5 -pattern_type glob -i "$output_base/"'frame_*.png' -c:v libx264 -pix_fmt yuv420p output.mp4
    ffmpeg -framerate 5 -pattern_type glob -i "$output_base/"'frame_*.png' -c:v libx264 -pix_fmt yuv420p "$output_file"
    fi

  2. ajmas revised this gist Jan 5, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions webp2mp4.sh
    Original file line number Diff line number Diff line change
    @@ -12,11 +12,13 @@ then
    frame_count=$(($frame_count))

    for idx in $(seq -f '%02g' 01 $frame_count); do
    # Extract the frames from the webp
    webpmux -get frame $idx "$1" -o "$output_base/frame_$idx.png"
    # Use ImageMagick to convert the PNG to PNG, since the one outputted by webpmux seems unsupported by ffmpeg
    convert "$output_base/frame_$idx.png" "$output_base/frame_$idx.png"
    done

    # Take the frames and assemble the MP4. We need to tune the FPS, since right now it is hardcoded
    ffmpeg -framerate 5 -pattern_type glob -i "$output_base/"'frame_*.png' -c:v libx264 -pix_fmt yuv420p output.mp4
    fi

  3. ajmas revised this gist Jan 5, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions webp2mp4.sh
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ then

    for idx in $(seq -f '%02g' 01 $frame_count); do
    webpmux -get frame $idx "$1" -o "$output_base/frame_$idx.png"
    # Use ImageMagick to convert the PNG to PNG, since the one outputted by webpmux seems unsupported by ffmpeg
    convert "$output_base/frame_$idx.png" "$output_base/frame_$idx.png"
    done

  4. ajmas created this gist Jan 5, 2024.
    21 changes: 21 additions & 0 deletions webp2mp4.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/bin/sh

    input=$1
    output_base=/tmp
    regex="Number of frames: ([0-9]+)"
    info=`webpmux -info "$1"`

    if [[ $info =~ $regex ]]
    then
    rm "$output_base/frame_*.png"
    frame_count="${BASH_REMATCH[1]}"
    frame_count=$(($frame_count))

    for idx in $(seq -f '%02g' 01 $frame_count); do
    webpmux -get frame $idx "$1" -o "$output_base/frame_$idx.png"
    convert "$output_base/frame_$idx.png" "$output_base/frame_$idx.png"
    done

    ffmpeg -framerate 5 -pattern_type glob -i "$output_base/"'frame_*.png' -c:v libx264 -pix_fmt yuv420p output.mp4
    fi