Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save arest/02daf6c98a97776a74986e8a45159ea0 to your computer and use it in GitHub Desktop.

Select an option

Save arest/02daf6c98a97776a74986e8a45159ea0 to your computer and use it in GitHub Desktop.

Revisions

  1. @anguyen8 anguyen8 revised this gist Sep 21, 2016. 1 changed file with 18 additions and 0 deletions.
    18 changes: 18 additions & 0 deletions make_crossfade_ffmpeg_video_from_images.sh
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,24 @@
    # This script takes in images from a folder and make a crossfade video from the images using ffmpeg.
    # Make sure you have ffmpeg installed before running.

    # The output command looks something like the below, but for as many images as you have in the folder.
    # See the answer by LordNeckbeard at:
    # http://superuser.com/questions/833232/create-video-with-5-images-with-fadein-out-effect-in-ffmpeg/1071748#1071748
    #
    #
    # ffmpeg \
    # -loop 1 -t 1 -i 001.png \
    # -loop 1 -t 1 -i 002.png \
    # -loop 1 -t 1 -i 003.png \
    # -loop 1 -t 1 -i 004.png \
    # -loop 1 -t 1 -i 005.png \
    # -filter_complex \
    # "[1:v][0:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b1v]; \
    # [2:v][1:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b2v]; \
    # [3:v][2:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b3v]; \
    # [4:v][3:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b4v]; \
    # [0:v][b1v][1:v][b2v][2:v][b3v][3:v][b4v][4:v]concat=n=9:v=1:a=0,format=yuv420p[v]" -map "[v]" out.mp4

    #----------------------------------------------------------------
    # SETTINGS
    input_dir="/path/to/your/folder" # Replace this by a path to your folder /path/to/your/folder
  2. @anguyen8 anguyen8 revised this gist May 1, 2016. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions make_crossfade_ffmpeg_video_from_images.sh
    Original file line number Diff line number Diff line change
    @@ -5,14 +5,15 @@
    # MIT License

    # This script takes in images from a folder and make a crossfade video from the images using ffmpeg.
    # Crossfade between each pair of images is 0.5 seconds.
    # Make sure you have ffmpeg installed before running.

    #----------------------------------------------------------------
    # SETTINGS
    input_dir="/path/to/your/folder" # Replace this by a path to your folder /path/to/your/folder
    n_files=10 # Replace this by a number of images
    files=`ls ${input_dir}/*.jpg | head -${n_files}` # Change the file type to the correct type of your images
    output_file="video.mp4" # Name of output video
    crossfade=0.9 # Crossfade duration between two images
    #----------------------------------------------------------------

    # Making an ffmpeg script...
    @@ -27,7 +28,7 @@ for f in ${files}; do

    next=$((i+1))
    if [ "${i}" -ne "$((n_files-1))" ]; then
    filters+=" [${next}:v][${i}:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b${next}v];"
    filters+=" [${next}:v][${i}:v]blend=all_expr='A*(if(gte(T,${crossfade}),1,T/${crossfade}))+B*(1-(if(gte(T,${crossfade}),1,T/${crossfade})))'[b${next}v];"
    fi

    if [ "${i}" -gt "0" ]; then
    @@ -37,7 +38,7 @@ for f in ${files}; do
    i=$((i+1))
    done

    output+="concat=n=$((i * 2 - 1)):v=1:a=0,format=yuv420p[v]\" -map \"[v]\" out.mp4"
    output+="concat=n=$((i * 2 - 1)):v=1:a=0,format=yuv420p[v]\" -map \"[v]\" ${output_file}"

    script="ffmpeg ${input} -filter_complex \"${filters} ${output}"

  3. @anguyen8 anguyen8 revised this gist May 1, 2016. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions make_crossfade_ffmpeg_video_from_images.sh
    Original file line number Diff line number Diff line change
    @@ -4,8 +4,9 @@
    # 2016-04-30
    # MIT License

    # This script takes in images from a folder and make a crossfade video from the images.
    # Crossfade between each pair of images is 0.5 seconds
    # This script takes in images from a folder and make a crossfade video from the images using ffmpeg.
    # Crossfade between each pair of images is 0.5 seconds.
    # Make sure you have ffmpeg installed before running.

    #----------------------------------------------------------------
    # SETTINGS
  4. @anguyen8 anguyen8 revised this gist May 1, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions make_crossfade_ffmpeg_video_from_images.sh
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,9 @@

    #----------------------------------------------------------------
    # SETTINGS
    input_dir="accuracy_in_frames"
    n_files=10
    files=`ls ${input_dir}/*.jpg | head -${n_files}`
    input_dir="/path/to/your/folder" # Replace this by a path to your folder /path/to/your/folder
    n_files=10 # Replace this by a number of images
    files=`ls ${input_dir}/*.jpg | head -${n_files}` # Change the file type to the correct type of your images
    #----------------------------------------------------------------

    # Making an ffmpeg script...
  5. @anguyen8 anguyen8 created this gist May 1, 2016.
    46 changes: 46 additions & 0 deletions make_crossfade_ffmpeg_video_from_images.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    #!/bin/bash

    # Anh Nguyen <[email protected]>
    # 2016-04-30
    # MIT License

    # This script takes in images from a folder and make a crossfade video from the images.
    # Crossfade between each pair of images is 0.5 seconds

    #----------------------------------------------------------------
    # SETTINGS
    input_dir="accuracy_in_frames"
    n_files=10
    files=`ls ${input_dir}/*.jpg | head -${n_files}`
    #----------------------------------------------------------------

    # Making an ffmpeg script...
    input=""
    filters=""
    output="[0:v]"

    i=0

    for f in ${files}; do
    input+=" -loop 1 -t 1 -i $f"

    next=$((i+1))
    if [ "${i}" -ne "$((n_files-1))" ]; then
    filters+=" [${next}:v][${i}:v]blend=all_expr='A*(if(gte(T,0.5),1,T/0.5))+B*(1-(if(gte(T,0.5),1,T/0.5)))'[b${next}v];"
    fi

    if [ "${i}" -gt "0" ]; then
    output+="[b${i}v][${i}:v]"
    fi

    i=$((i+1))
    done

    output+="concat=n=$((i * 2 - 1)):v=1:a=0,format=yuv420p[v]\" -map \"[v]\" out.mp4"

    script="ffmpeg ${input} -filter_complex \"${filters} ${output}"

    echo ${script}

    # Run it
    eval "${script}"