Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## ConvertVideo.ps1
- ## Requires FFMPEG https://www.ffmpeg.org/download.html
- ## Batch converts a directory of files to the a given format
- ## eg
- ## Given a directory with files:
- ## vid1.mkv, vid2.mkv, vid3.mkv
- ## Running the command ConvertVideo.mp4 -filepath %PATHTOFILES% -convertto MP4
- ## the results would be:
- ## vid1.mp4, vid2.mp4, vid3.mp4
- ## Usage:
- ## ConvertVideo.ps1 -filepath %PATHTOFILES% -convertto %EXT% [-ffmpeglocation %PATHTOFFMPEG%]
- ## -filepath is the path to the files to be converted, spaces must be quoted, trailing slash must be added
- ## -convertto is the new extension. Extension must be supported by ffmpeg https://www.ffmpeg.org/documentation.html
- ## -ffmpeglocation (optional) is the filepath to ffmpeg.exe. Default is "c:\program files\ffmpeg\ffmpeg.exe"
- ## eg:
- ## ConvertVideo.ps1 -filepath c:\scripts\videos\ -convertto MP4
- ## ConvertVideo.ps1 -filepath "c:\batch files\videos\" -convertto FLV
- ## ConvertVideo.ps1 -filepath "c:\batch files\videos\" -convertto FLV -ffmpeglocation "c:\program files\audio files\ffmpeg\ffmpeg.exe"
- param(
- [string]$filepath=$(throw "-filepath parameter is required"),
- [string]$convertto=$(throw "-convertto parameter is required"),
- [string]$ffmpeglocation="c:\program files\ffmpeg\ffmpeg.exe"
- )
- # ---------------------------------------------------------------------------#
- $ffmpegInputFile="-i"
- $ffmpegCodec="-codec"
- $ffmpegCopy="copy"
- $listoffiles=get-childitem $filepath | sort lastwritetime
- ## check location of ffmpeg
- if (test-path $ffmpeglocation)
- {
- foreach ($file in $listoffiles)
- {
- ## perform the conversion
- $newname=$file.directoryname+"\"+$file.basename+"."+$convertto
- & $ffmpeglocation $ffmpegInputFile $file.fullname $ffmpegCodec $ffmpegcopy $newname
- }
- }
- else
- {
- throw "ffmpeg.exe not found - https://www.ffmpeg.org/download.html"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement