Bug 361829

Summary: Rotated MP4 video with "Orientation" flag are not played back in the correct rotation angle
Product: [Applications] digikam Reporter: Jens <jens-bugs.kde.org>
Component: Preview-VideoAssignee: Digikam Developers <digikam-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: aegoreev, bg+kdex, caulier.gilles, dvb, metzpinguin
Priority: NOR    
Version: 5.4.0   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed In: 6.0.0
Sentry Crash Report:

Description Jens 2016-04-15 18:03:11 UTC
I have a lot of videos shot on iPhones or iPads in portrait mode. These are MOV (or MP4) files which have an "Orientation" metadata flag set. In iPhoto they are displayed correctly rotated, but in Digikam 4.14 they are not. (I can't test Digikam 5 because even on my Virtualbox Kubuntu 15.10, Digikam 5beta5 packages by philip5 flatly refuse to preview or show videos at all right now.)

I would wish for Digikam's player (phonon, gstreamer, ...) to correctly respect the "Orientation" flag in MOV and MP4 files (I don't know about other video formats) and to display the videos correctly.
If required, please reassign this bug to the correct project if Digikam itself cannot do anything about this.

Thank you!

Reproducible: Always
Comment 1 caulier.gilles 2016-04-16 09:14:30 UTC
The new digiKam 5 will be based on Qt5Multimedia framework (not Phonon), which use GStreamer backend.

1/ I don't yet checked if Qt5Multimedia handle orientation tag to rotate video accordingly.
2/ digiKam delegate video preview to Qt5Multimedia. We pass the file url to the framework and that all. So, we have nothing to do in digiKam to fix this problem.

Gilles Caulier
Comment 2 Jens 2016-04-16 11:32:36 UTC
Thank you! How can I check whether it already works in 5.0beta5, what packages do I need to install for video playback and thumbs to work?
Comment 3 caulier.gilles 2016-04-16 11:45:21 UTC
Typically Gstreamer backend whole packages under Linux:

http://wiki.qt.io/Qt_5.5.0_Multimedia_Backends

For the video thumbnails, Qt5Multimedia cannot do it for the moment. It still delegate to KDE5 imageio plugins

Gilles Caulier
Comment 4 Unknown 2016-12-11 12:09:04 UTC
Git commit 32ebb7dff83b03cfad91cbe89de252b1f62bdd6e by Gilles Caulier.
Committed on 11/12/2016 at 12:02.
Pushed by cgilles into branch 'master'.

digiKam embeded mediaplayer is now based on QtAV/ffmpeg instead Qt5Multimedia.

TODO:

- handle video rotation flag with new Exiv2 0.26 to autorotate media in player.
- port video thumbnailer to QtAV.
- port Presentation audio player to QtAV.
- remove Qt5Multimedia dependency.

For later:

- play video into slideshow tool.
- port old videoslideshow tool to QtAv
Related: bug 373272, bug 372485, bug 271751, bug 159824, bug 329854

M  +12   -6    CMakeLists.txt
M  +3    -2    app/CMakeLists.txt
M  +40   -38   app/views/mediaplayerview.cpp
M  +11   -8    app/views/mediaplayerview.h

https://commits.kde.org/digikam/32ebb7dff83b03cfad91cbe89de252b1f62bdd6e
Comment 5 Unknown 2016-12-11 16:40:12 UTC
Git commit ec50a8ad510e9fe6ded53f0632afd4ffbdf8ba47 by Gilles Caulier.
Committed on 11/12/2016 at 16:37.
Pushed by cgilles into branch 'master'.

digiKam port to QtAV/ffmpeg instead Qt5Multimedia : port Presentation audio player to QtAV.

TODO:

- handle video rotation flag with new Exiv2 0.26 to autorotate media in player.
- port video thumbnailer to QtAV.
- remove Qt5Multimedia dependency.

For later:

- play video into slideshow tool.
- port old videoslideshow tool to QtAv.
Related: bug 372485, bug 271751, bug 159824, bug 329854

M  +4    -5    app/CMakeLists.txt
M  +1    -1    app/views/mediaplayerview.cpp
M  +2    -2    app/views/mediaplayerview.h
M  +1    -5    utilities/presentation/CMakeLists.txt
M  +34   -24   utilities/presentation/audio/presentationaudiolist.cpp
M  +8    -5    utilities/presentation/audio/presentationaudiolist.h
M  +45   -27   utilities/presentation/audio/presentationaudiowidget.cpp
M  +9    -5    utilities/presentation/audio/presentationaudiowidget.h

https://commits.kde.org/digikam/ec50a8ad510e9fe6ded53f0632afd4ffbdf8ba47
Comment 6 Unknown 2016-12-11 21:11:36 UTC
Git commit 193ecfd91745aab81c15ccf1a3889dc033ee7917 by Gilles Caulier.
Committed on 11/12/2016 at 21:09.
Pushed by cgilles into branch 'master'.

digiKam port to QtAV/ffmpeg instead Qt5Multimedia : add video support into Slideshow.

TODO:

- handle video rotation flag with new Exiv2 0.26 to autorotate media in player.
- port video thumbnailer to QtAV.
- remove Qt5Multimedia dependency.

For later:

- port old videoslideshow tool to QtAv.
Related: bug 159824, bug 372485, bug 271751, bug 329854
FIXED-IN: 5.4.0

M  +8    -6    NEWS
M  +3    -3    app/views/mediaplayerview.cpp
M  +1    -1    app/views/mediaplayerview.h
M  +1    -0    utilities/slideshow/CMakeLists.txt
M  +68   -5    utilities/slideshow/slideshow.cpp
M  +3    -0    utilities/slideshow/slideshow.h
A  +227  -0    utilities/slideshow/slidevideo.cpp     [License: GPL (v2+)]
C  +16   -51   utilities/slideshow/slidevideo.h [from: app/views/mediaplayerview.h - 050% similarity]

https://commits.kde.org/digikam/193ecfd91745aab81c15ccf1a3889dc033ee7917
Comment 7 caulier.gilles 2016-12-22 17:18:03 UTC
I need to have a fresh feedback here using last digiKam bundle build with QtAV to handle video files. See this GDrive repository to upload a 5.4.0 pre-version :

https://drive.google.com/drive/folders/0BzeiVr-byqt5Y0tIRWVWelRJenM

Thanks in advance

Gilles Caulier
Comment 8 Maik Qualmann 2016-12-24 15:20:43 UTC
Git commit 7ce05cef9ce1260aa75cdfa909be57e7aaa49fc5 by Maik Qualmann.
Committed on 23/12/2016 at 21:14.
Pushed by mqualmann into branch 'master'.

add manual rotating the video output with the right mouse button

M  +39   -6    app/views/mediaplayerview.cpp
M  +1    -0    app/views/mediaplayerview.h

https://commits.kde.org/digikam/7ce05cef9ce1260aa75cdfa909be57e7aaa49fc5
Comment 9 Bill Goodman 2017-01-09 00:38:39 UTC
(In reply to caulier.gilles from comment #7)
> I need to have a fresh feedback here using last digiKam bundle build with
> QtAV to handle video files. See this GDrive repository to upload a 5.4.0
> pre-version :
> 
> https://drive.google.com/drive/folders/0BzeiVr-byqt5Y0tIRWVWelRJenM

I just noticed this same problem with rotated videos in 5.4.0 on both Win7 and Win10. My video has an EXIF:Rotation=180.

The video displays properly with VLC on Windows but it displays upside down with Windows Media Player.
Comment 10 Bill Goodman 2017-01-09 01:18:18 UTC
I installed QtAV1.11.0-VS2013x86.exe on both Win7 and Win10 and see the same rotation problem when playing my video on the QtAV.Player.
Comment 11 caulier.gilles 2017-01-09 19:12:27 UTC
Bill,

> I just noticed this same problem with rotated videos in 5.4.0 on both Win7 and > Win10. My video has an EXIF:Rotation=180.

Your video has Exif rotation flag set by your camera. Interesting... Please share this file through a cloud web service.. I would to check if Exiv2 0.26 is able to decode this information. If not, i will recommend to post an UPSTREAM Exiv2 bug for the next 0.27 release.

It will be a good idea to report this to QtAV bugzilla. The player based on ffmpeg, that DK use, must be able to auto-rotate the media automatically.

Gilles Caulier
Comment 12 Bill Goodman 2017-01-09 23:01:41 UTC
(In reply to caulier.gilles from comment #11)
> Your video has Exif rotation flag set by your camera. Interesting... Please
> share this file through a cloud web service.. I would to check if Exiv2 0.26
> is able to decode this information. If not, i will recommend to post an
> UPSTREAM Exiv2 bug for the next 0.27 release.

The video is available here:
https://www.dropbox.com/s/5w8guqu9kjwjlx3/VID_20161224_201626.mp4?dl=0
Comment 13 Andrius 2017-01-31 03:21:04 UTC
Confirmed on digiKam 5.4.0 on linux Mint 18.1 KDE
Comment 14 Dietrich 2017-08-02 11:13:39 UTC
Bug confirmed for digikam 5.6.0 on windows 7 / 64 bit.
The Rotation flag I set using Exiftool does not seem to be respected by digikam.

Is this the same issue as https://bugs.kde.org/show_bug.cgi?id=375197 ?

Dietrich
Comment 15 Andrius 2018-01-08 15:06:22 UTC
Confirmed on 5.8.0 pre-release bundle on openSUSE TW KDE.
QtAV still ignores the rotation flag.

Here an extract from ffmpeg output for a sample file:
"
Metadata:                                                                               
      rotate          : 90                                                                  
      creation_time   : 2017-11-26T00:45:53.000000Z                                         
      handler_name    : VideoHandle                                                         
    Side data:                                                                              
      displaymatrix: rotation of -90.00 degrees"
I think usually videoplayers use that displaymatrix value to display a video correctly. Basically it tells you to rotate the image 90 degrees back (-90)

I tried to find some info on how to call ffmpeg within c++ on found these:
(not sure if they are helpful though)
 
https://stackoverflow.com/questions/35751441/ffmpeg-c-apis-to-detect-if-a-video-is-rotated-shot-on-phone

https://ffmpeg.org/doxygen/trunk/index.html

https://www.codeproject.com/Tips/111468/FFmpeg-Tutorial

https://trac.ffmpeg.org/wiki/Including%20FFmpeg%20headers%20in%20a%20C%2B%2B%20application
Comment 16 Andrius 2018-01-08 15:13:19 UTC
Looking at https://github.com/wang-bin/QtAV/blob/master/widgets/GraphicsItemRenderer.cpp (search page for "rotat") it seems that QtAV checks the rotation flag...
Comment 17 Andrius 2018-01-08 15:15:34 UTC
Looks like this module does the transformation:

https://ffmpeg.org/doxygen/trunk/group__lavu__video__display.html
Comment 18 Maik Qualmann 2018-01-08 17:36:20 UTC
(In reply to Andrius from comment #16)
> Looking at
> https://github.com/wang-bin/QtAV/blob/master/widgets/GraphicsItemRenderer.
> cpp (search page for "rotat") it seems that QtAV checks the rotation flag...

This is the normal rotation feature that QtAV provides and that we also use to rotate the video with the right mouse button.

Maik
Comment 19 Andrius 2018-01-09 14:30:19 UTC
(In reply to Maik Qualmann from comment #18)
> (In reply to Andrius from comment #16)
> > Looking at
> > https://github.com/wang-bin/QtAV/blob/master/widgets/GraphicsItemRenderer.
> > cpp (search page for "rotat") it seems that QtAV checks the rotation flag...
> 
> This is the normal rotation feature that QtAV provides and that we also use
> to rotate the video with the right mouse button.
> 
> Maik

I wish there was a way to save the set orientation for video and its thumbnail though...
Comment 20 caulier.gilles 2018-01-09 14:33:03 UTC
Well the oritnation flag for item (image for exemple) exists in database, but only for the thumbnails.

Gilles Caulier
Comment 21 Andrius 2018-01-09 14:39:02 UTC
(In reply to caulier.gilles from comment #20)
> Well the oritnation flag for item (image for exemple) exists in database,
> but only for the thumbnails.
> 
> Gilles Caulier

It feels like digiKam always regenerates thumbnails for video files so I don't think there is a point in rotating them
Comment 22 Maik Qualmann 2018-02-27 20:16:04 UTC
Git commit 194c046adf1ce05cb051740498f9d7e680cdbc28 by Maik Qualmann.
Committed on 27/02/2018 at 20:13.
Pushed by mqualmann into branch 'development/6.0.0'.

play videos with the correct orientation, if available
FIXED-IN: 6.0.0

M  +25   -2    utilities/assistants/videoslideshow/player/mediaplayerview.cpp

https://commits.kde.org/digikam/194c046adf1ce05cb051740498f9d7e680cdbc28
Comment 23 Bill Goodman 2019-03-09 22:09:47 UTC
This is marked as FIXED but it is still broken for me.

I tested with digiKam-6.1.0-git-20190308T103035-Win64.exe on Windows 7.

Same video provided previously. That video plays correctly in VLC.
Comment 24 Maik Qualmann 2019-03-09 22:14:17 UTC
Video tested here. Thumbnail and play with correct orientation. Reload the metadata from this image.

Maik
Comment 25 Bill Goodman 2019-03-09 22:22:53 UTC
I'm sorry, Maik. You are correct. It plays correctly after refreshing the metadata.

This is great. Thanks!