Skip to content

Instantly share code, notes, and snippets.

@sakydev
Last active September 3, 2021 09:32
Show Gist options
  • Save sakydev/d9a68e688849b4443d1e6abc33e50f04 to your computer and use it in GitHub Desktop.
Save sakydev/d9a68e688849b4443d1e6abc33e50f04 to your computer and use it in GitHub Desktop.
php+ffmpeg: convert high size smartphone videos with minimal quality loss
<?php
// My smartphone Note 8 outputs really heavy size videos. So I wrote this script
// to automatically convert videos in given directory
$inputDir = 'directory_with_all_videos';
$outputDir = 'directory_to_save_converted_videos_to';
$files = glob($inputDir);
$count = count($files);
foreach ($files as $key => $file) {
$done = $key + 1;
$filebase = basename($file);
$cmd = "C:\ffmpeg.exe -i " . __DIR__ . "/{$file} {outputDir}/{$filebase}";
shell_exec($cmd);
echo "Done {$done} / {$count}\n";
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment