functions/public/Join-VideoFile.ps1

function Join-VideoFile {
  <#
  .SYNOPSIS
  This is a rudimentary function that joins together video files.

  .PARAMETER Filter
  Specify the filter for files, in the current directory, that you'd like to concatenate together.
  
  .PARAMETER OutputPath
  Specify the output file path that you want to write the resulting concatenated file to.
  #>

  [CmdletBinding()]
  param (
    [Parameter(Mandatory = $false)]
    [string] $Filter,
    [Parameter(Mandatory = $false)]
    [string] $OutputPath
  )

  # Get the files that will be included in the concatenation operation
  $FileList = Get-ChildItem -Path $Filter | Sort-Object -Property Name

  if (!$FileList) {
    throw 'Did not find any files with the specified filter: {0}' -f $Filter
    return
  }

  # Specify an output path, based on the first file in the input list
  if (!$OutputPath) {
    $OutputPath = '{0}.concat{1}' -f $FileList[0].FullName.Substring(0, $FileList[0].FullName.Length - 1 - $FileList[0].Extension.Length), $FileList[0].Extension
  }

  # Specify the text file that will be used to specify the input file list to FFMPEG
  $TargetFile = '{0}\ffmpeglist.txt' -f $FileList[0].Directory

  # Add each included file into the FFMPEG input file list for concatenation
  Set-Content -Path $TargetFile -Value ''
  foreach ($File in $FileList) {
    Add-Content -Path $TargetFile -Value ('file ''{0}''' -f $File.FullName)
  }

  # Run the ffmpeg concat command
  ffmpeg -f concat -safe 0 -i $TargetFile -c copy $OutputPath

  # Clean up the text file with the file list for FFMPEG
  Remove-Item -Path $TargetFile
}