Repository navigation
Expand file tree
/
Copy pathTranscodeAviToMP4.ps1
More file actions
87 lines (69 loc) · 2.87 KB
/
Copy pathTranscodeAviToMP4.ps1
File metadata and controls
87 lines (69 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
function Get-AviRemuxScript{
<# .SYNOPSIS
Generates a batch file of FFmpeg commands to remux AVI files into MP4 containers
.DESCRIPTION
A function to generate a batch file with FFMpeg commands that will remux AVIs into an mp4 container, to try and get better streaming support.
A batch file is generated because it turns out spawning a command line task out in Powershell is really kludgey and unreliable.
Assumes ffmpeg.exe is on the path
.NOTES
Author : Jason Coleman - pobox@chiencorp.com
GitTest
TODO:
.LINK
#>
Param(
[string]$Path=".\",
[string]$Action="batch"
)
# Set working path
$Path = Read-Host "Path to search(default to current)"
# Set default if no response
# If (!$Path){$Path = ".\"}
# Set action path
#$Action = Read-Host "Action(Remux or Transcode)"
# Set default if no response
If (!$Action){$Action = "batch"}
switch ( $Action )
{
'remux' {}
'batch' {}
default { $Action = "batch"}
}
#### Startup Checks ####
# Validate path
If (!(Test-Path $Path)){
Throw "Specified path not found"
}
# Trying something a little different, caching the output to memory instead of writing line by line.
$BatBuf = New-Object System.Text.StringBuilder
$CleanupBuf = New-Object System.Text.StringBuilder
$FileList = Get-ChildItem -Recurse -Filter '*.avi' -File -ErrorAction 'SilentlyContinue' | Sort-Object
Foreach ($file IN $FileList){
# Version of path with mp4 extension:
$mp4Name = ($file.FullName).TrimEnd(".avi") + ".mp4"
$bakName = ($file.FullName).TrimEnd(".avi") + ".bak"
# Wrap this in some logic
# Remux
$BatBuf.Append("ffmpeg -i """ + $file.FullName + """ -acodec copy -vcodec copy """ + $mp4name + """`r`n")
# Transcode
#$BatBuf.Append("ffmpeg -i """ + $file.FullName + """ -acodec copy -vcodec copy """ + $mp4name + """`r`n")
$BatBuf.Append("Rename-Item """ + $file.FullName + """ """ + $bakName + """`r`n")
$CleanupBuf.Append("Remove-Item ""$bakName""`r`n")
}
Write-Debug -Message "Writing AviRemux.ps1"
Try {
# Note: Out-File inside the VS.Code powershell env sticks a BOM mark in that doesn't happen in normal powershell
$BatBuf.ToString() | out-file AviRemux.ps1 -Encoding ascii
}
Catch{
Throw "Failed to write AviRemux.ps1. Batbuf Size:" + $BatBuf.Length
}
Write-Debug -Message "Writing AviCleanup.ps1"
Try {
# Note: Out-File inside the VS.Code powershell env sticks a BOM mark in that doesn't happen in normal powershell
$CleanupBuf.ToString() | out-file AviCleanup.ps1 -Encoding ascii
}
Catch{
Throw "Failed to write AviCleanup.ps1. CleanupBuf Size:" + $CleanupBuf.Length
}
}