Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duration Format With Moviepy #502

Closed
bobozar opened this issue Mar 18, 2017 · 5 comments
Closed

Duration Format With Moviepy #502

bobozar opened this issue Mar 18, 2017 · 5 comments

Comments

@bobozar
Copy link

bobozar commented Mar 18, 2017

How can I get the video duration in this format- 03:05 or 01:23:05 instead of the default format 60.15 for I hr 15 secs video.

Can seems to even get a template tag for this. Any idea on how to go about this in Python or in Django by saving the default format and change it in template.?

@Zulko
Copy link
Owner

Zulko commented Mar 20, 2017

Not sure what you mean. A video clip duration is expressed in seconds in Moviepy. 60.15 means 60 seconds and 15/100. To get the time format you want, you'd write something like (didnt check)

hours = clip.duration / 3600
mins = (clip.duration % 3600) / 60
secs = (clip.duration % 60)
duration = "%02d:%02d:0.2f" % (hours, mins, seconds)

@bobozar
Copy link
Author

bobozar commented Mar 26, 2017

Yeah something like this! Let me try it and get back to you. Thanks!

@bobozar
Copy link
Author

bobozar commented Mar 26, 2017

Done it. For anyone who might need this!

    >>> mx=clip.duration
     >>> seconds=mx
     >>> m, s=divmod(seconds, 60)
     >>> h, m=divmod(m, 60)
     >>> print "%d:%02d:%02d" % (h, m, s)
     0:01:00

@tburrows13
Copy link
Collaborator

@bobozar has a solution. Closing this now.

@ghost
Copy link

ghost commented Apr 4, 2017

should we add a function that will accept seconds and return a string in hh:mm:ss format ? I can add it if others think it might be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants