Last active
January 18, 2026 06:59
-
-
Save sombraguerrero/21f8231226372a9e078c964302416d68 to your computer and use it in GitHub Desktop.
Powershell for FFMPEG HLS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is a PowerShell script designed to be used with FFMPEG to encode videos for hls. | |
| # The duration calculation for .mov files is intended to account for videos recorded via iOS whose timelines | |
| # seem to have a large, continuous block of frames at the beginning whose PTS values are unusable for segmentation | |
| sl $PSScriptRoot | |
| $myMovie = Read-Host -Prompt 'Path to movie: ' | |
| $ext = (Get-Item $myMovie).Extension.ToLower() | |
| $isMov = $ext -eq ".mov" | |
| if ($isMov) { | |
| $duration = ffprobe -v error -show_entries format=duration -of csv=p=0 $myMovie | |
| $duration = [double]$duration | |
| # first fifth, rounded up | |
| $minSegment = [math]::Floor($duration / 5) | |
| } | |
| else { | |
| # default segment size for non-MOV files | |
| $minSegment = 6 | |
| } | |
| ffmpeg ` | |
| -i $myMovie ` | |
| -filter:v "scale=-2:1080" ` | |
| -c:v h264 -preset veryfast -b:v 5000k ` | |
| -c:a aac -b:a 128k ` | |
| -hls_time $minSegment ` | |
| -hls_segment_filename "1080p_%03d.ts" ` | |
| 1080p.m3u8 | |
| ffmpeg ` | |
| -i $myMovie ` | |
| -filter:v "scale=-2:720" ` | |
| -c:v h264 -preset veryfast -b:v 5000k ` | |
| -c:a aac -b:a 128k ` | |
| -hls_time $minSegment ` | |
| -hls_segment_filename "720p_%03d.ts" ` | |
| 720p.m3u8 | |
| ffmpeg ` | |
| -i $myMovie ` | |
| -filter:v "scale=-2:480" ` | |
| -c:v h264 -preset veryfast -b:v 5000k ` | |
| -c:a aac -b:a 128k ` | |
| -hls_time $minSegment ` | |
| -hls_segment_filename "480p_%03d.ts" ` | |
| 480p.m3u8 | |
| Write-Host "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment