Hi so we are using python to concatenate two videos together but we are facing issue to make the video visible on android and iOS device. By using this the second video which needs to be attached in the end, breaks down into small chunks and becomes distorted. I have attached the output of the video also. Watch the last five seconds of that video.
Output :
https://drive.google.com/file/d/1uwhUG03Q_92QmHiFd_VrecBwbWGTfwvP/view
we are using this :
# Import everything needed to edit video clips
from moviepy.editor import *
# loading video dsa gfg intro video
clip = VideoFileClip("v4.mp4")
# getting subclip as video is large
clip1 = clip.subclip(0, 5)
# loading video gfg
clipx = VideoFileClip("v3.mp4")
# getting subclip
clip2 = clipx.subclip(0, 3)
clip2.ipython_display(width = 480)
# clip list
clips = [clip1, clip2]
# concatenating both the clips
final = concatenate_videoclips(clips)
#final_clip.write_videofile("new.mp4")
# showing final clip
final.ipython_display(width = 480)
Related
I been trying this for a long time, but doesn't seem to work, I have tried using multiple codes, this is one of them that i'm currently using but doesn't seem to work:
from moviepy.editor import *
image = ImageClip("image.jpg")
audio = AudioFileClip("audio.mp3")
video = CompositeVideoClip([image.set_duration(audio.duration)])
video = video.set_audio(audio)
video.write_videofile("output.mp4", fps=24)
Try This way it should give u the desired result:
from moviepy.editor import *
# Import the audio(Insert to location of your audio instead of audioClip.mp3)
audio = AudioFileClip("audio.mp3")
# Import the Image and set its duration same as the audio (Insert the location
of your photo instead of photo.jpg)
clip = ImageClip("image.jpg").set_duration(audio.duration)
# Set the audio of the clip
clip = clip.set_audio(audio)
# Export the clip
clip.write_videofile("video.mp4", fps=24)
Title basically explains it. Trying to add audio to a video. I have a sequence of mp3 files that I want to play sequentially during the video. There're no errors or anything with the code but when I run the code theres still no audio in the video. Just a recreation of the old video with no audio (the original video doesnt have audio either).
video = VideoFileClip("finished_video.mp4")
title_clip = AudioFileClip("title.mp3")
audio_list = [title_clip]
for x in range(1, counter):
audio = AudioFileClip("p{}.mp3".format(x))
audio_list.append(audio)
video.set_audio(audio_list)
video.write_videofile("new_filename.mp4")
it works for me
from moviepy.editor import *
videoclip = VideoFileClip("sample.mp4")
audioclip = AudioFileClip("sample_audio.mp3")
new_audioclip = CompositeAudioClip([audioclip])
videoclip.audio = new_audioclip
videoclip.write_videofile("output.mp4")
use CompositeAudioClip to merge both files.
I had the same issue. It seems like set_audio() doesn't actually set it, but returns the new video combined with the audio.
This is the way I did it :
final_video = video.set_audio(audio_list)
final_video.write_videofile("new_filename.mp4")
Hope that helps !
I'm trying to make a program that downloads videos from TikTok and combines all the separate videos into one .mp4 file and moves the final video to a folder on my desktop. I've been able to make it download all the videos and when I watch the separate videos they play fine however when I combine the videos some of the videos are messed up and look like this but the audio is fine.
#slecting all .mp4 files
video_files = glob.iglob("*.mp4")
print(video_files)
clips = []
for clip in video_files: # For each mp4 file name
clips.append(VideoFileClip(clip)) # Store them as a VideoFileClip and add to the clips list
today = date.today()
final = concatenate_videoclips(clips) # Concatenate the VideoFileClips
final.write_videofile(f"{today}.mp4", codec="libx264")
#moving completed video to folder on desktop
shutil.move(f'{today}.mp4', '/Users/jacobmarrandio/Desktop/done_videos/')
thanks for any help
You want to ensure that all of your videos are of the same size before concatenating. Or, you could modify the smaller clips to have a black margin by filling up space by making this change:
final = concatenate_videoclips(clips, method='compose')
I am developing a program in Python which creates a video from an HTML file.
The HTML file may contain one animated GIF, and I need to keep the animation in the final video.
I already managed to extract each frame from the GIF, inspired by the method provided in the following GitHub Gist:
https://gist.github.com/revolunet/848913
import os
from PIL import Image
def extractFrames(inGif, outFolder):
frame = Image.open(inGif)
nframes = 0
while frame:
frame.save( '%s/%s-%s.gif' % (outFolder, os.path.basename(inGif), nframes ) , 'GIF')
nframes += 1
try:
frame.seek( nframes )
except EOFError:
break;
return True
extractFrames('ban_ccccccccccc.gif', 'output')
I replaced the GIF source in the HTML with each of these frames, and generated all the frames of the final video using PhantomJS.
Now, I need to get the duration of each frame in the source GIF file, in order to reproduce it in the corresponding frame of the video.
I found no way to achieve this in Python.
Is there a way to successfully always patch up any clips together in such a way that prevents weird glitches? I put together a .mp4 from smaller .mp4 files and I got a final video with weird glitches. I am running Python 3.6.1 on Windows 10 through Sublime Text 3. I used MoviePy to do the concatenation.
The code:
from moviepy.editor import VideoFileClip, concatenate_videoclips
import os.path
path = "C:/Users/blah/videos/out/"
cliparray = []
for filename in os.listdir(path):
cliparray.append(VideoFileClip(path + filename))
final_clip = concatenate_videoclips(cliparray)
final_clip.write_videofile(path + "concatenatedvideo.mp4", codec = "libx264")
The weird glitches:
One of the clips turns into a 3x3 grid of smaller clips.
Another has the audio not lined up with the video
Another is sped up faster than what was normal.
I had also glitch while concatenating different video clips. Some had different resolutions and that was making output video file with some sort of glitches. I fixed it with
final_clip = concatenate_videoclips(cliparray, method='compose')
Resulting output was without any glitch, but since they have different resolutions, the moviepy assigns highest resolution among video clips. To fix this you might just crop to same size.
from moviepy.editor import *
#load video 1 in to variable
video_1 = VideoFileClip('video1.mp4')
#load video 2 in to variable
video_2 = VideoFileClip('video2.mp4')
clips = [video_1, video_2]
# concatenating both the clips
final = concatenate_videoclips(clips,method='compose')
#writing the video into a file / saving the combined video
final.write_videofile("merged.mp4")