Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 MoviePy Script to Add Audio in Video File in Command Line

Posted on February 12, 2023

Welcome folks today in this blog post we will be using the moviepy library to add the audio in video file in command line. All the full source code of the application is shown below.

 

 

Get Started

 

 

First of all we need to install the below moviepylibrary using the pip command as shown below

 

 

pip install moviepy

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

Python
1
2
3
4
5
6
7
8
9
10
# Import everything needed to edit video clips
from moviepy.editor import *
 
 
# loading video dsa gfg intro video
clip = VideoFileClip("video.mp4")
 
 
# getting only first 5 seconds
clip = clip.subclip(0, 5)

 

 

As you can see we are importing the moviepy library at the very top and then we are only taking the first 5 seconds of the input video using the subclip()method

 

 

1
2
3
4
5
6
7
8
# loading audio file
audioclip = AudioFileClip("allwell.mp3").subclip(0, 5)
 
# adding audio to the video clip
videoclip = clip.set_audio(audioclip)
 
# showing video clip
videoclip.ipython_display()

 

 

As you can see we are loading the audio clip using the AudioFileClip class of moviepy library and then we are only taking the first 5 seconds of the audio file using the subclip() method. And then we are inserting the audio inside the video file using the set_audio() method. And then we are saving the resultant video file with the audio as shown below

 

 

 

Recent Posts

  • Javascript PDFObject Library Example to Render PDF Document From URL or From Local PC in Browser
  • Node.js Express Project to Extract Text From Word (.DOCX) File & Save it as Text File in Browser
  • Node.js Tutorial to Parse & Extract Text & Tables From PDF Document Using pdfreader Library in Javascript
  • Node.js Express Project to Stream Local MP4 Video in Webpage Using Fetch API in Javascript
  • Node.js Express Tutorial to Read & Write Stream of Data From Buffer to Server Using Pipes in Browser
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme