@@ -18,6 +18,9 @@ The name of the output file. By default, this is set to "out.ts".
1818. PARAMETER ChunkSize
1919The number of files to process in each chunk. This helps to avoid exceeding the command line length limit when concatenating files.
2020
21+ . PARAMETER UseFFmpeg
22+ Use FFMPEG to join files instead of build in copy command.
23+
2124. EXAMPLE
2225Join-TsFile "c:\test\"
2326Joins all *.ts files found in a "c:\test\" directory
@@ -39,9 +42,15 @@ If the total command length is too long for the cmd /c copy operation, reducing
3942 [Parameter (Mandatory = $false , Position = 2 )]
4043 [string ]$OutFile = " out.ts" ,
4144 [Parameter (Mandatory = $false , Position = 3 )]
42- [int ]$ChunkSize = 1000
45+ [int ]$ChunkSize = 1000 ,
46+ [Parameter (Mandatory = $false , Position = 4 )]
47+ [switch ]$UseFFmpeg
4348 )
4449
50+ function Test-FFmpegInstalled {
51+ return Get-Command ffmpeg - ErrorAction SilentlyContinue - OutVariable + Null
52+ }
53+
4554 $location = Get-Location
4655 try {
4756 if (! [string ]::IsNullOrWhiteSpace($FilesLocation )) {
@@ -52,13 +61,24 @@ If the total command length is too long for the cmd /c copy operation, reducing
5261 $tsFile = $Files | Select-Object - First 1
5362 $FilesLocation = $tsFile.Directory
5463 }
64+
65+ $fileNames = $fileNames | ? { $_ -ne $OutFile }
66+
5567 Set-Location $FilesLocation
5668
57- Copy-Item - Path $fileNames [0 ] - Destination $OutFile
58- for ($i = 1 ; $i -lt $fileNames.Count ; $i += $ChunkSize ) {
59- $chunk = $fileNames [$i .. ([math ]::Min($i + $ChunkSize - 1 , $fileNames.Count - 1 ))]
60- $concatenatedNames = $chunk -join " +"
61- cmd / c copy / b " $OutFile +$concatenatedNames " $OutFile | Out-Null
69+ if ($UseFFmpeg -and (Test-FFmpegInstalled )) {
70+ $tmpFilePath = Join-Path - Path (Get-Location ).Path - ChildPath " _fileList.txt"
71+ $fileNames | % { " file '$ ( $_ ) '" } | Set-Content - Path $tmpFilePath
72+ ffmpeg -f concat - safe 0 - i $tmpFilePath - c copy $OutFile - loglevel quiet
73+ Remove-Item - Path $tmpFilePath
74+ }
75+ else {
76+ Copy-Item - Path $fileNames [0 ] - Destination $OutFile
77+ for ($i = 1 ; $i -lt $fileNames.Count ; $i += $ChunkSize ) {
78+ $chunk = $fileNames [$i .. ([math ]::Min($i + $ChunkSize - 1 , $fileNames.Count - 1 ))]
79+ $concatenatedNames = $chunk -join " +"
80+ cmd / c copy / b " $OutFile +$concatenatedNames " $OutFile | Out-Null
81+ }
6282 }
6383 }
6484 finally {
0 commit comments