How I Edit My Videos With Python - Python Task Automation

2024 ж. 19 Мам.
72 809 Рет қаралды

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!!

    @yuvrajsingh-gm6zk@yuvrajsingh-gm6zk2 ай бұрын
  • 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.

    @markusbuchholz3518@markusbuchholz35183 жыл бұрын
    • Thanks so much for the kind words Markus!

      @patloeber@patloeber3 жыл бұрын
    • @@patloeber Good luck!

      @markusbuchholz3518@markusbuchholz35183 жыл бұрын
  • Straight to the point and just mind blowingly well explained.

    @thedebapriyakar@thedebapriyakar2 жыл бұрын
    • glad you like it!

      @patloeber@patloeber2 жыл бұрын
  • Thank you for sharing this! Love all your video! It's very informative!!!

    @brendensong8000@brendensong80002 жыл бұрын
  • 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.

    @Micetticat@Micetticat3 жыл бұрын
  • That's it i looking for. Awesome Bro !

    @rajukani100@rajukani1003 жыл бұрын
    • Thank you!

      @patloeber@patloeber3 жыл бұрын
  • Very useful for Minecraft ASMR mining blocks and putting blocks. I know that this is applicable in a lot of situations

    @vegaarcturus509@vegaarcturus509 Жыл бұрын
  • 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 :)

    @jrnpaulsen9926@jrnpaulsen9926 Жыл бұрын
  • I just found your channel. Great and really helpful content, thanks for providing it 🙂. Subscribed directly, of course.

    @ThorstenMueller@ThorstenMueller Жыл бұрын
  • this is so cool! Python can do so many things. Happy to know Python can edit videos and audio. Thanks!

    @terraflops@terraflops3 жыл бұрын
    • Glad you like it

      @patloeber@patloeber3 жыл бұрын
  • Hey, Nice work! Really helpful for me :D i really want to thank you for the help!

    @quagmirev252@quagmirev252 Жыл бұрын
  • this channel deserves more subscribers

    @sikkavilla3996@sikkavilla39963 жыл бұрын
    • thanks :)

      @patloeber@patloeber3 жыл бұрын
  • It's very helpful video, will be trying it for sure.

    @saralgyaan@saralgyaan Жыл бұрын
  • Loved it Wass willing to make it myself, but you made it easier....👌👌👌

    @abhimanyunegi4382@abhimanyunegi43823 жыл бұрын
    • Thanks :)

      @patloeber@patloeber3 жыл бұрын
    • @@patloeber Welcome ;)

      @abhimanyunegi4382@abhimanyunegi43823 жыл бұрын
  • Came for the video editing tips. Reminded me that I majored in deep learning, lol

    @brandonallen2301@brandonallen23012 жыл бұрын
  • Thanks for the great content. Thanks for sharing 😃🇨🇴

    @JuanGabrielOyolaCardona@JuanGabrielOyolaCardona2 жыл бұрын
  • This is insane

    @ClashBaseDeveloper@ClashBaseDeveloper8 ай бұрын
  • Thank You, now I'm gonna go and make a Video Editor in python with GUI - Quite a bit of work :)

    @WebStacks500@WebStacks5007 ай бұрын
  • 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

    @wassyppp@wassyppp2 жыл бұрын
  • DUDE, I was wondering if this was possible :)

    @RozBizMedia@RozBizMedia8 ай бұрын
  • I mean wow, this is better than any video editor, freaking awesome....!!!!!!!!!!!!!!!!!!!!!

    @shantanudhiman5263@shantanudhiman52632 жыл бұрын
    • yeah it's cool :)

      @patloeber@patloeber2 жыл бұрын
  • 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.

    @christiangeng6070@christiangeng60702 жыл бұрын
    • 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

      @lawrencedoliveiro9104@lawrencedoliveiro9104 Жыл бұрын
  • is there a library to visualise all of this I mean to give it a visual interface like in classic editing software?

    @kamel3d@kamel3d Жыл бұрын
  • Awesome, didnt even think about this possibility! Maybe I try to edit videos with Python :D

    @LanaDominkovic@LanaDominkovic2 жыл бұрын
    • Go for it!

      @patloeber@patloeber2 жыл бұрын
  • This is a great tutorial..

    @CodeWithTomi@CodeWithTomi3 жыл бұрын
    • Thanks :)

      @patloeber@patloeber3 жыл бұрын
  • @PythonEngineer do I see Tech with Tim and Corey Schafer in your subscription. 😃

    @lukajeliciclux3074@lukajeliciclux30743 жыл бұрын
    • Yes 😄

      @patloeber@patloeber3 жыл бұрын
  • 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.

    @JJSeattle@JJSeattle2 жыл бұрын
  • 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.

    @oneeyedphotographer@oneeyedphotographerАй бұрын
  • Nice video bro 🤙🤙

    @saurrav3801@saurrav38013 жыл бұрын
    • thanks!

      @patloeber@patloeber3 жыл бұрын
  • Hi with python pillow can it improve the video image quality or is it just pictures it does thankyou

    @azarmahmood1421@azarmahmood14212 жыл бұрын
  • Great info!

    @todologic@todologic2 жыл бұрын
    • Glad it was helpful!

      @patloeber@patloeber2 жыл бұрын
  • pretty nice! 🤗

    @CustAndCode@CustAndCode Жыл бұрын
  • Great man

    @hishamsomroz6913@hishamsomroz69133 жыл бұрын
  • Thankyou so much :)

    @rachit6099@rachit60993 жыл бұрын
    • thanks!

      @patloeber@patloeber3 жыл бұрын
  • Amazing!

    @hoclaptrinh882@hoclaptrinh8823 жыл бұрын
    • thanks!

      @patloeber@patloeber3 жыл бұрын
  • 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?

    @narendrarao5989@narendrarao59892 жыл бұрын
  • Beautiful 👍. Hey, I have some questions. Where do I reach out to you?

    @abuazfaar3662@abuazfaar36623 жыл бұрын
    • KZhead or Discord

      @patloeber@patloeber3 жыл бұрын
  • thanks

    @muhammad_talha@muhammad_talha3 жыл бұрын
  • 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???

    @seanivore@seanivore7 ай бұрын
  • Can we add an audio file that plays when with text overlay

    @future9728@future97282 жыл бұрын
  • I want to add a looping gif over music with out making a million cuts. Is that possible?

    @GoodBoyDanny@GoodBoyDanny3 жыл бұрын
  • --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.

    @errorhostnotfound1165@errorhostnotfound11653 жыл бұрын
  • 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.

    @user-yz8yn4zc2i@user-yz8yn4zc2i3 жыл бұрын
    • 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.

      @yusun5722@yusun57222 жыл бұрын
  • I saw that Davinci Resolve has Python Scripting support. Have you tried it?

    @todologic@todologic2 жыл бұрын
    • no I haven't but that's interesting

      @patloeber@patloeber2 жыл бұрын
    • @@patloeber Would be nice for a video perhaps? ;).

      @todologic@todologic2 жыл бұрын
    • I did a quick search, and it seems it has trouble with newer versions of Python.

      @lawrencedoliveiro9104@lawrencedoliveiro9104 Жыл бұрын
    • @@lawrencedoliveiro9104 oh. Pitty…

      @todologic@todologic Жыл бұрын
  • Out of curiosity, why did you stop using this method and what software do you use otherwise?. Thanks.

    @todologic@todologic2 жыл бұрын
    • 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@patloeber2 жыл бұрын
    • @@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.

      @todologic@todologic2 жыл бұрын
    • There is also “melt”, which uses the MLT framework. You can drive that via an XML control file.

      @lawrencedoliveiro9104@lawrencedoliveiro9104 Жыл бұрын
  • 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.

    @Kig_Ama@Kig_Ama3 жыл бұрын
    • 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@patloeber3 жыл бұрын
    • @@patloeber true, ty. May be in future there will be an AI that decides this for u.🙃

      @Kig_Ama@Kig_Ama3 жыл бұрын
    • @@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@patloeber3 жыл бұрын
    • @@patloeber Amazing!

      @Kig_Ama@Kig_Ama3 жыл бұрын
  • Python is Every Think

    @AbdifatahNadir-fk7lc@AbdifatahNadir-fk7lc9 ай бұрын
  • Guys don't you feel weird while editing on python, I mean there should be a GUI there no ?

    @-raiwzo@-raiwzo2 жыл бұрын
  • cool. but like... nooooooo

    @matthewpaquette@matthewpaquette2 жыл бұрын
  • ı'cant see ui? but nice click bait

    @suretmeyenateistoc4252@suretmeyenateistoc4252 Жыл бұрын
KZhead