[SOLVED] Detecting video rotation of video in mov-container

This forum is about all development around libVLC.
bepaald
New Cone
New Cone
Posts: 2
Joined: 08 Oct 2018 18:45

[SOLVED] Detecting video rotation of video in mov-container

Postby bepaald » 08 Oct 2018 19:13

*EDIT*
This turns out to be a stupid mistake in my own code below. It's actually almost more amazing that it seemed to work correctly for all other files, but that probably has to do with the order of the tracks in the libvlc_media_track array. For completeness, in the below code there is a '(*mediatracks)' that should be changed to 'mediatracks[t]'. Thanks





Hi!

I'm writing a program that deals a lot with video files created with mobile phones. Because of this, a relatively large group of these videos are in portrait orientation. To detect this I use libvlc_media_tracks_get() to get track information and check the i_orientation field of the video track. For most videos this works fine, however with a couple of them, this field is set to 0 (libvlc_video_orient_top_left) even though the video is rotated. All of the files exhibiting this issue were created with iPhones and are in mov containers. Now, if the orientation information is simply not available in the file, that would be unfortunate but not my problem, however playing the file with VLC it is correctly rotated and checking 'Codec information' in VLC, I see 'Orientation: Left bottom'. So, apparently the info is somewhere in the file, I just don't know how to get it.

Here is a simple piece of code that exhibits this behavior:

Code: Select all

#include <iostream> #include <thread> #include <vlc/vlc.h> int main(int argc, char *argv[]) { libvlc_instance_t *vlcinstance = libvlc_new(0, NULL); libvlc_media_t *vlcmedia = libvlc_media_new_path(vlcinstance, argv[1]); libvlc_media_player_t *mediaplayer = libvlc_media_player_new_from_media(vlcmedia); libvlc_media_player_play(mediaplayer); std::this_thread::sleep_for(std::chrono::milliseconds{3000}); libvlc_media_track_t **mediatracks; unsigned trackcount = libvlc_media_tracks_get(vlcmedia, &mediatracks); for (uint t = 0; t < trackcount; ++t) { if (mediatracks[t]->i_type == libvlc_track_video) { libvlc_video_orient_t orient = (*mediatracks)->video->i_orientation; std::cout << " - Orientation: " << orient << std::endl; // for all MOV files I have, this incorrectly prints 0, even though VLC seems to get the orientation right } else if (mediatracks[t]->i_type == libvlc_track_audio) std::cout << "Audio track" << std::endl; else std::cout << "OTHER TRACK" << std::endl; } libvlc_media_tracks_release(mediatracks, trackcount);https://www.google.com/search?q=difference+between+mov+and+mp4+containers&ie=utf-8&oe=utf-8&client=firefox-b libvlc_media_player_stop(mediaplayer); libvlc_media_player_release(mediaplayer); libvlc_media_release(vlcmedia); libvlc_release(vlcinstance); return 0; }
Am I doing something stupid here? Or is there another way to get the correct orientation from MOV files?

thanks!
Last edited by bepaald on 09 Oct 2018 08:53, edited 1 time in total.

User avatar
InTheWings
Developer
Developer
Posts: 1275
Joined: 07 Aug 2013 13:15
VLC version: crashing
Operating System: Linux
Contact:

Re: Detecting video rotation of video in mov-container

Postby InTheWings » 08 Oct 2018 19:18

If there's no orientation info, then we can't do anything.
How can you prove there's info on those files ?
:!: If you want your problem to be solved :
* First read troubleshooting guide VSG:Main
* Always provide verbose LOGS ! (command line or from gui)
* Always check your issue against a developer build from Nightly Build of VLC
* Tell us when your problem is solved !

bepaald
New Cone
New Cone
Posts: 2
Joined: 08 Oct 2018 18:45

Re: Detecting video rotation of video in mov-container

Postby bepaald » 08 Oct 2018 20:36

If there's no orientation info, then we can't do anything.
How can you prove there's info on those files ?
As I said, VLC correctly rotates the problematic videos. Also, viewing 'codec information' in VLC has correct orientation value filled in:
Image

Lastly, running the file through ffmpeg shows:

Code: Select all

[~/vidtest/test3] $ ffprobe -i IMG_0656.MOV ffprobe version n4.0.2 Copyright (c) 2007-2018 the FFmpeg developers built with gcc 8.2.0 (GCC) configuration: --prefix=/usr --disable-debug --disable-static --disable-stripping --enable-fontconfig --enable-gmp --enable-gnutls --enable-gpl --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libdrm --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libiec61883 --enable-libjack --enable-libmodplug --enable-libmp3lame --enable-libopencore_amrnb --enable-libopencore_amrwb --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libv4l2 --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxcb --enable-libxml2 --enable-libxvid --enable-nvdec --enable-nvenc --enable-omx --enable-shared --enable-version3 libavutil 56. 14.100 / 56. 14.100 libavcodec 58. 18.100 / 58. 18.100 libavformat 58. 12.100 / 58. 12.100 libavdevice 58. 3.100 / 58. 3.100 libavfilter 7. 16.100 / 7. 16.100 libswscale 5. 1.100 / 5. 1.100 libswresample 3. 1.100 / 3. 1.100 libpostproc 55. 1.100 / 55. 1.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'IMG_0656.MOV': Metadata: major_brand : mp42 minor_version : 1 compatible_brands: mp41mp42isom creation_time : 2017-08-07T10:11:11.000000Z location : +52.9610+005.7234-0.054993/ Duration: 00:04:24.36, start: 0.000000, bitrate: 765 kb/s Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default) Metadata: creation_time : 2017-08-07T10:11:11.000000Z handler_name : Core Media Audio Stream #0:1(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 568x320, 698 kb/s, 29.98 fps, 29.97 tbr, 600 tbn, 1200 tbc (default) Metadata: rotate : 90 creation_time : 2017-08-07T10:11:11.000000Z handler_name : Core Media Video Side data: displaymatrix: rotation of -90.00 degrees
Note both the 'rotate' in the metadata and the 'displaymatrix' in side data. I take all these things as an indication the orientation info is in the file somewhere, but I do not know how to get it. Please inform me if I'm mistaken in this assumption.

Thanks!

User avatar
InTheWings
Developer
Developer
Posts: 1275
Joined: 07 Aug 2013 13:15
VLC version: crashing
Operating System: Linux
Contact:

Re: [SOLVED] Detecting video rotation of video in mov-container

Postby InTheWings » 09 Oct 2018 09:44

provide sample then
:!: If you want your problem to be solved :
* First read troubleshooting guide VSG:Main
* Always provide verbose LOGS ! (command line or from gui)
* Always check your issue against a developer build from Nightly Build of VLC
* Tell us when your problem is solved !


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 28 guests