2

Once I upload videos to my server I'm creating a screencap using FFMPEG. Problem is, if the user takes a video in portrait mode the screencap is rotated 90º. The ridiculous things is that PhoneGap and FFMEG-php and FFMPEG don't seem to offer a mechanism for reading the video rotation/orientation value.

I found another library called mediainfo that will provide the info, but not in an easy to read/digest manner and I'm trying to avoid having to use another library.

Am I wrong about PhoneGap/FFMPEG? Is there a direct way to determine video orienation?


Here's my solution as a PHP function:

function get_video_orientation($video_path) {
    $cmd = FFMPEG_PATH . "ffprobe " . $video_path . " -show_streams 2>/dev/null";
    $result = shell_exec($cmd);

    $orientation = 0;
    if(strpos($result, 'TAG:rotate') !== FALSE) {
        $result = explode("\n", $result);
        foreach($result as $line) {
            if(strpos($line, 'TAG:rotate') !== FALSE) {
                $stream_info = explode("=", $line);
                $orientation = $stream_info[1];
            }
        }
    }

    return $orientation;
}
SomethingOn
  • 9,813
  • 17
  • 68
  • 107
  • is this related? http://stackoverflow.com/questions/2208522/ffmpeg-on-iphone-modifying-video-orientation – Anthony Hatzopoulos Oct 26 '12 at 19:45
  • In a way, but I know that I can rotate the video using FFMPEG, but the problem is I don't know IF I need to rotate because I don't know what the orientation of the video is in the first place :s – SomethingOn Oct 26 '12 at 19:52
  • what about this http://stackoverflow.com/a/11236144/881551 and `ffmpeg -i video.mpg` – Anthony Hatzopoulos Oct 26 '12 at 20:00
  • I looked at that one...ffprobe doesn't seem to give me the orientation/rotation value. I am using ffmpeg 0.6.5. Had trouble getting 1.0 installed on CentOS – SomethingOn Oct 26 '12 at 20:32
  • 1
    See [Compile FFmpeg on CentOS](http://ffmpeg.org/trac/ffmpeg/wiki/CentosCompilationGuide) for instructions. – llogan Oct 27 '12 at 05:09
  • Looks like everything compiled successfully; thanks for the CentOS instructions...now how do I run it/add it to my PATH variable. Where did everything get install to? – SomethingOn Oct 29 '12 at 13:47
  • I took the build from source approach in order to use FFMPEG 0.9 – SomethingOn Mar 12 '13 at 14:31

1 Answers1

-1

Use MediaCodec to find the rotation value. Then rotate the video using FFMPEG.

Eg: ffmpeg -i in.avi -vf "transpose=1" out.avi

this will flips the video 90 degrees clockwise.