[0:01] [Music] [0:09] [Music] [0:26] [Music] [0:30] hello [0:31] and welcome to video editing in python [0:34] using moviepie [0:35] video series this is part one of this [0:38] video series [0:38] and in this particular part we are going [0:41] to discuss [0:42] what pie is what it can do how to [0:45] install it [0:46] and how to get started with it movie pie [0:49] basically [0:50] is a very very powerful package [0:53] for video editing not just video you can [0:56] you can actually work with audio you can [0:59] work with text you can overlay text [1:02] on the video you can change the video of [1:04] one clip to another you can actually [1:06] make your own tick tock [1:07] uh just by picking a video from [1:11] the video images from some other source [1:13] and [1:14] audio source audio clip from another [1:17] source and just mixing them [1:18] up um not only that you can crop videos [1:21] you can [1:22] you can just give special effects to the [1:25] videos you can [1:26] you can actually do frame by frame [1:27] processing uh [1:29] using movie pi although uh using frame [1:31] by frame processing [1:32] is not really recommended uh in movie pi [1:36] there are some better packages for frame [1:38] by frame processing like opencv [1:40] and some simple cv and some other [1:42] packages [1:44] but moviepie basically give you a very [1:47] powerful [1:47] api for working with working with videos [1:50] audios and text and [1:52] making custom animations uh combining [1:55] different clips together [1:56] um and and making another clip and stuff [1:58] like so [1:59] so um yeah in this particular part [2:02] we will be uh actually getting started [2:05] with uh [2:06] video editing uh basically [2:09] we'll be uh loading videos we'll be [2:11] playing videos in jupiter notebooks we [2:13] will also be saving [2:15] uh videos on hard disk uh we will be [2:18] cropping videos we will be [2:20] picking sub clips we will be actually [2:22] changing [2:23] um changing audio of [2:26] a video with audio of another video [2:29] um we will also be seeing how to display [2:33] overlay text over a video or how how to [2:36] actually make the text moving on on a [2:39] video [2:39] so everything basically is in this uh in [2:41] this part [2:42] uh in the next part however we will see [2:45] in the next part of this video series we [2:46] will be actually seeing [2:48] how to combine different clips together [2:51] uh [2:51] and make one video that actually [2:53] contains a lot of videos [2:55] um and in the third and final clip of [2:58] this video series we will be actually [3:00] seeing how to make custom animations [3:02] um using movie pie so let's dive in [3:06] uh first of all um how to install it um [3:10] just write pip install movie pie and [3:12] that's it [3:14] it will get installed um there are some [3:17] dependencies [3:18] that uh moviepie automatically installs [3:20] for you [3:21] um but one thing that um that is [3:24] worth mentioning is image magic tool [3:27] that you have to install [3:28] uh separately so it's always good to [3:31] install [3:32] first the image magic and then install [3:33] moviepie um [3:35] then there are some config defaults file [3:38] config defaults [3:39] config underscore defaults dot pi file [3:43] in movie pi in which you have to you [3:46] have to set the path of image magic [3:48] in my machine however i just installed [3:50] image magic i [3:51] reboot the system and everything works [3:54] automatically [3:55] but in certain cases you may have to [3:56] work with config defaults [3:59] maybe you also have to install pygame [4:01] that also has [4:02] some dependency with movie pie but most [4:05] of the stuff [4:06] is just done using this movie pie and [4:08] image magic [4:09] if you for example go to the owner's [4:12] page silko it's the owner of this [4:15] package uh there are these clear [4:17] instructions so [4:18] you can see the zulko github.io moviepie [4:21] slash [4:22] you can go to download and installation [4:24] and it actually guides each and [4:26] everything [4:27] how to install it uh what kind of [4:29] dependencies are there [4:30] uh how to change this config underscore [4:33] defaults if required [4:35] uh for dependencies you have to use this [4:37] image magic [4:39] how to change the path of the image [4:40] magic and stuff like so [4:42] and also you may need the spy game for [4:45] video and sound previews if you really [4:47] want to see the previews [4:49] um if you want to see the previews there [4:53] is a function clip dot show if you want [4:54] to use that you may need this buy game [4:57] uh installed so yeah and and that's a [5:01] good page by the way it [5:02] uh it actually contains a lot of [5:04] documentation a lot of example scripts [5:06] and a lot of stuff [5:07] um and it's uh to to learn movie pie in [5:11] detail [5:11] it's good to just go through this page [5:13] first [5:14] so yeah um uh [5:18] let's let's basically start um coding in [5:21] moviepie let me just set the [5:23] zoom level to a better level uh let me [5:27] uh yeah so first of all [5:31] um we have to from [5:34] we have to load most of the stuff is [5:37] done by movie pie dot [5:38] editor so movie pie dot [5:42] um editor from there [5:46] if you want to import certain modules [5:48] you can import certain modules [5:50] if you import if you want to import [5:52] everything although it's not recommended [5:54] because it makes things slow but [5:56] um here is we have imported each and [5:59] everything [6:00] um from this movie pi now next what we [6:03] do is [6:04] uh we read a video clip from from the [6:07] hard disk here i have some video clips [6:10] downloaded from youtube so let's read [6:14] 2 dot mp4 and see its properties [6:17] so 2 or mp4 that's the path [6:22] and here we go back so let's say [6:25] clip equals [6:29] video file clip that is there [6:33] in moviepie dot editor video file clip [6:37] there are [6:37] there are basically three kinds of clips [6:39] video clips [6:41] uh audio clips and text clips so video [6:44] file clip [6:45] are that is for the raw [6:48] string and here you actually [6:51] read the clip so yeah the clip has been [6:55] read [6:56] there are several properties that we can [6:58] see about this clip for example the size [7:00] of this clip [7:02] so width and height is clip dot [7:05] size what is the size of this [7:09] clip so let's print width and height [7:12] and the size of this particular clip is [7:14] the width is 480 [7:16] and the height basically is 360. so that [7:20] for this particular clip [7:21] that's the width and height there are [7:24] other [7:25] for example other properties of this [7:28] clip as well [7:29] so for example clip dot duration [7:33] what is that the duration of this clip [7:35] in seconds [7:36] is 283 seconds if we for example divide [7:40] this [7:41] by 60 we may get [7:45] the minutes which is four minutes and [7:48] roughly [7:49] the rest is again the seconds so around [7:52] four minutes four point some [7:53] uh minutes so 4.72 minutes so if we [7:56] multiply this point 72 [7:58] with 60 we get exactly the number of [8:01] minutes that are there [8:02] further we can we can also see several [8:06] things [8:07] let's see for example clip dot fps [8:11] frames per second this video has been [8:13] recorded [8:14] in how many frames per second a frame is [8:17] an image in in videos normally in one [8:21] second [8:23] it actually saves a lot of images those [8:25] images are called frames [8:27] so this frames per second is a property [8:30] for high resolution images these [8:32] high resolution video images this fps [8:34] number is really large [8:36] which means for one second you are [8:37] saving a lot of details a lot of [8:39] frames so in this particular case for [8:42] this particular video the [8:43] frames per second property is really 30. [8:48] um we can have a sub clips [8:51] if we really want before before actually [8:54] going towards the sub clip and stuff [8:56] like so [8:56] let's actually display this clip uh in [8:59] in in the jupyter notebook so [9:01] clip dot ipython [9:06] display so clip dot ipython display and [9:09] here you can set the width uh [9:13] inside the notebook for example the [9:15] width [9:16] i'm setting the width like let's say [9:20] 280 maybe maybe i can set the width [9:24] maybe the original width or maybe for [9:26] example [9:28] 350 and it will automatically [9:31] uh actually it will automatically take [9:33] care of the aspect ratio and [9:35] will convert the height accordingly so [9:37] that will do [9:38] that will actually embed the clip in i [9:40] in this jupyter notebook so let's see [9:43] how it goes uh it will take some time [9:45] because it is rendering [9:47] so yeah it will take some time it's a [9:50] it's a long clip it will take some time [9:52] to render it [9:53] so yeah let's let's wait for it [9:57] rendering [9:58] and then we will be actually we will [10:01] actually be able to [10:02] uh see it's playing inside the [10:06] inside the notebook so let's see let's [10:10] wait for it [10:11] it is rendering um [10:14] yeah or maybe i can just [10:18] pause the video and once the rendering [10:19] is up then i then i get back to this [10:21] video against to [10:23] to save the time so let me [10:26] let me get this thing finished and then [10:29] we will see [10:30] if oh it's an error what kind of error [10:33] is this [10:35] not the embedding large videos may take [10:37] all the memory away so this video [10:39] basically is [10:40] oh this video is basically large and it [10:43] exceeds the maximum duration so it [10:44] cannot be embedded [10:46] uh inside the uh inside the notebook so [10:50] let let's just let's just get a sub clip [10:53] of this video and [10:54] and and show that so why not why not [10:57] just pick [10:57] the sub clip of that video so clip two [11:01] is clip dot sub clip [11:05] and um i actually [11:08] get the sub clip with the ending time [11:12] as as 0 [11:16] 0 30 that means [11:19] um pick the sub clip of the image [11:22] starting from the very beginning [11:24] but the end time is 30 seconds this the [11:27] first [11:28] argument is for hours the second [11:29] argument is it argument is for minutes [11:32] and the third argument is for seconds [11:36] so what i'm saying here is uh start from [11:38] the very beginning [11:40] and go till 30 seconds and crop and [11:43] and just and just get the sub clip and [11:46] copy that [11:46] into clip two uh you can set the dstart [11:49] property here tn property here [11:51] separately and [11:52] you can work with that as well so that's [11:55] clip two [11:57] now let's uh let's display this clip too [11:59] maybe it is faster clip two is [12:02] dot i python display [12:05] this is faster maybe because uh the [12:08] the duration of this clip is smaller [12:10] width is let's say [12:12] uh 280 maybe so [12:16] let's see uh if it is a little bit [12:19] quicker [12:20] let's see so yeah [12:24] so here it has actually rendered that [12:27] inside this [12:28] jupyter notebook and now you can see you [12:31] might be [12:32] uh hearing the the sound of the [12:35] the sound of the video as well [12:38] [Music] [12:52] so these are the 30 seconds of the video [12:58] [Music] [12:59] and not only that i mean you have you [13:02] have [13:02] found the sub clip no if you really want [13:05] this sub clip [13:06] or the part of the video to be saved on [13:08] the hard disk [13:09] you can actually go and write clip [13:13] to dot um [13:17] right video file [13:20] and there you have to give the path of [13:22] the video file where you really want to [13:24] save it [13:25] so for example um let me give the path [13:27] like this [13:32] and here we go [13:35] and here we say ok to clipped [13:40] and it will start actually writing that [13:43] onto the hard disk for you [13:46] there are certain extensions there are [13:48] certain extensions that are supported [13:49] uh i'm right now i'm working with mp4 [13:52] there are a couple of others as well [13:54] so yeah it has done so let's go to hard [13:58] disk [13:58] and actually see this is too clipped so [14:02] let's open up it [14:03] in windows media player and here you're [14:05] seeing the 30 minutes clip [14:07] 30 seconds clip yeah [14:14] yeah so [14:17] that's the very beginning of uh [14:20] this clip sub clip and stuff like so [14:23] let's play [14:23] uh with it a little bit more let's say [14:26] for example [14:27] clip three is clip [14:30] two dot rotate [14:33] uh with 180 degree so what it will do is [14:37] it will rotate the clip [14:39] uh with 180 degree and then if you [14:41] really [14:42] want to embed this if you really want to [14:44] see this [14:45] clip 3 dot [14:48] ipython display oh [14:52] the clip 3 is not created yet so this so [14:55] clip [14:56] 3 dot python display [15:00] um and whatever the original length is [15:03] so i will i will go with that so that [15:06] will embed there [15:07] remember all the operations here in this [15:09] movie pi they [15:10] uh actually are not performed on the [15:12] whole video [15:14] until the video is rendered for either [15:16] display [15:17] or embedding in the notebook or or if it [15:20] is going to be [15:21] written on uh on in the in the hard disk [15:25] so at the very final time the video is [15:26] rendered and at that particular time it [15:29] takes some time so [15:31] uh let's see basically if i have rotated [15:34] the video [15:35] by 180 degree it actually flipped the [15:38] video upside down so [15:40] let's see how it goes yeah so [15:43] that has a larger size let me uh [15:47] let me do a little bit yeah so if you [15:50] now see [15:51] the video is just upside down [15:55] and there are a lot of effects that you [15:57] can go through with [15:58] um right now um i'm going to basically [16:02] um add um add a text [16:06] clip on the on on on this particular [16:08] video clip [16:09] so we will be having video clip two what [16:12] i'm going to do [16:12] is i'm going to uh overlay text [16:16] on this video clip too um you can you [16:19] can have [16:20] several other functions for example [16:23] clip 2 is clip 2 [16:27] dot volume volume [16:30] x and that if for example i set the [16:33] value 0.7 [16:35] that means reduce the volume of my clip [16:38] um by by i mean just keep the 70 [16:42] of it and reduce it by 30 percent and [16:45] and you can give this number to be [16:46] larger than one and the volume become [16:48] increase [16:49] amplified so and and there are so many [16:52] other functions there are so many other [16:53] functions [16:54] you can just uh you can just check right [16:57] now i'm going to basically [16:58] um uh write a write a floating text [17:02] on on this video and the resultant video [17:05] will be saved [17:06] or displayed in the notebook or can be [17:09] saved in the hard disk either way [17:11] so we already have clip two let's make a [17:13] text clip [17:14] so let me write text clip [17:19] is text clip that is there [17:22] in movie by dot editor um [17:25] let's say the text clip contains the [17:27] text as [17:29] a i sciences i [17:34] ai sciences um and for this text clip [17:38] the font size [17:39] is let's say let's say the font size is [17:42] 150 [17:44] and the color let's say the color is you [17:47] can have different colors [17:48] uh let's say the color right now is [17:51] let's say [17:52] we have red color so that's our text [17:55] text clip uh next what we do is uh we [17:58] set the [18:00] set the position of this text clip so [18:03] text [18:05] clip is equal to [18:08] text [18:11] clip unlike other object-oriented [18:14] packages where [18:15] you write a dot and you call certain [18:17] functions and the properties are changed [18:18] inside um this moviepie actually returns [18:22] a copy and you have to save the copy [18:24] otherwise the changes are lost [18:26] so that's why i actually i'm saving i'm [18:29] doing i'm [18:30] going to change the properties of text [18:31] clip but the [18:33] properties they will not be reflected [18:35] inside this object but it returns an [18:36] object that you have to save somewhere [18:38] otherwise [18:40] they will not be saved exactly here [18:42] which is [18:43] uh which is something something [18:46] different than [18:46] the ordinary uh object oriented [18:48] programming where [18:50] we actually change the properties inside [18:52] the object [18:54] so position [18:57] so position and we can set several [19:00] positions we can we can for example i [19:02] can just set the position [19:04] um 20 and 20 that means for screen [19:08] size for the m for the clip size go to [19:10] 2020 and just place that [19:13] text uh what what other thing that i can [19:16] do is i can change the position with [19:18] time using a function let's say lambda [19:21] t that t is the time [19:24] t basically is the time and we are going [19:26] to change this [19:29] the position time by time so let's say [19:31] 10 historic t [19:33] then steric t so that means for every [19:37] time unit [19:38] go to this particular position and [19:40] display the text [19:41] further i have to set the duration [19:45] of the clip duration [19:48] let's say the duration duration of the [19:51] text [19:52] let's say the duration of the text is [19:56] the duration of or or let's say duration [20:00] of the [20:02] let's say duration of clip 2. [20:06] duration so that's um [20:10] our text clip ready and positions are [20:13] set [20:13] what next is we need to overlay this [20:17] text [20:18] onto the video so let's make a final [20:20] clip or video [20:23] final video and here we will be using [20:26] composite function composite class [20:29] composite video clip class [20:31] um we will see the composite video clip [20:34] class [20:35] in more detail in our next part of the [20:37] same series [20:38] right now i'm just using it clip 2 [20:42] and then we have this text clip [20:47] and we can set the start of this clip [20:50] when should it start let's say it should [20:52] start right after [20:54] two seconds of the clip two video [20:57] and then we can have effects like a fade [21:00] in [21:00] effect so let's say cross [21:04] fade in how many seconds it should [21:07] fade in it should appear it should take [21:10] how many seconds to appear in the video [21:12] let's say let's say three seconds and [21:15] that's our video [21:16] um yeah video is ready now once [21:20] the video is ready now we can either [21:22] embed it [21:23] in ipad ipython notebook or we can save [21:25] it [21:26] so let's embed it in the notebook video [21:29] dot [21:30] ipython display and [21:33] let's display it in [21:36] with width let's say [21:40] 280 let's say um [21:45] yeah so let's see how it goes [21:49] it will take a few seconds to render it [21:53] so yeah [21:57] almost done um not almost i mean [22:01] but getting closer and closer and this [22:04] uh text will appear in the floating form [22:07] on this uh video so let's see that [22:11] [Music] [22:14] yeah so you can see this oh the font [22:17] size is too big [22:19] the font size is too big for for this [22:21] video [22:22] so let's go back and let's go [22:26] back and reduce the font size the font [22:29] size is let's say [22:30] um let's say 20. [22:34] let's go back let's re-render it [22:38] because the font size was too big to [22:41] appear on this video [22:46] so let's see how it goes now with the [22:49] new font size [22:50] [Music] [22:53] oh you can see this a sciences [22:56] um yeah it is floating over the video [23:01] you can have special effects for this [23:03] you can have you can have [23:05] certain characters to appear one by one [23:07] and moves on [23:11] it will stay as long as the [23:15] the video continues because we set the [23:17] duration as the duration of the video [23:19] clip [23:21] so yeah that's cool we have done a lot [23:25] of stuff [23:25] just in just in a very small amount of [23:29] time [23:29] and that's the power of this package i [23:31] mean if you want to start video editing [23:33] um you want to play with audio you want [23:37] to play with [23:38] text uh this is the this is one [23:41] of the best packages to really start [23:43] with [23:44] um yeah uh i end this part here in the [23:47] next part i will be [23:49] actually going a little deeper and i [23:51] will be telling you how to [23:53] combine different uh video clips [23:55] together [23:56] to make a final video that has um that [23:59] has a combination of several clips [24:01] and we will be primarily using concave [24:03] we will be primarily concatenating [24:05] videos we will be actually arranging [24:06] them in a matrix form [24:08] or actually more precisely we will be [24:10] using this uh [24:11] composite video class uh composite video [24:14] clip [24:15] class um to to get special kind of [24:18] effects [24:19] um and in in the last part of this video [24:22] series part three [24:23] we will actually be making our custom [24:25] animations so hope to see you in the [24:27] next [24:30] part [24:32] [Music] [24:49] [Music] [24:55] [Music] [24:56] you