Skip to content

Instantly share code, notes, and snippets.

@Sharuru
Created July 11, 2020 08:16
Show Gist options
  • Save Sharuru/20b908afe03eba516c6bd47642583101 to your computer and use it in GitHub Desktop.
Save Sharuru/20b908afe03eba516c6bd47642583101 to your computer and use it in GitHub Desktop.
Concatenate MIJIA camera recordings and making a motion video as well
# This script should work with Powershell 7.
# It will take about 25 minutes to finish the whole job.
# You should place the ffmpeg.exe under the same folder.
# Also, create a folder named as 'image' is required.
if (!(Test-Path "ffmpeg.exe")) {
Write-Output "ffmpeg.exe is NOT FOUND, exiting..."
throw "ffmpeg.exe is not found in the current working directory."
}
if (Test-Path "output.mp4")
{
Remove-Item "output.mp4"
Write-Output "Working file: output.mp4 is REMOVED."
}
$workingFileName = "target.txt"
if (Test-Path $workingFileName)
{
Remove-Item $workingFileName
Write-Output "Working file: target.txt is REMOVED."
}
Write-Output "Generating file list..."
Get-ChildItem -recurse -Filter *.mp4 | Sort-Object LastWriteTime|
Foreach-Object {
$fullName = $_.FullName
Write-Output "WRITE: $fullName -> $workingFileName"
"file $fullName".Replace("\", "\\") | Out-File -Encoding utf8NoBOM -Append $workingFileName
}
Write-Output "Concating video files..."
.\ffmpeg.exe -f concat -safe 0 -i target.txt -c copy -an output_full.mp4
# WIP: should faster.
Write-Output "Taking screenshots...this may take some time"
Remove-Item image\frame*.jpg
.\ffmpeg -i output_full.mp4 -vf fps=1/48 image\frame%04d.jpg
Write-Output "Making motion videos..."
.\ffmpeg -framerate 60 -i image\frame%04d.jpg -r 60 -y output_motion.mp4
Write-Output "Job finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment