Hi. I am using ffmpeg to encode videos both uploaded from the web and from iPhones. Currently, we are rotating the iPhone videos with another script. This has worked great so far however we just launched a mobile version of our site and now videos that have been rotated 90 degrees won?t play on the iPhone. The videos that are rotated 270 degrees work fine. I am wondering if there is a way to encode the file with ffmpeg so that it keeps the rotation matrix information from the iPhone so that if I try to play it again on the iPhone it works? Thanks *Ben*
On Tue, Jun 1, 2010 at 5:51 PM, Ben Knight <ben.knight at f-i.com> wrote:
Hi. I am using ffmpeg to encode videos both uploaded from the web and from iPhones. Currently, we are rotating the iPhone videos with another script. This has worked great so far however we just launched a mobile version of our site and now videos that have been rotated 90 degrees won?t play on the iPhone. The videos that are rotated 270 degrees work fine.
I am wondering if there is a way to encode the file with ffmpeg so that it keeps the rotation matrix information from the iPhone so that if I try to play it again on the iPhone it works?
There is some missing information here. iPhone video "rotations" are simply specified as metadata in the file. But there are plenty (most?) encoding formats that don't support this metadata, so it's important to know what format you're encoding TO. But even knowing this information, my experience is that in most cases, ffmpeg simply ignores the rotation matrix written by iPhone 3GS phones. The relevant code is in libavformat/mov.c, routine mov_read_tkhd(). In order to fix the problem for my project, I had to hack mov.c to persist the rotation angle instead MOVStreamContext, and then use a custom avfilter (based almost entirely on vf_rotate) which looked for this rotation angle, and then rotated the pixel buffer if it found it (no-op if it didn't find any rotation angle). Norbert
Hi. I am using ffmpeg to encode videos both uploaded from the web and from iPhones. Currently, we are rotating the iPhone videos with another
This has worked great so far however we just launched a mobile version of our site and now videos that have been rotated 90 degrees won't play on
Hey Norbert, Thanks for the reply. We are currently encoding the files into mp4 format. Even if the information is ignored by ffmpeg, is there a way to add it into the encoded file? That way if the new encoded video is played on an iphone, it can read the rotation information from the metadata? Thanks, Ben -----Original Message----- From: ffmpeg-user-bounces at mplayerhq.hu [mailto:ffmpeg-user-bounces at mplayerhq.hu] On Behalf Of Norbert Burger Sent: Tuesday, June 01, 2010 6:28 PM To: FFmpeg user questions and RTFMs Subject: Re: [FFmpeg-user] iPhone Matrix Rotation Info On Tue, Jun 1, 2010 at 5:51 PM, Ben Knight <ben.knight at f-i.com> wrote: script. the
iPhone. The videos that are rotated 270 degrees work fine.
I am wondering if there is a way to encode the file with ffmpeg so that it keeps the rotation matrix information from the iPhone so that if I try to play it again on the iPhone it works?
There is some missing information here. iPhone video "rotations" are simply specified as metadata in the file. But there are plenty (most?) encoding formats that don't support this metadata, so it's important to know what format you're encoding TO. But even knowing this information, my experience is that in most cases, ffmpeg simply ignores the rotation matrix written by iPhone 3GS phones. The relevant code is in libavformat/mov.c, routine mov_read_tkhd(). In order to fix the problem for my project, I had to hack mov.c to persist the rotation angle instead MOVStreamContext, and then use a custom avfilter (based almost entirely on vf_rotate) which looked for this rotation angle, and then rotated the pixel buffer if it found it (no-op if it didn't find any rotation angle). Norbert _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
You would be better off simply detecting, rotating (with mencoder), and then encoding. That's what we do on several encoding systems. On Wed, Jun 2, 2010 at 11:47 AM, Ben Knight <ben.knight at f-i.com> wrote:
Hey Norbert,
Thanks for the reply. We are currently encoding the files into mp4 format.
Even if the information is ignored by ffmpeg, is there a way to add it into the encoded file? That way if the new encoded video is played on an iphone, it can read the rotation information from the metadata?
Thanks, Ben
-----Original Message----- From: ffmpeg-user-bounces at mplayerhq.hu [mailto:ffmpeg-user-bounces at mplayerhq.hu] On Behalf Of Norbert Burger Sent: Tuesday, June 01, 2010 6:28 PM To: FFmpeg user questions and RTFMs Subject: Re: [FFmpeg-user] iPhone Matrix Rotation Info
On Tue, Jun 1, 2010 at 5:51 PM, Ben Knight <ben.knight at f-i.com> wrote:
Hi. I am using ffmpeg to encode videos both uploaded from the web and from iPhones. Currently, we are rotating the iPhone videos with another script. This has worked great so far however we just launched a mobile version of our site and now videos that have been rotated 90 degrees won't play on the iPhone. The videos that are rotated 270 degrees work fine.
I am wondering if there is a way to encode the file with ffmpeg so that it keeps the rotation matrix information from the iPhone so that if I try to play it again on the iPhone it works?
There is some missing information here. iPhone video "rotations" are simply specified as metadata in the file. But there are plenty (most?) encoding formats that don't support this metadata, so it's important to know what format you're encoding TO.
But even knowing this information, my experience is that in most cases, ffmpeg simply ignores the rotation matrix written by iPhone 3GS phones. The relevant code is in libavformat/mov.c, routine mov_read_tkhd().
In order to fix the problem for my project, I had to hack mov.c to persist the rotation angle instead MOVStreamContext, and then use a custom avfilter (based almost entirely on vf_rotate) which looked for this rotation angle, and then rotated the pixel buffer if it found it (no-op if it didn't find any rotation angle).
Norbert _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
On Wed, Jun 2, 2010 at 1:55 PM, David Overcash <funnylookinhat at gmail.com>wrote:
You would be better off simply detecting, rotating (with mencoder), and then encoding. That's what we do on several encoding systems.
Agreed. Ben - rather than trying to persist the metadata, I think the better approach is to rotate the video -- if needed -- as part of the transcoding step (again, this is what I'm doing). This method guarantees that your video is oriented correctly, regardless of output format or player. Luckily, it can be done all within ffmpeg. Norbert
Hey guys, Thanks again for all the good info. We are currently rotating the video so that is not really the problem. The problem I am having is that when we try to view an encoded video on the iphone, if it has been rotated 90 degrees, the iphone gives an error message that the video cannot be played. Any other rotated or non rotated video works fine. My thought was maybe if the metadata could persist through the encoding maybe the iphone would read that for its rotation. Thanks Ben -----Original Message----- From: ffmpeg-user-bounces at mplayerhq.hu [mailto:ffmpeg-user-bounces at mplayerhq.hu] On Behalf Of Norbert Burger Sent: Wednesday, June 02, 2010 3:02 PM To: FFmpeg user questions and RTFMs Subject: Re: [FFmpeg-user] iPhone Matrix Rotation Info On Wed, Jun 2, 2010 at 1:55 PM, David Overcash <funnylookinhat at gmail.com>wrote:
You would be better off simply detecting, rotating (with mencoder), and then encoding. That's what we do on several encoding systems.
Agreed. Ben - rather than trying to persist the metadata, I think the better approach is to rotate the video -- if needed -- as part of the transcoding step (again, this is what I'm doing). This method guarantees that your video is oriented correctly, regardless of output format or player. Luckily, it can be done all within ffmpeg. Norbert _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
On Wed, Jun 2, 2010 at 3:13 PM, Ben Knight <ben.knight at f-i.com> wrote:
Hey guys,
Thanks again for all the good info.
We are currently rotating the video so that is not really the problem. The problem I am having is that when we try to view an encoded video on the iphone, if it has been rotated 90 degrees, the iphone gives an error message that the video cannot be played. Any other rotated or non rotated video works fine.
What are you using to rotate the video? In an earlier email, you mentioned "another script", but it wasn't clear which tool. My first thought is that this tool is changing the metadata in a non-standard way. Norbert
Hey Norbert, Upon another look, it looks like you are correct. We are using a python script call qtrotate.py (http://github.com/danielgtaylor/qtrotate/blob/master/qtrotate.py). At the top of the script in the comments, it states that the translation info will be lost. This is not commented in the script we currently have in our system. This was a system that I inherited and the person who implemented it is no longer here so I am not only learning about ffmpeg now but also about the rotation. Thanks again for all the help! Ben -----Original Message----- From: ffmpeg-user-bounces at mplayerhq.hu [mailto:ffmpeg-user-bounces at mplayerhq.hu] On Behalf Of Norbert Burger Sent: Wednesday, June 02, 2010 3:21 PM To: FFmpeg user questions and RTFMs Subject: Re: [FFmpeg-user] iPhone Matrix Rotation Info On Wed, Jun 2, 2010 at 3:13 PM, Ben Knight <ben.knight at f-i.com> wrote:
Hey guys,
Thanks again for all the good info.
We are currently rotating the video so that is not really the problem. The problem I am having is that when we try to view an encoded video on the iphone, if it has been rotated 90 degrees, the iphone gives an error message that the video cannot be played. Any other rotated or non rotated video works fine.
What are you using to rotate the video? In an earlier email, you mentioned "another script", but it wasn't clear which tool. My first thought is that this tool is changing the metadata in a non-standard way. Norbert _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
On Wed, Jun 2, 2010 at 3:56 PM, Ben Knight <ben.knight at f-i.com> wrote:
Hey Norbert,
Upon another look, it looks like you are correct. We are using a python script call qtrotate.py (http://github.com/danielgtaylor/qtrotate/blob/master/qtrotate.py). At the top of the script in the comments, it states that the translation info will be lost. This is not commented in the script we currently have in our system.
I think you're mixing translation and rotation. The author's comment seems to imply that translation (not rotation) info will be lost if a new rotation angle is written. Both transformations can be combined together in a single 3x3 matrix, as in line 157 of your script: value = struct.pack(">9l", cos_deg, sin_deg, 0, -sin_deg, cos_deg, 0, 0, 0, (1<<30)) Norbert
How does one detect the video orientation? I am running FFmpeg from a php sript.
On date Wednesday 2010-06-02 13:47:13 -0400, Ben Knight encoded:
Hey Norbert,
Thanks for the reply. We are currently encoding the files into mp4 format.
Even if the information is ignored by ffmpeg, is there a way to add it into the encoded file? That way if the new encoded video is played on an iphone, it can read the rotation information from the metadata?
FFmpeg supports metadata settings, the problem is understand if FFmpeg is currently supporting *that* kind of metadata (and if it is supported by the output format). A starting point would be to point to a sample which contains that metadata, and provide evidence that it is indeed ignored by FFmpeg. At that point you may file a feature request/send patches/pay/beg someone to implement that. Regards.
Hi Norbert, Can you provide some sample code for this fix. As i tried the patch given by dave (see below) but doesn't work. I am using 0.8.4 version libraries of FFMPEG. In IPhone portrait video rotate to 90 degree after FFMPEG encoding. Need help. //av_dict_set(&st->metadata, "rotate", "180", 0); av_metadata_set2(&st->metadata, "rotate", "180", 0);
participants (6)
-
andrew@vermillion.ca -
ben.knight@f-i.com -
funnylookinhat@gmail.com -
Gagan -
norbert.burger@gmail.com -
stefano.sabatini-lala@poste.it