Permalink
Browse files

add function video modification

  • Loading branch information...
sdpython committed Jan 2, 2018
1 parent 2ced014 commit 16ea91a85c48459aa3efabb0811debfaf85adb50
@@ -35,6 +35,7 @@
:epkg:`Mary Poppins` du décor dans lequel elle danse.
.. image:: image_mary_poppins_12_0.jpeg
:width: 400
Ce procédé s'appuie sur du :epkg:`deep learning` et je ne pense pas
que cette fonctionnalité soit accessible depuis un logiciel de
@@ -78,6 +78,7 @@
epkg_dictionary['gif'] = 'https://fr.wikipedia.org/wiki/Graphics_Interchange_Format'
epkg_dictionary[
'Mary Poppins'] = 'https://fr.wikipedia.org/wiki/Mary_Poppins_(film,_1964)'
epkg_dictionary['moviepy'] = 'https://zulko.github.io/moviepy/'
epkg_dictionary['OpenShot'] = 'https://www.openshot.org/'
epkg_dictionary['pytube'] = 'https://github.com/nficano/pytube'
epkg_dictionary['SciTe'] = 'http://www.scintilla.org/SciTE.html'
@@ -46,7 +46,7 @@
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, ExtTestCase
from src.code_beatrix.faq.faq_video import video_save, video_extract_video, video_compose, video_concatenate
from src.code_beatrix.faq.faq_video import video_save, video_extract_video, video_compose, video_concatenate, video_modification
class TestVideo(ExtTestCase):
@@ -83,6 +83,18 @@ def test_compose_avideo(self):
video_save(vid3, exp)
self.assertExists(exp)
def test_modify_avideo(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_video_modification")
vid = os.path.join(temp, '..', 'data', 'videxa.mp4')
vid2 = video_modification(vid, speed=2., mirrory=True, mirrorx=True)
exp = os.path.join(temp, "courte2x.mp4")
video_save(vid2, exp)
self.assertExists(exp)
if __name__ == "__main__":
unittest.main()
@@ -9,6 +9,7 @@
from pytube import YouTube
from imageio import imsave
import moviepy.audio.fx.all as afx
import moviepy.video.fx.all as vfx
from moviepy.audio.AudioClip import AudioArrayClip, CompositeAudioClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.compositing.concatenate import concatenate_videoclips
@@ -328,3 +329,41 @@ def video_concatenate(video_or_files, **kwargs):
for _ in ctx:
_.__exit__()
return res
def video_modification(new_video, volumex=1., resize=1., speed=1.,
mirrorx=False, mirrory=False, method=None):
"""
Modifies a video.
Modifie une vidéo.
@param volumex multiplies the sound
@param speed speed of the sound
@param resize resize
@param mirrorx mirror x
@param mirrory mirror y
@param method method used to resize
@return new video
"""
def check_duration(video):
if video.duration is None:
raise ValueError('video duration should not be None')
with VideoContext(new_video) as video:
if speed:
check_duration(video)
dur = video.duration
video = video.fl_time(lambda t: t * speed)
video = video.set_duration(dur / speed)
if volumex != 1.:
video = video.fx(vfx.volumex, volumex)
if resize != 1.:
if method is not None:
video = video.fx(vfx.resize, resize)
else:
video = video.fx(vfx.resize, resize, method=method)
if mirrorx:
video = video.fx(vfx.mirror_x)
if mirrory:
video = video.fx(vfx.mirror_y)
return video

0 comments on commit 16ea91a

Please sign in to comment.