2015-10-05 08:36:06 +02:00
|
|
|
"""
|
|
|
|
Author: Jaisen Mathai <jaisen@jmathai.com>
|
|
|
|
Video package that handles all video operations
|
|
|
|
"""
|
2015-10-02 09:20:27 +02:00
|
|
|
|
2015-10-05 08:36:06 +02:00
|
|
|
# load modules
|
2015-10-12 09:37:57 +02:00
|
|
|
from distutils.spawn import find_executable
|
2015-10-02 09:20:27 +02:00
|
|
|
from sys import argv
|
2015-10-12 09:37:57 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
2015-10-02 09:20:27 +02:00
|
|
|
import mimetypes
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
|
2015-10-07 08:47:51 +02:00
|
|
|
from elodie.media.media import Media
|
2015-10-02 09:20:27 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
Video class for general video operations
|
|
|
|
"""
|
2015-10-07 08:47:51 +02:00
|
|
|
class Video(Media):
|
2015-10-05 08:36:06 +02:00
|
|
|
# class / static variable accessible through get_valid_extensions()
|
2015-10-06 10:28:00 +02:00
|
|
|
__valid_extensions = ('avi','m4v','mov','mp4','3gp')
|
2015-10-05 08:10:46 +02:00
|
|
|
|
2015-10-05 08:36:06 +02:00
|
|
|
"""
|
|
|
|
@param, source, string, The fully qualified path to the video file
|
|
|
|
"""
|
2015-10-02 09:20:27 +02:00
|
|
|
def __init__(self, source=None):
|
2015-10-07 08:47:51 +02:00
|
|
|
super(Video, self).__init__(source)
|
2015-10-02 09:20:27 +02:00
|
|
|
|
2015-10-14 09:39:30 +02:00
|
|
|
# We only want to parse EXIF once so we store it here
|
|
|
|
self.exif = None
|
2015-10-02 09:20:27 +02:00
|
|
|
|
2015-10-05 08:36:06 +02:00
|
|
|
"""
|
|
|
|
Get the duration of a video in seconds.
|
|
|
|
Uses ffmpeg/ffprobe
|
|
|
|
|
|
|
|
@returns, string or None for a non-video file
|
|
|
|
"""
|
2015-10-07 08:47:51 +02:00
|
|
|
def get_duration(self):
|
2015-10-02 09:20:27 +02:00
|
|
|
if(not self.is_valid()):
|
|
|
|
return None
|
|
|
|
|
|
|
|
source = self.source
|
2015-10-05 08:36:06 +02:00
|
|
|
result = subprocess.Popen(['ffprobe', source],
|
2015-10-02 09:20:27 +02:00
|
|
|
stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
|
|
|
|
for key in result.stdout.readlines():
|
|
|
|
if 'Duration' in key:
|
|
|
|
return re.search('(\d{2}:\d{2}.\d{2})', key).group(1).replace('.', ':')
|
2015-10-05 08:36:06 +02:00
|
|
|
return None
|
2015-10-02 09:20:27 +02:00
|
|
|
|
2015-10-05 08:36:06 +02:00
|
|
|
"""
|
|
|
|
Static method to access static __valid_extensions variable.
|
|
|
|
|
|
|
|
@returns, tuple
|
|
|
|
"""
|
2015-10-05 08:10:46 +02:00
|
|
|
@classmethod
|
|
|
|
def get_valid_extensions(Video):
|
|
|
|
return Video.__valid_extensions
|
|
|
|
|
2015-10-02 09:20:27 +02:00
|
|
|
class Transcode(object):
|
|
|
|
# Constructor takes a video object as it's parameter
|
|
|
|
def __init__(self, video=None):
|
|
|
|
self.video = video
|