Skip to content

Instantly share code, notes, and snippets.

@ravihara
Created November 10, 2017 09:55
Show Gist options
  • Select an option

  • Save ravihara/75078bafee933bc91e0d57287c44d1ed to your computer and use it in GitHub Desktop.

Select an option

Save ravihara/75078bafee933bc91e0d57287c44d1ed to your computer and use it in GitHub Desktop.

Revisions

  1. ravihara created this gist Nov 10, 2017.
    24 changes: 24 additions & 0 deletions video2mp4.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/bin/bash -e
    # Shell script to convert videos in a folder to mp4 format

    export IFS=$(echo -en "\n\b")

    VID_LIST_FILE="/tmp/videos.txt"

    ## List out the videos first
    rm -f $VID_LIST_FILE
    for a in $(find . -iname "video*" -type d); do
    find $a -name "*" -type f | grep -v "Thumbs.db" | sed -e 's/^.\///' >> $VID_LIST_FILE
    sync
    done

    ## Convert the videos to mp4
    for a in $(cat $VID_LIST_FILE); do
    b="$(echo $a | sed -e 's/.\w\+$/.mp4/')"
    ffmpeg -i "$a" -vcodec libx264 -b 500k "$b" && sync
    done

    # Finally, remove the temporary video list file
    rm -f $VID_LIST_FILE

    exit 0