Skip to content

Instantly share code, notes, and snippets.

@steventrux
Last active May 27, 2021 22:56

Revisions

  1. steventrux revised this gist Apr 17, 2014. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions Chromecast batch conversion script
    Original file line number Diff line number Diff line change
    @@ -75,7 +75,7 @@ if ffmpeg -formats > /dev/null 2>&1
    ffversion=`ffmpeg -version 2> /dev/null | grep ffmpeg | sed -n 's/ffmpeg\s//p'`
    echo "Your ffmpeg verson is $ffversion"
    else
    echo "\nERROR:\nYou need ffmpeg installed with x264 and an aac encoder"
    echo "ERROR: You need ffmpeg installed with x264 and libfdk_aac encoder"
    exit
    fi

    @@ -111,7 +111,7 @@ if ffmpeg -codecs 2> /dev/null | grep "libx264" > /dev/null
    exit
    fi

    echo "Your FFMpeg is OK\nEntering File Processing\n\n"
    echo "Your FFMpeg is OK Entering File Processing"

    ################################################################
    cd "$sourcedir"
    @@ -120,7 +120,7 @@ do
    if ffmpeg -i $filelist 2>&1 | grep 'Invalid data found' #check if it's video file
    then
    echo "ERROR File $filelist is NOT A VIDEO FILE can be converted!"
    exit
    continue

    fi

    @@ -143,8 +143,8 @@ do
    acodec=libfdk_aac
    fi


    echo "\n\nUseing video codec: $vcodec audio codec: $acodec and Container format $outformat for\nFile: $filelist\n\n\n\nStarting Converting\n"
    echo "Converting $filelist"
    echo "Video codec: $vcodec Audio codec: $acodec Container: $outformat"

    # using ffmpeg for real converting
    echo "ffmpeg -i $filelist -y -f $outformat -acodec $acodec -ab 192k -ac 2 -absf aac_adtstoasc -async 1 -vcodec $vcodec -vsync 0 -profile:v main -level 3.1 -qmax 22 -qmin 20 -x264opts no-cabac:ref=2 -threads 0 $indir/castable/$filelist.$outmode"
  2. steventrux revised this gist Apr 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Chromecast batch conversion script
    Original file line number Diff line number Diff line change
    @@ -155,5 +155,5 @@ done
    echo ALL Processed!

    ###################
    echo "DONE"
    echo "DONE, your video files are chromecast ready"
    exit
  3. steventrux revised this gist Apr 16, 2014. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Chromecast batch conversion script
    Original file line number Diff line number Diff line change
    @@ -48,13 +48,18 @@ fi

    # Target dir
    indir=$3
    if [[ $indir ]]; then
    if mkdir -p $indir/castable
    then
    echo "Using $indir/castable as Output Folder"
    else
    echo "Error: Check if you have the rights to write in $indir"
    exit
    fi
    else
    echo "Error: Check if you have set an output folder"
    exit
    fi

    # set format
    if [ $outmode=mp4 ]
  4. Steven Trux revised this gist Apr 16, 2014. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions Chromecast batch conversion script
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #! /bin/bash

    # Batch Convert Script by SteVenTrux
    # Batch Convert Script by StevenTrux
    # The Purpose of this Script is to batch convert any video file to mp4 or mkv format for chromecast compatibility
    # this script only convert necessary tracks if the video is already
    # in H.264 format it won't convert it saving your time!
    @@ -16,12 +16,10 @@

    # usage:
    #########################
    #########################
    # cast.sh mp4 /home/user/divx /home/user/chromecastvideos
    # or
    # cast.sh mkv /home/user/divx /home/user/chromecastvideos
    #########################
    #########################

    # working mode
    outmode=$1
  5. Steven Trux revised this gist Apr 16, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Chromecast batch conversion script
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #! /bin/bash

    # Batch Convert Script by Stefano
    # Batch Convert Script by SteVenTrux
    # The Purpose of this Script is to batch convert any video file to mp4 or mkv format for chromecast compatibility
    # this script only convert necessary tracks if the video is already
    # in H.264 format it won't convert it saving your time!
  6. Steven Trux revised this gist Apr 16, 2014. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions Chromecast batch conversion script
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,6 @@
    # sourcedir is the directory where to be converted videos are
    # indir is the directory where converted video will be created


    # usage:
    #########################
    #########################
    @@ -152,8 +151,6 @@ do
    done
    echo ALL Processed!



    ###################
    echo "DONE"
    exit
  7. Steven Trux created this gist Apr 16, 2014.
    159 changes: 159 additions & 0 deletions Chromecast batch conversion script
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,159 @@
    #! /bin/bash

    # Batch Convert Script by Stefano
    # The Purpose of this Script is to batch convert any video file to mp4 or mkv format for chromecast compatibility
    # this script only convert necessary tracks if the video is already
    # in H.264 format it won't convert it saving your time!

    # Put all video files need to be converted in a folder!
    # the name of files must not have " " Space!
    # Rename the File if contain space

    # Variable used:
    # outmode should be mp4 or mkv
    # sourcedir is the directory where to be converted videos are
    # indir is the directory where converted video will be created


    # usage:
    #########################
    #########################
    # cast.sh mp4 /home/user/divx /home/user/chromecastvideos
    # or
    # cast.sh mkv /home/user/divx /home/user/chromecastvideos
    #########################
    #########################

    # working mode
    outmode=$1
    # check output mode
    if [[ $outmode ]]; then
    if [ $outmode = "mp4" ] || [ $outmode = "mkv" ]
    then
    echo "WORKING MODE $outmode"
    else
    echo "$outmode is NOT a Correct target format. You need to set an output format! like cast.sh mp4 xxxx or cast.sh mkv xxxx"
    exit
    fi
    else
    echo "Working mode is missing. You should set a correct target format like mp4 or mkv"
    exit
    fi

    # Source dir
    sourcedir=$2
    if [[ $sourcedir ]]; then
    echo "Using $sourcedir as Input Folder"
    else
    echo "Error: Check if you have set an input folder"
    exit
    fi

    # Target dir
    indir=$3
    if mkdir -p $indir/castable
    then
    echo "Using $indir/castable as Output Folder"
    else
    echo "Error: Check if you have the rights to write in $indir"
    exit
    fi

    # set format
    if [ $outmode=mp4 ]
    then
    outformat=mp4
    else
    outformat=matroska
    fi

    # Check FFMPEG Installation
    if ffmpeg -formats > /dev/null 2>&1
    then
    ffversion=`ffmpeg -version 2> /dev/null | grep ffmpeg | sed -n 's/ffmpeg\s//p'`
    echo "Your ffmpeg verson is $ffversion"
    else
    echo "\nERROR:\nYou need ffmpeg installed with x264 and an aac encoder"
    exit
    fi

    if ffmpeg -formats 2> /dev/null | grep "E mp4" > /dev/null
    then
    echo "Check mp4 container format ... OK"
    else
    echo "Check mp4 container format ... NOK"
    exit
    fi

    if ffmpeg -formats 2> /dev/null | grep "E matroska" > /dev/null
    then
    echo "Check mkv container format ... OK"
    else
    echo "Check mkv container format ... NOK"
    exit
    fi

    if ffmpeg -codecs 2> /dev/null | grep "libfdk_aac" > /dev/null
    then
    echo "Check AAC Audio Encoder ... OK"
    else
    echo "Check AAC Audio Encoder ... NOK"
    exit
    fi

    if ffmpeg -codecs 2> /dev/null | grep "libx264" > /dev/null
    then
    echo "Check x264 the free H.264 Video Encoder ... OK"
    else
    echo "Check x264 the free H.264 Video Encoder ... NOK"
    exit
    fi

    echo "Your FFMpeg is OK\nEntering File Processing\n\n"

    ################################################################
    cd "$sourcedir"
    for filelist in `ls`
    do
    if ffmpeg -i $filelist 2>&1 | grep 'Invalid data found' #check if it's video file
    then
    echo "ERROR File $filelist is NOT A VIDEO FILE can be converted!"
    exit

    fi

    if ffmpeg -i $filelist 2>&1 | grep Video: | grep h264 #check video codec
    then
    vcodec=copy
    else
    vcodec=libx264
    fi

    if ffmpeg -i $filelist 2>&1 | grep Video: | grep "High 10" #10 bit H.264 can't be played by Hardware.
    then
    vcodec=libx264
    fi

    if [ ffmpeg -i $filelist 2>&1 | grep Audio: | grep aac ] || [ ffmpeg -i $filelist 2>&1 | grep Audio: | grep mp3 ] #check audio codec
    then
    acodec=copy
    else
    acodec=libfdk_aac
    fi


    echo "\n\nUseing video codec: $vcodec audio codec: $acodec and Container format $outformat for\nFile: $filelist\n\n\n\nStarting Converting\n"

    # using ffmpeg for real converting
    echo "ffmpeg -i $filelist -y -f $outformat -acodec $acodec -ab 192k -ac 2 -absf aac_adtstoasc -async 1 -vcodec $vcodec -vsync 0 -profile:v main -level 3.1 -qmax 22 -qmin 20 -x264opts no-cabac:ref=2 -threads 0 $indir/castable/$filelist.$outmode"
    ffmpeg -i $filelist -y -f $outformat -acodec $acodec -ab 192k -ac 2 -absf aac_adtstoasc -async 1 -vcodec $vcodec -vsync 0 -profile:v main -level 3.1 -qmax 22 -qmin 20 -x264opts no-cabac:ref=2 -threads 0 $indir/castable/$filelist.$outmode


    done
    echo ALL Processed!



    ###################
    echo "DONE"
    exit