OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

iOS/OSX: avfoundation plugin not reporting correct media duration


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Plugins [osgPlugins]
View previous topic :: View next topic  
Author Message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Fri Jan 19, 2018 8:50 am    Post subject:
iOS/OSX: avfoundation plugin not reporting correct media duration
Reply with quote

Hi,
I found out that when you want to know the duration of a media file, specifically a movie, the instruction:

Code:
_videoDuration = CMTimeGetSeconds([_data->avplayer.currentItem duration]);


returns 0, I tried to use the following instead:

Code:
_videoDuration = CMTimeGetSeconds([[_data->avplayer.currentItem asset] duration]);


that seems to return the correct movie's duration in seconds.

If you agree I will send a pull request about this fix.

Cheers,
Alessandro
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 12148

PostPosted: Fri Jan 19, 2018 9:08 am    Post subject:
iOS/OSX: avfoundation plugin not reporting correct media duration
Reply with quote

HI Alessandro,

Has AVFoundation changed? Or do you think that the original code was
likely wrong all along?

If there is chance that different versions work slightly different
then making your suggested change could break older versions so we
might need to put some version handling around it.

Robert.

On 19 January 2018 at 08:50, Alessandro Terenzi <> wrote:
Quote:
Hi,
I found out that when you want to know the duration of a media file, specifically a movie, the instruction:


Code:
_videoDuration = CMTimeGetSeconds([_data->avplayer.currentItem duration]);



returns 0, I tried to use the following instead:


Code:
_videoDuration = CMTimeGetSeconds([[_data->avplayer.currentItem asset] duration]);



that seems to return the correct movie's duration in seconds.

If you agree I will send a pull request about this fix.

Cheers,
Alessandro

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72784#72784








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
a.terenzi (Alessandro Terenzi)
Appreciator


Joined: 03 Sep 2009
Posts: 250

PostPosted: Fri Jan 19, 2018 10:02 am    Post subject:
Reply with quote

Hi Robert,
as far as I know the issue was present already with OSG version 3.4.0.

According to the AVFoundation documentation it seems that when one wants to access 'static' aspects of a media, such as the duration it is safe to rely on the AVAsset reference while when actually playing the media one has to use the AVPlayerItem instance, whose specific duration may be available only after a while... this is the reason, I think, the _duration variable is set to 0 in the above code.

This is what the doc says:

Quote:
AVAsset only models the static aspects of the media, such as its duration or creation date, and on its own, is unsuitable for playback with an AVPlayer. To play an asset, you need to create an instance of its dynamic counterpart found in AVPlayerItem.


In my proposal, [avplayer.currentItem asset] is the AVAsset reference that stores the static duration of the movie, and avplayer.currentItem is the AVPlayerItem that is still used for playback.

Anyway, I'm not an expert of AVFoundation, so please, anyone with more experience with that is welcome to comment Smile

Cheers,
Alessandro
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> Plugins [osgPlugins] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts OSG GLTF loader plugin Chris Hanson General 0 Thu Dec 06, 2018 9:55 pm View latest post
No new posts playing videos with audio channels wi... Trajce Nikolov NICK General 7 Wed Nov 21, 2018 9:17 pm View latest post
No new posts Could not find plugin to load objects sdef General [3rdparty] 1 Sat Oct 27, 2018 6:10 am View latest post
No new posts osg3.6.3 plugin issues jaisingla Plugins [osgPlugins] 2 Thu Oct 18, 2018 6:35 am View latest post
No new posts building the fbx plugin Tare Plugins [osgPlugins] 2 Wed Oct 10, 2018 3:04 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP