Skip to content

Instantly share code, notes, and snippets.

@dciliberti
Last active January 5, 2025 10:09
Show Gist options
  • Save dciliberti/6200c2f9e0d37eb9addd65558f9522bb to your computer and use it in GitHub Desktop.
Save dciliberti/6200c2f9e0d37eb9addd65558f9522bb to your computer and use it in GitHub Desktop.
Powershell scripts to make video slideshow with many photos. Customize framerate and video format. Useful to make stop motion movies.

English version

Scroll down for the Italian description.

Scope of the work

I have used GitHub Copilot in VSCode to make a fast .mp4 slideshow with many photos. The photos were high quality .jpg files with different names and sizes from my wedding day.

Since many picture were similar because shot in close moments, I wanted to grab all of them in a single video to make a short movie like a stop motion vid. I also wanted to make it quickly without expensive or complicate software. After all, I just need to put many pictures in sequence and run them fast, possibly ranked by shot date and time, right?

Not so easy but after several tests I made it. A big thank you to GitHub Copilot, the code was entirely written by it.

How it works

Execute the following scripts (or just copy/paste the lines of codes) sequentially in Windows powershell. Requires:

Italian version

La descrizione in inglese è qui sopra.

Scopo del lavoro

Ho usato GitHub Copilot in VSCode per realizzare una veloce video presentazione .mp4 con molte fotografie. Le foto sono immagini .jpg di alta qualità con nomi e formati differenti scattate al mio matrimonio.

Siccome molte foto sono simili essendo state scattate in momenti ravvicinati, ho voluto metterle tutte insieme in un video per fare un breve filmato tipo stop motion. Volevo anche realizzarlo velocemente senza usare software costosi e complicati. Dopo tutto, devo solo mettere molte foto in sequenza e farle scorrere rapidamente, ordinandole possibilmente per data e ora, giusto?

Non così semplice, ma dopo diverse prove ci sono riuscito. Un grande ringraziamento a GitHub Copilot, il codice è stato interamente scritto da esso.

Come funziona

Eseguire i seguenti script (o copiare e incollare le linee di codice) in sequenza nella console di Windows Poweshell. Requisiti:

# Powershell script to rank many photos to their acquisition date and rename them sequentially.
# Script powershell per ordinare numerose foto in base alla loro data di acquisizione e rinominarle sequenzialmente.
# Written by GitHub Copilot. Requires ExifTool binaries (https://exiftool.org/). Tested on Windows 11.
# Initialize a counter
$counter = 1
# Get all pictures from the current folder and rank them by acquisition date
Get-ChildItem -Filter *.jpg | ForEach-Object {
$exifDate = & exiftool -DateTimeOriginal -d "%Y%m%d_%H%M%S" -s3 $_.FullName
if ($exifDate) {
[PSCustomObject]@{
Path = $_.FullName
Date = [datetime]::ParseExact($exifDate, "yyyyMMdd_HHmmss", $null)
}
}
} | Sort-Object Date | ForEach-Object {
# Create a new name for the picture with a 5-digits sequential counter
$newName = "img" + "{0:D5}" -f $counter + ".jpg"
# Rename the picture
Rename-Item -Path $_.Path -NewName $newName
# Increase the counter
$counter++
}
# Powershell script to convert pictures in pixel format YUV 4:2:0 (useful to make video slideshows).
# Script powershell per convertire immagini nel formato pixel YUV 4:2:0 (utile per video presentazioni).
# Written by GitHub Copilot. Requires ffmpeg binaries to run (https://ffmpeg.org/download.html#build-windows). Tested on Windows 11.
# First run the previous script '01_batchPhotoRankRename.ps1'.
Get-ChildItem -Filter img*.jpg | ForEach-Object {
$newName = "converted_" + $_.Name
ffmpeg -i $_.FullName -pix_fmt yuv420p $newName
}
# Powershell script to make a video slideshow of many pictures with a specific framerate and format. In this example, a framerate of 10 fps and a full HD mp4 video format is set.
# Script powershell per creare una video presentazione di molte immagini con uno specifico framerate e formato. In questo esempio è stato impostato un framerate di 10 immagini al secondo e un formato mp4 in full HD.
# Written by GitHub Copilot. Requires ffmpeg binaries to run (https://ffmpeg.org/download.html#build-windows). Tested on Windows 11.
# First run the previous script '02_ffmpegPicturesYUV420.ps1'.
ffmpeg -framerate 10 -i converted_img%05d.jpg -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:(ow-iw)/2:(oh-ih)/2,format=yuv420p" -c:v libx264 -pix_fmt yuv420p output.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment