On 30/04/2015 at 12:19, xxxxxxxx wrote:
There is difinately something wrong with the 'Calculate' button regarding fps. I'll report it.
Thanks for the 'MovieLoader' method. I'll use that for now since it will work across platforms.
Here is function I wrote to get movie info from different sources.
It lets you switch between 'MovieLoader' and ffprobe.
ffprobe will give you pretty much anything you want from either the video or audio stream.
def GetVideoInfo(file_path, movie_loader = True) :
from c4d import bitmaps
if movie_loader:
ml= bitmaps.MovieLoader()
movie=ml.Open(file_path)
print 'Movie loader', ml.GetInfo()
info = ml.GetInfo()
frames = info[0]
time_base = info[1]
duration = frames / float(time_base)
else:
# This uses 'ffprobe.exe' to get the info. Set 'gl_file_info_path' to the path for 'ffprobe.exe'
# This runs the subprocess without the pop-up console window.
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
result = subprocess.Popen([gl_file_info_path, file_path, '-print_format', 'json', '-show_streams', '-loglevel', 'quiet'], startupinfo=startupinfo,
stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
# Everything.
#return result.stdout.readlines()
# Video Stream, audio is 1.
#return json.loads(result.stdout.read())['streams'][0]
dict = json.loads(result.stdout.read())['streams'][0]
frames = int(dict['nb_frames'])
# Alternate in different format: return int(json.loads(result.stdout.read())['streams'][0]['duration_ts'])
duration = float(dict['duration'])
# Alternate in different format: values = dict['time_base'].split('/')
values = dict['r_frame_rate'].split('/')
time_base = float(float(values[0]) / float(values[1]))
print 'ffprobe:', frames, time_base
return frames, time_base, duration
Thanks everyone,
Chris
Here is a list of things you can get from ffprobe:
{
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "Main",
"codec_type": "video",
"codec_time_base": "1/50",
"codec_tag_string": "avc1",
"codec_tag": "0x31637661",
"width": 1280,
"height": 720,
"has_b_frames": 1,
"sample_aspect_ratio": "0:1",
"display_aspect_ratio": "0:1",
"pix_fmt": "yuv420p",
"level": 51,
"r_frame_rate": "25/1",
"avg_frame_rate": "25/1",
"time_base": "1/25",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 31453,
"duration": "1258.120000",
"bit_rate": "441269",
"nb_frames": "31453",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0
},
"tags": {
"creation_time": "2012-03-24 09:25:52",
"language": "eng",
"handler_name": "Apple Video Media Handler"
}
},
{
"index": 1,
"codec_name": "aac",
"codec_long_name": "AAC (Advanced Audio Coding)",
"codec_type": "audio",
"codec_time_base": "1/44100",
"codec_tag_string": "mp4a",
"codec_tag": "0x6134706d",
"sample_fmt": "fltp",
"sample_rate": "44100",
"channels": 2,
"bits_per_sample": 0,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/44100",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 55483392,
"duration": "1258.126803",
"bit_rate": "127999",
"nb_frames": "54183",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0
},
"tags": {
"creation_time": "2012-03-24 09:25:52",
"language": "eng",
"handler_name": "Apple Sound Media Handler"
}
}
],
"format": {
"filename": "C:\\temp\\TestFile.mp4",
"nb_streams": 2,
"format_name": "mov,mp4,m4a,3gp,3g2,mj2",
"format_long_name": "QuickTime / MOV",
"start_time": "0.000000",
"duration": "1258.120000",
"size": "90237437",
"bit_rate": "573792",
"tags": {
"major_brand": "mp42",
"minor_version": "1",
"compatible_brands": "mp42mp41",
"creation_time": "2012-03-24 09:25:52"
}
}
}