Last active
September 3, 2021 09:32
-
-
Save sakydev/bca90fb6b8d1b9f6a633f52d63ced5ea to your computer and use it in GitHub Desktop.
php+ffmpeg: rotate all videos in a directory by specified degrees
This file contains 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
<?php | |
// Requires FFMPEG to be installed and globally available | |
// Been using this to rotate videos shot on a phone with dead sensors | |
if (!$argv['1']) { exit("php rotate_360.php input_dir output_dir degress_to_rot"); } | |
$input_dir = $argv['1']; | |
$output_dir = $argv['2']; | |
if (!file_exists($output_dir)) { @mkdir($output_dir); } | |
$degress = !empty($argv['3']) ? $argv['3'] : 360; | |
$files = glob("{$input_dir}/*.mp4"); | |
foreach ($files as $key => $file) { | |
$filename = pathinfo($file, PATHINFO_FILENAME); // outputs nameonly | |
$command = "ffmpeg -i {$input_dir}/{$filename}.mp4 -c copy -metadata:s:v:0 rotate={$degress} {$output_dir}/{$filename}-out.mp4"; | |
echo $command . "\n"; | |
shell_exec($command); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment