Functions/Functions.ps1


function Get-Tips {
    $tips
}

function Start-Transcode {
    <#
    .DESCRIPTION
    Transcodes video files containing extenstions *.mp4, *.mkv, *.avi, and *.mpg
     
    Inputed Parameters are
 
    -c:v libx265 -crf 21 -ac 6 -c:a aac -preset veryfast
     
    .NOTES
    Requires ffmpeg be installed in path
 
    Outpath folder must already be created prior to running the command
 
    .Example
    Specify the output path for the remuxed files
     
    Start-Transcode -outpath "c:\files\new files\"
    #>

    #>
    
    param (
        [Parameter(Mandatory = $true)]$outpath
    )

    $ext = "*.mkv"
    $array = @(Get-ChildItem -filter $ext)
        Foreach ($movie in $array.Name) {
            ffmpeg.exe -i $movie -c:v libx265 -crf 21 -ac 6 -c:a aac -preset veryfast "B:\Video Convert\new\$movie"
    }

    $ext = "*.avi"
    $array = @(Get-ChildItem -filter $ext)
        Foreach ($movie in $array.Name) {
            ffmpeg.exe -i $movie -c:v libx265 -crf 21 -ac 6 -c:a aac -preset veryfast "B:\Video Convert\new\$movie"
    }

    $ext = "*.mp4"
    $array = @(Get-ChildItem -filter $ext)
        Foreach ($movie in $array.Name) {
            ffmpeg.exe -i $movie -c:v libx265 -crf 21 -ac 6 -c:a aac -preset veryfast "B:\Video Convert\new\$movie"
    }

    $ext = "*.mpg"
    $array = @(Get-ChildItem -filter $ext)
        Foreach ($movie in $array.Name) {
            ffmpeg.exe -i $movie -c:v libx265 -crf 21 -ac 6 -c:a aac -preset veryfast "B:\Video Convert\new\$movie"
    }
}


function Start-BurnSubtitles {
    <#
    .DESCRIPTION
    Burn subtitles from embeded subtitles or an srt file
 
    .NOTES
    Requires ffmpeg be installed in path
 
    .Example
    When using embeded subtitles specify the movie and the index for the embedded srt.
     
    Start-BurnSubtitles -Movie "Action Jackson.mkv" -subindex 0 -embed
 
    .Example
    When using embeded subtitles specify the movie and the index for the embedded srt.
     
    Start-BurnSubtitles -Movie "Action Jackson.mkv" -outpath "c:\files\new files" -srtfile 0 -srt
    #>


    param (
        [Parameter(Mandatory = $true, ParameterSetName = "embed")]
        [Parameter(Mandatory = $true, ParameterSetName = "srt")]
        $Movie,
        [Parameter(Mandatory = $true, ParameterSetName = "embed")]
        [Parameter(Mandatory = $true, ParameterSetName = "srt")]
        $outpath,
        [Parameter(Mandatory = $true, ParameterSetName = "embed")]$SubIndex,
        [Parameter(Mandatory = $true, ParameterSetName = "embed")][Switch]$Embed,
        [Parameter(Mandatory = $true, ParameterSetName = "srt")]$srtfile,
        [Parameter(Mandatory = $true, ParameterSetName = "srt")][Switch]$srt
    )
    
    if ($Embed) {
        set-location "B:\Video Convert"
        ffmpeg -i "$Movie" -vf "subtitles=$Movie:si=$SubIndex" "$outpath$Movie"
    }

    if ($srt) {
        ffmpeg -i "$Movie" -vf "subtitles=$srtfile" -c:v libx265 -crf 23 -ac 6 -c:a aac -preset veryfast  "$outpath$Movie"
    }
}


function Start-Remux {
    <#
    .DESCRIPTION
    Remux files to mkv
 
    .NOTES
    Requires ffmpeg be installed in path
 
    Outpath folder must already be created prior to running the command
 
    .Example
    Specify the output path for the remuxed files
     
    Start-Remux -outpath "c:\folder\folder new\"
    #>


    param (
        [Parameter(Mandatory = $true)]$outpath
    )

    $ext = "*.avi"
    $array = @(Get-ChildItem -filter $ext)
        Foreach ($movie in $array.Name) {
            $movieout = $movie -split ".avi"
            ffmpeg -i "$Movie" -c copy "$outpath$Movieout.mkv"
    }

    $ext = "*.mp4"
    $array = @(Get-ChildItem -filter $ext)
        Foreach ($movie in $array.Name) {
            $movieout = $movie -split ".mp4"
            ffmpeg -i "$Movie" -c copy "$outpath$Movieout.mkv"
    }

    $ext = "*.mpg"
    $array = @(Get-ChildItem -filter $ext)
        Foreach ($movie in $array.Name) {
            $movieout = $movie -split ".mpg"
            ffmpeg -i "$Movie" -c copy "$outpath$Movieout.mkv"
    }  
}