Blender Tutorial - How to Render Animations on Google Colab for Free! (Part 2)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
a few weeks ago i published a video on how to use google collab to speed up your final blender renders for free google collab provides free high performance gpus for things like training deep learning models on the cloud and other high performance computation applications but in this video and my previous video i demonstrate and will demonstrate how to download and install blender on google collab session and render a scene much faster than a typical desktop pc in my previous video i demonstrated that i could speed up my render time by at least 10 times i received a lot of comments on the video including a number of useful suggestions on how to simplify the whole process i also received a number of requests on how this technique could be used in other ways some of the requests included how to render blender animations using google collab how to render blender scenes that have image textures and how to change the file name of the rendered image in this video i'm going to show you how to do these things and in addition i will render my blender scenes using optics rather than cycles which i used in my last video in this video i'm not going to give a detailed explanation of the individual coding steps and what they do i'm also not going to compare render times between my desktop pc and google colab for more information on these please check out part one of this video i'll leave a link in the description of this video one reason in particular to watch part one is the instructions on how to download and install a specific version of blender for your specific project to make sure your blender scene renders as expected it's best to make sure you render with the same version of blender as your local project so let's get started so the first step is just to load up the blender file that you want to render on google colab here i've just set up a simple scene and for the purpose of this video i'm going to add one image texture to show that how you transfer these image textures to google colab so it renders correctly i've also animated the camera and some of these other objects i'll just play the video here you can see the camera is panning in and i've got this sphere that's hovering here in the center okay so for the first part of this video i'm going to show you how you render out an animation in mp4 format and keep the image texture as a separate file so for the mountain here if i bring up the shader editor window you can see i've applied a image texture i'll just render it out so you can see what it looks like i'll just expand out the window so it's a little bit bigger and zoom in so i haven't properly unwrapped the image texture or anything like that this the purpose of this video is just to show you how to copy that image texture across so i'm just going to open up the image texture here and i've got my jpeg of the image texture this location if you press the little cog over here you can see that it's set to relative path so that means provided that my blender file and the image texture in the same directory when i copy it to google collab it should render fine so i'm just going to go open image okay so i've configured my image texture correctly i'm sure your blender file will have many other image textures and hdris it's just the same process making sure that the relative path is set correctly and when you transfer it to your google drive they're all set with the same relative path directories so the next thing i want to do is just set up my render settings for google colab so i've set it here to render at full hd but just to speed up the render process on google codelab i'm just going to reduce the percentage down to 50 so it renders at half that resolution so although google collab is very quick compared with my pc here rendering the file it still does take some time so i'm going to just reduce it to 50 so i want to render 100 frames i've set my start frame to be 1 and my end frame to be 100 it doesn't matter what you set your render output directory to be i'll just leave it at the default now to render as an mp4 you want to change your file format to ffmpeg video you want the container to be mp4 and you can change other settings here so you could change it from output quality to say perceptually lossless and that's all you need to do there to remember out a video then you want to go to your render properties here make sure your render engine's set to cycles or ev depending on what you're doing set the number of samples that you want to render with i'm just going to set 500 for this purpose and then turn on things like motion blur if you want that in your movie and that's pretty much all you have to do so i'm just going to save my blender file now that i've changed those settings i'm going to close blender now you can see the directory where i've stored my blender file i've also got the associated ground texture which goes with my blender file now i'm just going to upload both of these to my google drive so i am going to copy the entire directory of glass orb into google drive and just let that upload okay now that my blender files and textures have been uploaded to google drive we're next going to go to google colab where we'll start writing out the command line scripts to render our blender file so if you just go to google and type in google colab click on this link here and you want to create a new notebook so google collab just requires a free google account to access so once it's loaded you'll be presented with this screen here so you can just change the name of your jupyter notebook here to something like um blender render and these lines here are where you type in your your code so i'm not going to write out the individual code i'm just going to present the individual snippets of code if you're interested in what these individual bits of code do please go back to my the first part of this video and you'll get a better explanation there so this first line of code just downloads blender version 2.91 from the official blender website so as i mentioned earlier in the video you probably want to match your blender version to the version of blender that you're using on your local pc to make sure it renders correctly so be sure to check out part one where i give an explanation of how to download a specific version of blender onto google colab so to insert the next line of code you just go insert code cell so this next line of code just installs the blender file that we just downloaded i'm going to insert another cell this next line of code connects to our google drive so that google colab can see our google drive and access the files like the blender file and the texture file this next line of code i'm just specifying the file name for my blender file so you can see it's going to be stored on my google drive my drive the glass orb directory which i just uploaded to google drive and i've specified the name of the blender file which was glassorb.blend now i'm going to insert one more code cell so this last line of code i'm going to go into a bit more detail but this is how you render your blender file on google colab so let's go through the individual steps just to explain what each of them do so this first bit here just runs blender on the command line by accessing the installed version of blender which we did in a previous step minus b means run blender in background so it won't bring up the interface where you would normally do your modeling and shading it just runs it on the command line dollar's file name says open up the blender file that we specified in this previous step no audio is just required for running blender on the command line minus e tells blender what render engine to use so in this case we've specified cycles minus o specifies the output file name so here i've specified slash means the uh the current direct directory so it's going to be stored in the same directory as the glass or blender file and it's going to output the file name in the form image and the hash symbols mean the frame number so in this case it might be if i was rendering frame one it might be image zero zero zero one since we're rendering an animation we wanna be able to specify um the frames that we wanna render so minus s is the start frame for the animation so i'm starting at frame one i'm going to render just say 125 frames so minus e is the end frame so ending at 125 and minus a means to render an animation this last step here tells blender to look for a optics based uh device so we're running on nvidia gpus here so we should be able to use the optics engine but you could replace this optics with uh cuda for example but in this case i'm just going to run with optics so the next step in rendering this blender file on google colab is just to run down the site here and click these plus signs to run the individual steps but before do you do that you want to go to the edit menu go to notebook settings under hardware accelerator we want to choose gpu because we want to render on a gpu and you also want to tick this box here which says emit code cell output when saving to this notebook i had a few errors unless i clicked this and then just press save and then say reload and you can see here it's connecting to an instance of google colab and you can see we're connected here and it's giving an indication of how much ram we're using on this instance and how much disk space we're using okay so next step click these plus buttons to download blender first and this will take just a few minutes you can see here it's giving us the percentage that's downloaded blender saying we've got about 45 seconds left while this is downloading i'll just mention that there is the option that you could download blender to your google drive directory so you don't have to repeat this download at every step but i generally find this is much easier since the time required to download blender is small compared to the total render time so i think this is just as easy so now that it's downloaded you can see it saved this blender tar file the next step is just to install blender so press the play button on the next step and this will take just a few seconds to install blender to our google collab instance and we don't have any errors so your blender has been installed correctly next step we want to connect to our google drive account and mount it as slash g drive so you can see it's saying go to this url in the browser and it wants an authorization code which gives google colab the rights to connect to our google drive so just click on this link and it will ask you to choose a google account that you want to link so i'll just click on my google drive and it's saying it wants to give access to your google account to say allow and it says please copy this code and paste into google collab so just press this little copy button go back to your google colab page and paste it into this cell and press enter and it should authorize you can see it's mounted at g drive so google chrome can now see our google drive i'm going to click the next step which just sets the file name to my glass orb if we go back to my google drive and go to my glass orb folder you can see i've got the glass or blend file here uploaded and my rocks ground image texture so let's just run the last step now so you can see it's uh read the blend file correctly glassob.blend and if you scroll down here you can see it's starting the rendering process and this might just take a few moments for the start of the first rendering of the first frame okay see we've got some progress here so you can see it's loaded in my rocks texture it's using the sky texture and it started rendering out the tiles so you can see at the moment it's rendered 10 out of the 40 tiles on the first frame here on the left and you can see the number of samples that it's rendered for each so you can see so far we've had about 1 minute and 48 seconds of render time and it's rendered about half the tiles on the first frame just give that a second to finish that one okay so let's render the first frame and let's just see how long that took scroll up so it took about two minutes total to uh initialize the rendering process and let's just see how long the next one's going to take each frame actually takes a lot less than that looks like it takes about a minute to render each frame but you can see here on the left we're at frame 2 of 125 now so i'm just going to leave that for a bit and then we'll come back and we will look at the finished product okay so you can see that blend has finished rendering that video file uh because of the time that it takes to render this i've just told it to render two frames but if you continue with that last process i just showed you it'll continue on to 125 frames or whatever number of frames that you've selected uh it tells you the total time that it took to render it and it will say blender quit so let's go back to our google drive now and see the image of the video that it's produced you can see here it's made a file called image001 to the frame number 0125.mp4 and you can see there we have it the animation has been rendered on google colab and stored in google drive which you can then download by right-clicking i'm just going to download it to my desktop and there you have it the animation okay now i'm going to show you a second method of doing this and this involves embedding all the image textures into the blender file that itself so you don't have to upload all the individual image textures up to google codelab and in this example i'm also just going to show you how to render a static a single frame rather than an animation so this will output a dot png file so what i'm going to do is duplicate my directory here so glass orb directory and i'm just going to call it glass orb 2. so let's load that up and double click on the glass orb all right so nothing's changed from the the previous time that i set up the blender file all i'm going to do this time is first go over to our output properties i'm going to change the file format to png and i think i can leave all the other settings correct i'm just going to ramp up the resolution to 100 again so it renders a full hd image you know render properties still got 500 samples i'm going to leave it as is but what i'm going to do now is embed all the image textures that i'm using within my blender file into the blender file itself so if you go up to the file menu and go external data and go automatically pack into dot blend you can see down here in the bottom it says packed one file so what this has done is it's saved that rox image texture into the blender file so i don't actually have to upload that that jpeg image anymore it'll save all your hdris it'll save your image textures into the blender file and then you just want to go file save and if you go to file again and have a look at external data you can if it can't find the files for some reason you can say report missing files or find missing files and correct all that here so now that i've done that just make sure it's saved close your blender file and to demonstrate that this works i'm going to delete the rocks texture that's used within my blender file then i'm going to go to my google drive and i'm going to upload this directory i'm going to go to my google drive and i'm going to upload this second directory that i've just made the glass orb 2 directory and just give that a minute to upload the file size of the the blender file that i've just created will be larger because it's saving the image textures within the blender file now and it's just a convenient way of packaging and sharing blender files okay so now that i've uploaded that new blender file i'm going to go back to my google colab notebook here so the only commands that are going to change are that i need to change my file name here so i'm just going to copy and paste that and i'm going to call it file name 2. and it's stored in the glass or two directory so i'm just gonna add a two there but the blender file name is the same so the other command that's gonna change is the the blender rendering commands the last commands that we use so just a few of the options are changing here so i'll just go through and explain it again so everything here is the same we're still running in the background we're changing the file name to file name too so we make sure we select this the second glass or blend file we still want to render with cycles i want to output the image file i've selected here slash g drive my drive so that's going to access my google drive account i've told i want to export it to the glass or two directory and i want to call the png file that exports image one the minus f command here says i want to render just frame 1 as a png and minus f says i want to render as a png file and the last command is just the same i want to render using optics just to show that this texture packaging method works i'm just showing my google drive account here so you can see glass or two and all i have is the blender file there's no image textures in there so let's go back to google collab now and if you're still using the same instance of colab that you use for the first part of this tutorial then you don't need to install blender again or download blender you don't need to connect to your google drive again account again all you need to do is run this new command here which specifies file name two paths so i'll click that then all you have to do is just run this last command here which will render a single frame as a png file for us so let's run that now you can see it's found the glassop2 file and it started rendering here we go rendering frame 1 it's estimating about 2 and a half minutes to render this at full hd with 500 samples and you can see here it's rendering 135 tiles and it's rendered tile 12 of 135 so i'll just give that a few more minutes to render and then we'll come back and look at the final result i'll upload a copy of this code as a text file and i'll store the link in the description you'll be able to download this code from my github account and there you have it you can see that blender has finished rendering it has saved my png file to my google drive to the glass or 2 directory and it's called image1001.png and it says it's taking a total time of 2 minutes and 26 seconds and it's quick blender okay so let's go to the google drive and just see what our output looks like you might have to refresh your browser here but you can see it's now created a new image file which you can click on and there you have it a static frame from the blender file and it saved it as a png and now you can just download this to your local pc just a few more points to consider google reports that the maximum run time for a google colab session is 12 hours and if your google collab session is idle for more than 90 minutes it will terminate it google also states in their faq that they give priority to users who run the notebook open and interactively so you can actually run blender by even if you close your browser once you've started rendering but google has or may cut you off so it's not a perfect system and you can't render for more than 12 hours at a time so once you finish your blender render you want to go up here to runtime go to manage sessions and you can see here i've got two google collab sessions running and it's saying one of them is using the gpu which is the one we just used you want to make sure you press terminate or terminate both of them so this will make sure that you're not using the gpu behind the scenes and next time you want to use google colab you might not be given access to a gpu by google so terminating the sessions means you're not using the gpu with your browser closed basically so google also says that they give priority to users who haven't used google a gpu for a while um so if you are using google copy if you are using a gpu on google codelab an awful lot then you might find later on that you might not have access to a gpu for a while but you will be given access again eventually you can actually just say you want to use the cpu if you're not to push for time you can go notebook settings and just say none and when you render it it will just use an available cpu which obviously take a lot longer but there's a free cpu for you thank you very much for watching part two of this tutorial if you enjoyed this tutorial or any of my other videos please don't forget to subscribe i'll be uploading new blender tutorials regularly thanks for watching
Info
Channel: Micro Singularity
Views: 14,512
Rating: undefined out of 5
Keywords: blender, blender tutorial, cycles, render, GPU, optimise, optimize, speed, fast, free, easy, google, google colab, colab, Colaboratory, animation, eevee, blender 2.9, google drive, python, free render farm, free GPU, software
Id: eOxawEi5cNk
Channel Id: undefined
Length: 24min 2sec (1442 seconds)
Published: Wed Jan 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.