Skip to content

Commit 9dc8028

Browse files
committed
Merge branch 'master' of github.com:anshulkhare7/PythonUtils
2 parents 0f0d318 + be2d695 commit 9dc8028

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1+
2+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Twitter](https://img.shields.io/twitter/follow/_anshulkhare?style=social)](https://twitter.com/_anshulkhare)
23

34
## Python Utils
45

@@ -17,4 +18,6 @@ Some useful python code snippets and utilities.
1718

1819
[Snap7](https://github.com/anshulkhare7/PythonUtils/blob/master/snap7) - Snap7 is a python library to connect to Siemens PLCs.
1920

20-
[Merge PDF](https://github.com/anshulkhare7/PythonUtils/blob/master/mergePDF.py) - Merge PDF files using PyPDF2 package. Install with `pip install pypdf2`. Based on [this.](https://realpython.com/pdf-python/). Requires python 3.8.
21+
[Merge PDF](https://github.com/anshulkhare7/PythonUtils/blob/master/mergePDF.py) - Merge PDF files using PyPDF2 package. Install with `pip install pypdf2`. Based on [this.](https://realpython.com/pdf-python/). Requires python 3.8.
22+
23+
[Convert Audio to Video](https://github.com/anshulkhare7/PythonUtils/blob/master/audio2video.py) - Convert audio file to video file.

audio2video.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from moviepy.editor import *
2+
from os import listdir
3+
from os.path import isfile, join
4+
5+
def convert(inDir, imagePath, outDir):
6+
7+
onlyfiles = [f for f in listdir(inDir) if isfile(join(inDir, f))]
8+
9+
for mp3File in onlyfiles:
10+
if(mp3File.endswith(".mp3")):
11+
filePath = inDir + mp3File
12+
audio = AudioFileClip(filePath)
13+
clip = ImageClip(imagePath).set_duration(audio.duration)
14+
fileName = outDir + os.path.splitext(mp3File)[0] + '.mp4'
15+
clip = clip.set_audio(audio)
16+
clip.write_videofile(fileName, fps=0.1)
17+
18+
def joinVideo(inputdirectory):
19+
20+
onlyfiles = [f for f in listdir(inputdirectory) if isfile(join(inputdirectory, f))]
21+
22+
clips = []
23+
for videofile in onlyfiles:
24+
if(videofile.endswith(".mp4")):
25+
filepath = inputdirectory + videofile
26+
clip = VideoFileClip(filepath)
27+
clips.append(clip)
28+
29+
final_clip = concatenate_videoclips(clips)
30+
final_clip.write_videofile(inputdirectory+'joined-video.mp4')
31+
32+
if __name__=="__main__":
33+
inDir = r"C:\Users\anshul\Documents\\"
34+
imagePath = r"C:\Users\anshul\Documents\myimage.jpg"
35+
outDir = r"C:\Users\anshul\Documents\\"
36+
convert(inDir, imagePath, outDir)
37+
joinVideo(outDir)

0 commit comments

Comments
 (0)