We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decided to make a powershell version of comcut for fun (and for me):
param( [string]$infile, [string]$outfile, [switch]$keepEdl, [switch]$keepMeta, [string]$ffmpegPath = ".\ffmpeg.exe", [string]$comskipPath = ".\comskip.exe", [string]$comskipini = "$env:USERPROFILE.comskip.ini", [string]$lockfile, [string]$workdir ) $ldPath = $env:LD_LIBRARY_PATH $env:LD_LIBRARY_PATH = "" $exitcode = 0 if (-not $infile) { $exename = Split-Path -Leaf $MyInvocation.MyCommand.Path Write-Host "Remove commercial from video file using EDL file" Write-Host " (If no EDL file is found, comskip will be used to generate one)" Write-Host "" Write-Host "Usage: $exename infile [outfile]" exit 1 } [bool]$deleteedl = $keepEdl [bool]$deletemeta = $keepMeta $deletelog = $true $deletelogo = $true $deletetxt = $true $tempfiles = @() $totalcutduration = 0 if (-not $outfile) { $outfile = $infile } $outdir = Split-Path $outfile -Parent $outextension = $outfile -split "." | Select-Object -Last 1 $comskipoutput = "" if ($workdir) { if (!($workdir.EndsWith(""))) { $comskipoutput = "--output=$workdir" $workdir += "" } $infileb = Split-Path $infile -Leaf $edlfile = "${workdir}$($infileb -replace '.[^.]+$').edl" $metafile = "${workdir}$($infileb -replace '.[^.]+$').ffmeta" $logfile = "${workdir}$($infileb -replace '.[^.]+$').log" $logofile = "${workdir}$($infileb -replace '.[^.]+$').logo.txt" $txtfile = "${workdir}$($infileb -replace '.[^.]+$').txt" } else { $edlfile = "$($infile -replace '.[^.]+$').edl" $metafile = "$($infile -replace '.[^.]+$').ffmeta" $logfile = "$($infile -replace '.[^.]+$').log" $logofile = "$($infile -replace '.[^.]+$').logo.txt" $txtfile = "$($infile -replace '.[^.]+$').txt" } if (-not (Test-Path $comskipIni)) { "output_edl=1" | Out-File -Encoding utf8 $comskipIni } elseif ((Get-Content $comskipIni) -notcontains "output_edl=1") { "output_edl=1" | Add-Content -Encoding utf8 $comskipIni } if (-not (Test-Path $edlfile)) { & "$comskipPath" $comskipoutput --ini="$comskipIni" "$infile" } $start = 0 $i = 0 $hascommercials = $false $concat = "" $lines = Get-Content $edlfile foreach ($line in $lines) { $fields = $line -split "`t" $end = [float]$fields[0] $startnext = [float]$fields[1] if ([double]$end * 1000 -gt [double]$start * 1000) { $i++ $hascommercials = $true Add-Content -Path $metafile ";FFMETADATA1" Add-Content -Path $metafile "[CHAPTER]" Add-Content -Path $metafile "TIMEBASE=1/1000" Add-Content -Path $metafile "START=$([int]($start * 1000 - $totalcutduration * 1000))" Add-Content -Path $metafile "END=$([int]($end * 1000 - $totalcutduration * 1000))" Add-Content -Path $metafile "title=Chapter $i" $chapterfile = "$($infile -replace '.[^.]+$').part-$i.ts" if ($workdir) { $chapterfile = Split-Path $chapterfile -Leaf $chapterfile = "$workdir$chapterfile" } $tempfiles += $chapterfile $concat += "|$chapterfile" $duration = [double]$end - [double]$start & $ffmpegPath -hide_banner -loglevel error -nostdin -i $infile -ss $start -t $duration -c copy -y $chapterfile $totalcutduration += $startnext - $end } $start = $startnext } if ($hascommercials) { $endstring = & $ffmpegPath -hide_banner -nostdin -i $infile 2>&1 | Select-String -Pattern "Duration" | ForEach-Object { $_ -replace '\D+(\d+:\d+:\d+.\d+),.*', '$1' } $end=([TimeSpan]::Parse($endstring)).TotalSeconds if ([double]$end * 1000 -gt [double]$start * 1000) { $i++ Add-Content -Path $metafile "[CHAPTER]" Add-Content -Path $metafile "TIMEBASE=1/1000" Add-Content -Path $metafile "START=$([int]($start * 1000 - $totalcutduration * 1000))" Add-Content -Path $metafile "END=$([int]($end * 1000 - $totalcutduration * 1000))" Add-Content -Path $metafile "title=Chapter $i" $chapterfile = "$($infile -replace '.[^.]+$').part-$i.ts" if ($workdir) { $chapterfile = Split-Path $chapterfile -Leaf $chapterfile = "$workdir$chapterfile" } $tempfiles += $chapterfile $concat += "|$chapterfile" $duration = [double]$end - [double]$start & $ffmpegPath -hide_banner -loglevel error -nostdin -i $infile -ss $start -t $duration -c copy -y $chapterfile } & $ffmpegPath -hide_banner -loglevel error -nostdin -i $metafile -i ("concat:$($concat.Substring(1))") -c copy -map_metadata 0 -y $outfile } foreach ($tempfile in $tempfiles) { Remove-Item -Path $tempfile } if ($deleteedl) { Remove-Item -Path $edlfile } if ($deletemeta) { Remove-Item -Path $metafile } if ($deletelog) { Remove-Item -Path $logfile } if ($deletelogo) { Remove-Item -Path $logofile } if ($deletetxt) { Remove-Item -Path $txtfile } if ($ldPath) { $env:LD_LIBRARY_PATH = $ldPath } if ($lockfile) { Remove-Item -Path $lockfile }
The text was updated successfully, but these errors were encountered:
ComCutps1.txt
Sorry, something went wrong.
Awesome. Make a pull request and I'll consider adding it to the main repo.
No branches or pull requests
Decided to make a powershell version of comcut for fun (and for me):
param(
$edlfile = "$ {workdir}$($infileb -replace '.[^.]+$ ').edl"
$metafile = "$ {workdir}$($infileb -replace '.[^.]+$ ').ffmeta"
$logfile = "$ {workdir}$($infileb -replace '.[^.]+$ ').log"
$logofile = "$ {workdir}$($infileb -replace '.[^.]+$ ').logo.txt"
$txtfile = "$ {workdir}$($infileb -replace '.[^.]+$ ').txt"
$edlfile = "$ ($infile -replace '.[^.]+$ ').edl"
$metafile = "$ ($infile -replace '.[^.]+$ ').ffmeta"
$logfile = "$ ($infile -replace '.[^.]+$ ').log"
$logofile = "$ ($infile -replace '.[^.]+$ ').logo.txt"
$txtfile = "$ ($infile -replace '.[^.]+$ ').txt"$metafile "START=$ ([int]($start * 1000 - $totalcutduration * 1000))"$metafile "END=$ ([int]($end * 1000 - $totalcutduration * 1000))"
$chapterfile = "$ ($infile -replace '.[^.]+$ ').part-$i.ts"$metafile "START=$ ([int]($start * 1000 - $totalcutduration * 1000))"$metafile "END=$ ([int]($end * 1000 - $totalcutduration * 1000))"
$chapterfile = "$ ($infile -replace '.[^.]+$ ').part-$i.ts"$metafile -i ("concat:$ ($concat.Substring(1))") -c copy -map_metadata 0 -y $outfile
[string]$infile,
[string]$outfile,
[switch]$keepEdl,
[switch]$keepMeta,
[string]$ffmpegPath = ".\ffmpeg.exe",
[string]$comskipPath = ".\comskip.exe",
[string]$comskipini = "$env:USERPROFILE.comskip.ini",
[string]$lockfile,
[string]$workdir
)
$ldPath = $env:LD_LIBRARY_PATH
$env:LD_LIBRARY_PATH = ""
$exitcode = 0
if (-not $infile) {
$exename = Split-Path -Leaf $MyInvocation.MyCommand.Path
Write-Host "Remove commercial from video file using EDL file"
Write-Host " (If no EDL file is found, comskip will be used to generate one)"
Write-Host ""
Write-Host "Usage: $exename infile [outfile]"
exit 1
}
[bool]$deleteedl = $keepEdl
[bool]$deletemeta = $keepMeta
$deletelog = $true
$deletelogo = $true
$deletetxt = $true
$tempfiles = @()
$totalcutduration = 0
if (-not $outfile) {
$outfile = $infile
}
$outdir = Split-Path $outfile -Parent
$outextension = $outfile -split "." | Select-Object -Last 1
$comskipoutput = ""
if ($workdir) {
if (!($workdir.EndsWith(""))) {
$comskipoutput = "--output=$workdir"
$workdir += ""
}
$infileb = Split-Path $infile -Leaf
}
else {
}
if (-not (Test-Path $comskipIni)) {
"output_edl=1" | Out-File -Encoding utf8 $comskipIni
}
elseif ((Get-Content $comskipIni) -notcontains "output_edl=1") {
"output_edl=1" | Add-Content -Encoding utf8 $comskipIni
}
if (-not (Test-Path $edlfile)) {
& "$comskipPath" $comskipoutput --ini="$comskipIni" "$infile"
}
$start = 0
$i = 0
$hascommercials = $false
$concat = ""
$lines = Get-Content $edlfile
foreach ($line in $lines) {
$fields = $line -split "`t"
$end = [float]$fields[0]
$startnext = [float]$fields[1]
if ([double]$end * 1000 -gt [double]$start * 1000) {
$i++
$hascommercials = $true
Add-Content -Path $metafile ";FFMETADATA1"
Add-Content -Path $metafile "[CHAPTER]"
Add-Content -Path $metafile "TIMEBASE=1/1000"
Add-Content -Path
Add-Content -Path
Add-Content -Path $metafile "title=Chapter $i"
if ($workdir) {
$chapterfile = Split-Path $chapterfile -Leaf
$chapterfile = "$workdir$chapterfile"
}
$tempfiles += $chapterfile
$concat += "|$chapterfile"
$duration = [double]$end - [double]$start
& $ffmpegPath -hide_banner -loglevel error -nostdin -i $infile -ss $start -t $duration -c copy -y $chapterfile
$totalcutduration += $startnext - $end
}
$start = $startnext
}
if ($hascommercials) {
$endstring = & $ffmpegPath -hide_banner -nostdin -i $infile 2>&1 | Select-String -Pattern "Duration" | ForEach-Object { $_ -replace '\D+(\d+:\d+:\d+.\d+),.*', '$1' }
$end=([TimeSpan]::Parse($endstring)).TotalSeconds
if ([double]$end * 1000 -gt [double]$start * 1000) {
$i++
Add-Content -Path $metafile "[CHAPTER]"
Add-Content -Path $metafile "TIMEBASE=1/1000"
Add-Content -Path
Add-Content -Path
Add-Content -Path $metafile "title=Chapter $i"
if ($workdir) {
$chapterfile = Split-Path $chapterfile -Leaf
$chapterfile = "$workdir$chapterfile"
}
$tempfiles += $chapterfile
$concat += "|$chapterfile"
$duration = [double]$end - [double]$start
& $ffmpegPath -hide_banner -loglevel error -nostdin -i $infile -ss $start -t $duration -c copy -y $chapterfile
}
& $ffmpegPath -hide_banner -loglevel error -nostdin -i
}
foreach ($tempfile in $tempfiles) {
Remove-Item -Path $tempfile
}
if ($deleteedl) {
Remove-Item -Path $edlfile
}
if ($deletemeta) {
Remove-Item -Path $metafile
}
if ($deletelog) {
Remove-Item -Path $logfile
}
if ($deletelogo) {
Remove-Item -Path $logofile
}
if ($deletetxt) {
Remove-Item -Path $txtfile
}
if ($ldPath) {
$env:LD_LIBRARY_PATH = $ldPath
}
if ($lockfile) {
Remove-Item -Path $lockfile
}
The text was updated successfully, but these errors were encountered: