문제

A video can contain a meta info about the camera orientation. For example iPhone and other phones set this flag if you turn the device. Problem is while some player read this info and rotate the video accordingly, other players do not.

To fix this the video has to be rotated and the meta info needs to be set correctly.

Does ffmpeg provide a fix for this or do I have to go the hard way (Read rotation, rotate, set meta data)

도움이 되었습니까?

해결책

I did go the hard way:

$ffmpeg == "path/to/ffmpeg";
$output_file_full = "file/after/normal/conversion";

// get rotation of the video
ob_start();
passthru($ffmpeg . " -i " . $output_file_full . " 2>&1");
$duration_output = ob_get_contents();
ob_end_clean();

// rotate?
if (preg_match('/rotate *: (.*?)\n/', $duration_output, $matches))
{
    $rotation = $matches[1];
    if ($rotation == "90")
    {
        echo shell_exec($ffmpeg . ' -i ' . $output_file_full . ' -metadata:s:v:0 rotate=0 -vf "transpose=1" ' . $output_file_full . ".rot.mp4 2>&1") . "\n";
        echo shell_exec("mv $output_file_full.rot.mp4 $output_file_full") . "\n";
    }
    else if ($rotation == "180")
    {
        echo shell_exec($ffmpeg . ' -i ' . $output_file_full . ' -metadata:s:v:0 rotate=0 -vf "transpose=1,transpose=1" ' . $output_file_full . ".rot.mp4 2>&1") . "\n";
        echo shell_exec("mv $output_file_full.rot.mp4 $output_file_full") . "\n";
    }
    else if ($rotation == "270")
    {
        echo shell_exec($ffmpeg . ' -i ' . $output_file_full . ' -metadata:s:v:0 rotate=0 -vf "transpose=2" ' . $output_file_full . ".rot.mp4 2>&1") . "\n";
        echo shell_exec("mv $output_file_full.rot.mp4 $output_file_full") . "\n";
    }
}

I used some ugly temp files. Sorry about that.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top