How I Edit My Videos With Python - Python Task Automation
In this tutorial, I show you how I edit my videos using Python and MoviePy.
MoviePy is a Python module for video editing, which can be used for basic operations like cuts, concatenations, title insertions, video compositing, video processing, and even to create advanced effects.
✅ Write cleaner code with Sourcery, instant refactoring suggestions in VS Code & PyCharm: sourcery.ai/?... *
⭐ Join Our Discord : / discord
🚀🚀 Get monthly Python and ML Tips:
www.python-engineer.com/newsl...
🚀🚀 SUPPORT ME ON PATREON:
/ patrickloeber
If you enjoyed this video, please subscribe to the channel!
Moviepy: zulko.github.io/moviepy/index...
Code:
github.com/patrickloeber/pyth...
You can find me here:
Website: www.python-engineer.com
Twitter: / patloeber
GitHub: github.com/patrickloeber
Music: www.bensound.com/
Photo by Jakob Owens on: unsplash.com/photos/l82NzBSYbj0
#Python
----------------------------------------------------------------------------------------------------------
* This is a sponsored or an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏
As a video editor who is now a coding wannabe, this is pure gold man!!
Hello Patrick, there are some but not so many YT channels which are prepared so outstanding like your. The effort and performance you deliver are remarkable, brilliant and impressive. You cover all the latest SW technologies and share your passion. Keep fingers for your goals.
Thanks so much for the kind words Markus!
@@patloeber Good luck!
Straight to the point and just mind blowingly well explained.
glad you like it!
Thank you for sharing this! Love all your video! It's very informative!!!
I found your great tutorial because I was thinking how convenient would be to have a way to edit videos using code for some workflows.
That's it i looking for. Awesome Bro !
Thank you!
Very useful for Minecraft ASMR mining blocks and putting blocks. I know that this is applicable in a lot of situations
I've been thinking of doing something similar myself, but I'm trying to find a more efficient method for the manual work (in Audacity). One method could be to just use the label-function in Audacity, then find a way to extract/export all of the label-data (from/to/labelname). Another (more basic) improvement to the current workflow could be to link a hotkey to a script that adds track-selection start/end-time to the clipboard. Anyways, great video! There's so many tasks that (in large parts) can be be automated :)
I just found your channel. Great and really helpful content, thanks for providing it 🙂. Subscribed directly, of course.
this is so cool! Python can do so many things. Happy to know Python can edit videos and audio. Thanks!
Glad you like it
Hey, Nice work! Really helpful for me :D i really want to thank you for the help!
this channel deserves more subscribers
thanks :)
It's very helpful video, will be trying it for sure.
Loved it Wass willing to make it myself, but you made it easier....👌👌👌
Thanks :)
@@patloeber Welcome ;)
Came for the video editing tips. Reminded me that I majored in deep learning, lol
Thanks for the great content. Thanks for sharing 😃🇨🇴
This is insane
Thank You, now I'm gonna go and make a Video Editor in python with GUI - Quite a bit of work :)
Great video! Is there a way to play the video and save the cuts by pressing a button (start/stop). Then just running this function. Thanks
DUDE, I was wondering if this was possible :)
I mean wow, this is better than any video editor, freaking awesome....!!!!!!!!!!!!!!!!!!!!!
yeah it's cool :)
Thanks for the lovely video! I have one question not directly related to the content presented, but as you are demoing your screencasts I think this is still relevant: How are you recording your screencasts - before cutting them? For me especially relevant would be appropriate command line switches for ffmgeg under Linux.
I have only done screen grabbing on Linux under X11. On Wayland, things will be different. I once did a capture of a 1280×720 region using a command like ffmpeg -f x11grab -video_size 1280:720 -framerate 25 -i :0.0+«offset» -vcodec png «dir»/frame%04d.png
is there a library to visualise all of this I mean to give it a visual interface like in classic editing software?
Awesome, didnt even think about this possibility! Maybe I try to edit videos with Python :D
Go for it!
This is a great tutorial..
Thanks :)
@PythonEngineer do I see Tech with Tim and Corey Schafer in your subscription. 😃
Yes 😄
Ahahha okay, that was a funny disclaimer, "I don't use it myself for my KZhead videos, but you could." Ahahahaha that just tickled me.
I might use this approach to add a standard preamble, to trim dead space to make the video fit the target duration (good for YT #shorts), add a trailer for the next episode as required. I think a standard GUI editor would be my go to for normal work. If I'm talking, make an error and reshoot that segment, this isn't going to handle it well. Similar if I record an interview, it might take an hour of shooting but need to be condensed to 15 minutes. Python can probably be made to drive Premiere Pro too, it can drive Photoshop.
Nice video bro 🤙🤙
thanks!
Hi with python pillow can it improve the video image quality or is it just pictures it does thankyou
Great info!
Glad it was helpful!
pretty nice! 🤗
Great man
Thankyou so much :)
thanks!
Amazing!
thanks!
i want to add an audio test.mp3 of 2 secs to a video file of test.mp4 of 15 secs at multiple places like at 4th, 8 th , 12 th. what would be the approach?
Beautiful 👍. Hey, I have some questions. Where do I reach out to you?
KZhead or Discord
thanks
I have a database of images and text and can't find a no-code bulk automator for making video shorts. Canva came out with one but you can't change the background. I've never used code... will this be too hard for me???
Can we add an audio file that plays when with text overlay
I want to add a looping gif over music with out making a million cuts. Is that possible?
--I'm not sure why __name__ is italicized and missing an _ on the right and left side in this comment, but I didn't write it like that. --What does if __name__ == '__main__': edit_video(loadtitle, savetitle, cuts) --do? --What is "libx264"? Does the video have to be ".mov" to ".mp4" or can it be ".mp4" to ".mp4"? Videoquality is "24", what happens if I increase/decrease that number? Instead of having title separate from loadtitle and savetitle, could I have loadtitle and savetitle be paths? What are cut[0] and cut[1] in for cut in cuts: clip = video.subclip(cut[0], cut[1]) clips.append(clip) --? Are they individual cuts or are they start of a number of cuts? If I have cuts = [('00:01:00.00', '00:00:02.00'), ('00:00:05.00', 00:00:07.00')] is it for cut in cuts: clip = video.subclip(cut[0], cut[4]) clips.append(clip) --or for cut in cuts: clip = video.subclip(cut[0], cut[1], cut[3], cut[4]) clips.append(clip) --? Also, I haven't been able to run it fully yet, but it seems that for Windows txt = mpy.TextClip('Please Subscribe!', font='Courier') fontsize=120, color='white', bg_color='gray35' txt = txt.set_position(('center', 0.6), relative=True) txt = txt.set_start((0, 3)) # (min, s) txt = txt.set_duration(4) txt = txt.crossfadein(0.5) txt = txt.crossfadeout(0.5) ... final_clip.write_videofile(savetitle, threads=4, fps=24) codec=vcodec, preset=compression, ffmpeg_params=["-crf", videoquality]) --needs to be rewritten as txt = mpy.TextClip('Please Subscribe!', font='Courier') txt = txt.mpy.TextClip(fontsize=120, color='white', bg_color='gray35') txt = txt.set_position(('center', 0.6), relative=True) txt = txt.set_start((0, 3)) # (min, s) txt = txt.set_duration(4) txt = txt.crossfadein(0.5) txt = txt.crossfadeout(0.5) ... final_clip.write_videofile(savetitle, threads=4, fps=24, codec=vcodec, preset=compression, ffmpeg_params=["-crf", videoquality]) --to avoid an unexpected indent error.
Hi, I'm a student. I want to know how to clip the photos into a vedio with python like a function of the photo album and add some special effects when a photo changes. Thank you for your replying.
There might be a simpler way, but at least you can save the video frames as images, embed the photo to the correpsonding images and export the video.
I saw that Davinci Resolve has Python Scripting support. Have you tried it?
no I haven't but that's interesting
@@patloeber Would be nice for a video perhaps? ;).
I did a quick search, and it seems it has trouble with newer versions of Python.
@@lawrencedoliveiro9104 oh. Pitty…
Out of curiosity, why did you stop using this method and what software do you use otherwise?. Thanks.
It's not super convenient and limited in the features. You cannot do fancy video transitions or something. I switched to Davinci Resolve afterwards
@@patloeber thanks for the info. The problem that I have is that I can not find a good video editor that is parametric. I know you can use JS with Premiere, but it is limited.
There is also “melt”, which uses the MLT framework. You can drive that via an XML control file.
How do we know the cut times? What if we have so many cut times? I am not sure, whether this works for my purpose.
Yes as I said, it is not suited for every workflow. You have to select the cut times manually by going through the video or audio line
@@patloeber true, ty. May be in future there will be an AI that decides this for u.🙃
@@Kig_Ama Yes, I think this is already possible (even without AI just by analyzing the sound intensity). But for my own recordings this task is more difficult because sometimes I don't talk but still write code on the screen. It's hard to detect this...
@@patloeber Amazing!
Python is Every Think
Guys don't you feel weird while editing on python, I mean there should be a GUI there no ?
cool. but like... nooooooo
ı'cant see ui? but nice click bait