Public/Start-BurnSubtitles.ps1

function Start-BurnSubtitles {
    <#
    .DESCRIPTION
    Burn subtitles from embeded subtitles or an srt file. Option exists to transcode or burn subtitles only.
 
    .NOTES
    Outpath folder must already be created prior to running the command
 
    .PARAMETER Video
    Specify Video Input
 
    .PARAMETER Transcode
    Specify if the video should also be transcoded
 
    .PARAMETER Subindex
    Specify the subindex if using the embeded parameter set
 
    .PARAMETER Embed
    Specifies the subtitles being used are embeded
 
    .PARAMETER SrtFile
    Specify and srt file for use with the Srt parameter set
 
    .PARAMETER Srt
    Specify if the subtitles are contained in an external srt file
 
    .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" -srtfile "Action Jackson.srt" -srt
 
    .Example
    If the transcode switch parameter is used then the file will be transcoded in addition to the subtitles being burned.
 
    Start-BurnSubtitles -Movie "Action Jackson.mkv" -srtfile "Action Jackson.srt" -srt -Transcode
    #>

    [cmdletbinding()]
    param (
        [Parameter(Mandatory = $true, ParameterSetName = "embed")]
        [Parameter(Mandatory = $true, ParameterSetName = "srt")]
        $video,
        [Parameter(Mandatory = $False, ParameterSetName = "embed")]
        [Parameter(Mandatory = $False, ParameterSetName = "srt")]
        [Switch]
        $transcode,
        [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 ($env:FFToolsSource -and $env:FFToolsTarget) {
        #Change directory to the source folder
        Set-Location $env:FFToolsSource

        #Split variable to only provide the file name
        $videosplit = ($video).Split('\')[-1]
        $srtfilesplit = ($srtfile).Split('\')[-1]

        #execute subtitle burn
        if ($transcode) {

            if ($Embed) {
                ffmpeg.exe -i "$videosplit" -vf "subtitles=$video:si=$SubIndex" -c:v libx265 -crf 21 -ac 6 -c:a aac -preset veryfast "$outpath$video"
            }

            if ($srt) {
                ffmpeg.exe -i "$videosplit" -vf "subtitles=$srtfilesplit" -c:v libx265 -crf 21 -ac 6 -c:a aac -preset veryfast  "$env:FFToolsTarget$video"
            }
        }

        else {

            if ($Embed) {
                ffmpeg.exe -i "$videosplit" -vf "subtitles=$video:si=$SubIndex" "$outpath$video"
            }

            if ($srt) {
                ffmpeg.exe -i "$videosplit" -vf "subtitles=$srtfilesplit" "$outpath$video"
            }
        }
    }

    else {
        Write-Warning "You must first run Set-FFToolsVariables! This is only required once."
    }
}