I wanted to edit a video, so I thought I would use moviepy, but I stumbled upon it, so I made a note.
mac Mojave python 3.6.8
The following is easy for the use case of "adding text or images using a video file as Input, and exporting the video file as Output".
pip install moviepy==1.0.0
##* Since we have confirmed the operation only with QuickTime Player on mac, it may not work unless it is here.
##moviepy version 1.0.A little tinkering with 0
# pip install -U git+https://github.com/mynkit/moviepy.git@mynkit/dev
sample_moviepy.py
import moviepy.editor as mp
AUDIOPATH = 'hogehoge.mp4'
IMGPATH = 'hogehoge.png'
video = mp.VideoFileClip(AUDIOPATH)
img = (mp.ImageClip(IMGPATH)
.set_start(1) #How many seconds in the video to display the image
.set_duration(10) #How many seconds to display the image
.resize(height=250) #Image height
.margin(right=0, top=0, opacity=0) #Margin size setting(No margin this time)
.set_pos(('right','bottom'))) #This time the image is displayed in the lower right
final = mp.CompositeVideoClip([video, img])
# mynkit/If you have pip install from dev`final.subclip(0,10).write_videofile('test.mp4')`Only need.
final.subclip(0,10).write_videofile(
"test.mp4",
codec='libx264',
audio_codec='aac',
temp_audiofile='temp-audio.m4a',
remove_temp=True
) # 0~Test up to 10 seconds.Output to mp4
Apparently, write_videofile doesn't seem to be various.
At the moment (2020/03/07), the latest version of MoviePy is 1.1.0
, but if you execute write_videofile as it is, the following error will occur.
AttributeError: 'NoneType' object has no attribute 'stdout'
Looking at issue938, it says that the version should be lowered to 1.0.0. For the time being, lower it as told.
There is certainly audio in the input file, and on jupyter
final.subclip(0,10).ipython_display(width=400)
Then I was able to preview the sound in the presence. However, there is no sound in the output file. ..
This was also described in issue876.
'-i',
'-i', described in moviepy / video / io / ffmpeg_writer.py The order of'-','-an'is wrong, and the correct order is
'-an','-i','-'`. This was supported by forked on my github.
By the way, even if this correspondence is not taken, it was played by QuickTime Player if only the following correspondence was made.
I thought that this was safe, but when I checked it with QuickTime Player on mac, there was still no sound ...
As mentioned in issue51 and issue820, with QuickTime Player In the argument of write_videofile to play
codec='libx264',
audio_codec='aac',
temp_audiofile='temp-audio.m4a',
remove_temp=True
Seems to be necessary. When I exported the video in this state, it worked.