Render animation frame and stream to video file
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Render animation frame and stream to video file
Hi all. New user here. Nice to meet you all. I'm an Electrical Engineer by profession, but I tinker with robotics in my spare time. I'm planning to use FreeCAD's scripting capabilities to simulate the gait of a hexapod. I originally hand-wrote a Python-based OpenGL simulator for a 6 DOF robotic arm (here's a screenshot: https://i.imgur.com/UnfD8Fj.jpg) but it's a huge pain to rig. FreeCAD looks like a promising upgrade for complex mechanisms.
I've been playing around with script-based animation via A2Plus and I really appreciate the simplicity of joint actuation when imposing constraints. My concern, however, is slow rendering on the active view due to expensive computation at each time step.
So I had an idea. I'd like to script a job that renders one frame at a time, exporting each frame to a video stream output. I would gladly sacrifice the real-time animation for a smooth video end result. I'd imagine PySide2 can stream to a video buffer, I'm just not sure how to grab the active view (with transparent background).
Any thoughts how I could make this happen? Does this idea seem reasonable?
Note: I'd like to avoid Blender as this would require re-rigging the model.
I've been playing around with script-based animation via A2Plus and I really appreciate the simplicity of joint actuation when imposing constraints. My concern, however, is slow rendering on the active view due to expensive computation at each time step.
So I had an idea. I'd like to script a job that renders one frame at a time, exporting each frame to a video stream output. I would gladly sacrifice the real-time animation for a smooth video end result. I'd imagine PySide2 can stream to a video buffer, I'm just not sure how to grab the active view (with transparent background).
Any thoughts how I could make this happen? Does this idea seem reasonable?
Note: I'd like to avoid Blender as this would require re-rigging the model.
Re: Render animation frame and stream to video file
Have you investigated Assembly4? It can also do animations, and since it doesn't use a constraint solver, it may be faster. You may give it a try.
See Challenge: Constant Velocity Joint (M. Gesik)
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Render animation frame and stream to video file
Thanks for the link. I suppose my question is not how to improve rendering time but rather how to capture the active view with a transparent background so that I can feed it into a video buffer stream. Sorry if that wasn't clear. According to https://forum.freecadweb.org/viewtopic.php?t=29968 I can screen-grab with:vocx wrote: ↑Sun May 03, 2020 3:46 pmHave you investigated Assembly4? It can also do animations, and since it doesn't use a constraint solver, it may be faster. You may give it a try.
See Challenge: Constant Velocity Joint (M. Gesik)
Code: Select all
activeView = FreeCADGui.activeDocument().activeView()
activeView.saveImage(fileName,1000,800,'White')
Re: Render animation frame and stream to video file
I know what you wanted to do, I just mentioned Assembly4 in case you wanted to test that as well.
As for taking pictures, you can test different options of the Std_ViewScreenShot tool. Various rendering options were added in 0.19. I haven't tested them myself. Maybe one of them helps.
See Issue with "saveImage" and Parts with Transparency Nonzero.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Render animation frame and stream to video file
I had a further read and it seems that Qt5 isn't able to write a video file natively on Windows anyway. So unless I use something like OpenCV I'll be forced to export screenshots and stitch them together afterwards. Not too elegant, but not the end of the world!vocx wrote: ↑Sun May 03, 2020 8:40 pmI know what you wanted to do, I just mentioned Assembly4 in case you wanted to test that as well.
As for taking pictures, you can test different options of the Std_ViewScreenShot tool. Various rendering options were added in 0.19. I haven't tested them myself. Maybe one of them helps.
See Issue with "saveImage" and Parts with Transparency Nonzero.
Re: Render animation frame and stream to video file
hi
try this macro Macro_Screen_Wiki (special for the wiki worker) only for FC 0.19
choice the definition image , background visualise wit Set Screen or Tile Screen (facultatif) save your first image (name path...) after, if you want create serial image for create a gif animation (with other program) click the Follow button and the image are saved with the same name, path + 00x number without passing to the window Save image. (You have also window for create Rotation)
install with AddonManager
EDIT: 15h53 PARIS uprgade Version=0.02: 2020/05/04 (correct bug color, restore)
mario
try this macro Macro_Screen_Wiki (special for the wiki worker) only for FC 0.19
choice the definition image , background visualise wit Set Screen or Tile Screen (facultatif) save your first image (name path...) after, if you want create serial image for create a gif animation (with other program) click the Follow button and the image are saved with the same name, path + 00x number without passing to the window Save image. (You have also window for create Rotation)
install with AddonManager
EDIT: 15h53 PARIS uprgade Version=0.02: 2020/05/04 (correct bug color, restore)
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
Re: Render animation frame and stream to video file
Hey that's pretty neat. It's nearly what I'm looking for, except that I'll also need to animate joint movements. I had a look at the source and there's a lot of good stuff to get me started on writing a script of my own. Thanks for sharing. Out of curiosity, is there something in particular that needs PySide2 (Qt5) that I should be aware of? 0.19 has a few visual bugs so I'm planning to stick with 0.18 for now.mario52 wrote: ↑Mon May 04, 2020 9:24 am hi
try this macro Macro_Screen_Wiki (special for the wiki worker) only for FC 0.19
choice the definition image , background visualise wit Set Screen or Tile Screen (facultatif) save your first image (name path...) after, if you want create serial image for create a gif animation (with other program) click the Follow button and the image are saved with the same name, path + 00x number without passing to the window Save image. (You have also window for create Rotation)
install with AddonManager
EDIT: 15h53 PARIS uprgade Version=0.02: 2020/05/04 (correct bug color, restore)
mario
Re: Render animation frame and stream to video file
If you see bugs they won't be solved unless you report them.
Independently of that, Qt4 is obsolete, so you should be using Python 3 and Qt5, instead of staying with Python 2 and Qt4.
Always add the important information to your posts if you need help. Also see Tutorials and Video tutorials.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
To support the documentation effort, and code development, your donation is appreciated: liberapay.com/FreeCAD.
Re: Render animation frame and stream to video file
hi
for animation you have :
Animation_Workbench
here for rotate and save image step by step
Manipulator_Workbench
Placement
my other macro Macro_Rotate_To_Point
mario
natural evolution and i work for convert my all macros
for animation you have :
Animation_Workbench
here for rotate and save image step by step
Manipulator_Workbench
Placement
my other macro Macro_Rotate_To_Point
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
My macros on Gist.github here complete macros Wiki and forum.
- jimmihenry
- Posts: 238
- Joined: Sat Jan 11, 2020 3:36 pm