Trigger 'Calculate' frames button [SOLVED]
-
On 30/04/2015 at 00:53, xxxxxxxx wrote:
I'm loading a movie into a shader:
shader[c4d.BITMAPSHADER_FILENAME] = filepath
...and I need to trigger the 'Calculate' button so C4D will set the 'Movie Start Frame', and the 'Movie End Frame'. I don't see an easy way to calculate that myself. The method I use will have to work on different OS's.
Also, I've noticed that if I press 'Calculate' with a movie that has a frame rate of 29.97, C4D incorrectly sets the fps to 29. It doesn't set it correctly, or even attempt to round up to 30. What's up?
Thanks,
Chris
-
On 30/04/2015 at 05:00, xxxxxxxx wrote:
Hi Chris,
you can use movie loader Get info to read the informations out of your movie file.
After this you can set the timing to the shader like we discussed it in this thread:
Grabbing bitmap dataimport c4d, os from c4d import bitmaps def BitmapSet(Shader,doc) : bitmapPath = Shader[c4d.BITMAPSHADER_FILENAME] #if bitmapPath is´nt absolute if not os.path.dirname(bitmapPath) : #the document has´nt been saved already ->picture in user library if not doc.GetDocumentPath() : abspath= c4d.storage.GeGetStartupWritePath()+"/"+"tex"+"/"+bitmapPath #the picture should be inside the asset´s texture folder else: abspath= doc.GetDocumentPath()+"/"+"tex"+"/"+bitmapPath else: abspath = bitmapPath bmp = bitmaps.BaseBitmap() result, ismovie = bmp.InitWith(abspath) if result==c4d.IMAGERESULT_OK: # picture loaded if ismovie==True: ml= bitmaps.MovieLoader() movie=ml.Open(abspath) print ml.GetInfo() return def main() : TexTag = op.GetTag(c4d.Ttexture) Mat= TexTag.GetMaterial() Shader=Mat[c4d.MATERIAL_COLOR_SHADER] doc = op.GetDocument() BitmapSet(Shader,doc) if __name__=='__main__': main()
Best wishes
Martin -
On 30/04/2015 at 05:25, xxxxxxxx wrote:
You could try to use CallButton()
-
On 30/04/2015 at 07:30, xxxxxxxx wrote:
Hello,
as Niklas said you can use CallButton() to trigger a button. In fact, this function was discussed recently on this forum so you find information on that in this threads:
CallButton: Bitmap Animation - Calculate
Save Project File in Render SettingsIf a feature of Cinema 4D does not work like expected please use this form to send a bug report. Thanks.
Best wishes,
Sebastian -
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" } } }
-
On 30/04/2015 at 13:56, xxxxxxxx wrote:
I just got a response from the bug report I sent to Maxon about the 'Calculate' button:
'Unfortunately this is a known bug that seems to have been around forever.'Hmmm.....Then why hasn't it been fixed?