Back to Top

Python MoviePy Tutorial

Program 1 : Combine Two Audio Files in to One Audio File using Python MoviePy || Concatenate Two Audio Files

 

# combine two audio files into one using python moviepy

from moviepy.editor import concatenate_audioclips, AudioFileClip

input_audio1 = AudioFileClip("audio1.mp3")
input_audio2 = AudioFileClip("audio2.mp3")

final_audio = concatenate_audioclips([input_audio1, input_audio2])
final_audio.write_audiofile("output.mp3")

 

Program 2 : Adding Background Music to your Video using Python MoviePy Audio Length is greater than Video Length

 

# Adding Background Music to Video - Audio Length > Video Length

from moviepy.editor import AudioFileClip, VideoFileClip, CompositeAudioClip

input_video_clip = VideoFileClip("video.mp4")
input_audio_clip = AudioFileClip("audio.mp3")

duration = input_video_clip.duration
temp_audio_clip = input_audio_clip.set_duration(duration)
final_audio_clip = CompositeAudioClip([temp_audio_clip])

final = input_video_clip.set_audio(final_audio_clip)
final.write_videofile("output.mp4",fps=60)

 

Program 3 : Cut Audio File in to Sub clips using Python MoviePy Editor || Create Sub clip of an audio file

# cut audio in to sub clip and store them using python moviepy

from moviepy.editor import AudioFileClip

input_audio_clip = AudioFileClip("audio1.mp3")

final_clip = input_audio_clip.subclip(30, 60)
final_clip.write_audiofile("output.mp3")

 

Program 4 : Cut video in to sub clip and store them using python moviepy


# Cut video in to sub clip and store them using python moviepy

from moviepy.editor import VideoFileClip

input_video = VideoFileClip("video.mp4")

final_clip = input_video.subclip(0, 29)

final_clip.write_videofile("output.mp4", fps=60)


Write A Program To Take Two Inputs Day, Month And Then Calculate Which Day Of The Year

 Write A Program To Take Two Inputs Day, Month And Then Calculate Which Day Of The Year

 

# Write A Program To Take Two Inputs Day, Month And Then Calculate Which Day Of The Year

day = int(input("Enter the day : "))
month = int(input("Enter the month : "))
if day > 30 or month > 12:
print("Invalid day and month !!!")
else:
print("Its ", (month - 1) * 30 + day, " day of the year")

 

Write Python Program Calculate Product Multiplying Numbers Given Tuple

 Write Python Program Calculate Product Multiplying Numbers Given Tuple

 

# write a python program to calculate the product multiplying all the numbers of a given tuple.

tuple_length = int(input("Enter tuple length : "))
my_tuple = ()
for x in range(tuple_length):
temp = float(input("Enter tuple item : "))
my_tuple += (temp,)

product = 1
for item in my_tuple:
product = product * item

print("Product of tuple items is : ", product)

 

 

 

write a python program to get the python version you are using

write a python program to get the python version you are using

>>>
>>> import os
>>> os.system("python --version")
Python 3.8.5
0
>>>

 

Another Method

>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)
>>>

 

Print only version

import sys

print(sys.version_info[0], sys.version_info[1]) 


Get Version Using Platform Library

>>>
>>> import platform
>>> print(platform.python_version())
3.8.5
>>>


 

















write a program to access the class method define a variable inside method and print its value after accessing it

write a program to access the class method. define a variable inside method and print its value after accessing it.


class my_class:
def __init__(self):
self.variable = None

def set_variable(self, x):
self.variable = x

def get_variable(self):
return self.variable


my_object = my_class()
my_object.set_variable("hello")
print(my_object.get_variable())

 

Integer Access


class my_class:
def __init__(self):
self.variable = None

def set_variable(self, x):
self.variable = x

def get_variable(self):
return self.variable


my_object = my_class()
my_object.set_variable(25)
print(my_object.get_variable())



BESbswyBESbswyBESbswyBESbswyBESbswyBESbswy