2013-08-07 22:25:18 +00:00
|
|
|
import numpy.core.multiarray # important this comes before cv!
|
|
|
|
import cv
|
2013-02-19 00:11:43 +00:00
|
|
|
from flvlib import tags as flv_tags
|
2013-07-10 20:25:57 +00:00
|
|
|
import HydrusConstants as HC
|
|
|
|
import os
|
2013-02-19 00:11:43 +00:00
|
|
|
import traceback
|
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
def GetFLVProperties( path ):
|
2013-02-19 00:11:43 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
with HC.o( path, 'rb' ) as f:
|
2013-02-19 00:11:43 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
flv = flv_tags.FLV( f )
|
|
|
|
|
|
|
|
script_tag = None
|
|
|
|
|
|
|
|
for tag in flv.iter_tags():
|
2013-02-19 00:11:43 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
if isinstance( tag, flv_tags.ScriptTag ):
|
|
|
|
|
|
|
|
script_tag = tag
|
|
|
|
|
|
|
|
break
|
|
|
|
|
2013-02-19 00:11:43 +00:00
|
|
|
|
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
width = 853
|
|
|
|
height = 480
|
|
|
|
duration = 0
|
|
|
|
num_frames = 0
|
2013-02-19 00:11:43 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
if script_tag is not None:
|
|
|
|
|
|
|
|
tag_dict = script_tag.variable
|
|
|
|
|
|
|
|
# tag_dict can sometimes be a float?
|
|
|
|
# it is on the broken one I tried!
|
|
|
|
|
|
|
|
if 'width' in tag_dict: width = tag_dict[ 'width' ]
|
|
|
|
if 'height' in tag_dict: height = tag_dict[ 'height' ]
|
|
|
|
if 'duration' in tag_dict: duration = int( tag_dict[ 'duration' ] * 1000 )
|
|
|
|
if 'framerate' in tag_dict: num_frames = int( ( duration / 1000.0 ) * tag_dict[ 'framerate' ] )
|
|
|
|
|
2013-02-19 00:11:43 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
return ( ( width, height ), duration, num_frames )
|
2013-02-19 00:11:43 +00:00
|
|
|
|
2013-07-10 20:25:57 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
def GetMP4Properties( path ):
|
2013-07-10 20:25:57 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
cvcapture = cv.CaptureFromFile( path )
|
2013-07-10 20:25:57 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
num_frames = cv.GetCaptureProperty( cvcapture, cv.CV_CAP_PROP_FRAME_COUNT )
|
2013-07-10 20:25:57 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
fps = cv.GetCaptureProperty( cvcapture, cv.CV_CAP_PROP_FPS )
|
2013-07-10 20:25:57 +00:00
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
length_in_seconds = num_frames / fps
|
2013-07-10 20:25:57 +00:00
|
|
|
|
|
|
|
length_in_ms = int( length_in_seconds * 1000 )
|
|
|
|
|
2013-08-07 22:25:18 +00:00
|
|
|
width = cv.GetCaptureProperty( cvcapture, cv.CV_CAP_PROP_FRAME_WIDTH )
|
|
|
|
|
|
|
|
height = cv.GetCaptureProperty( cvcapture, cv.CV_CAP_PROP_FRAME_HEIGHT )
|
|
|
|
|
|
|
|
return ( ( width, height ), duration, num_frames )
|
2013-07-10 20:25:57 +00:00
|
|
|
|