Skip to content

Instantly share code, notes, and snippets.

@BitbeyHub
Created December 22, 2019 14:23
Show Gist options
  • Save BitbeyHub/f0c9de4010c55d4949f1138d987f8d47 to your computer and use it in GitHub Desktop.
Save BitbeyHub/f0c9de4010c55d4949f1138d987f8d47 to your computer and use it in GitHub Desktop.
Extract all its frames from a video according to its native frame rate using ffmpeg with Powershell script languague as example.
[string]$your_video = Read-Host 'Plz enter the fullpath of your video to extract.'
[string]$fps = ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate -of default=nokey=1:noprint_wrappers=1 -i $your_video # This will return a string like '30/1'
[int]$fps = Invoke-Expression $fps # Let's try to run the string directly as an expression somehow like a trick.
[string]$frame_count = ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 -i $your_video
[string]$out_path = Read-Host 'Choose a fullpath to extract all its frames. (e.g., C:\Users\xxx\Desktop)'
[string]$out_name_pattern = Read-Host 'Choose a name pattern of the frames. (e.g., Github -> Github_001.png)'
# extracting
ffmpeg -i $your_video -r $fps "$($out_path)\$($out_name_pattern)_%$($frame_count.Length)d.png"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment