Permalink
Browse files

add function video_image

  • Loading branch information...
sdpython committed Jan 6, 2018
1 parent 237e0a3 commit 4a60cf1d16ed6c00d3bba688e4ced6df6ea2a3e9
Binary file not shown.
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
"""
@brief test log(time=1000s)
Duraction is around a few seconds but the test needs to be run
at the end of the series of unitests as it interferes
with the notebook unittesting (it uses Popen too).
"""
import sys
import os
import unittest
try:
import pyquickhelper
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper
try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import get_temp_folder, ExtTestCase
from src.code_beatrix.faq.faq_video import video_save, video_image
class TestVideoImage(ExtTestCase):
def test_video_image(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_video_image")
img = os.path.join(temp, '..', 'data', 'GastonLagaffe_1121.jpg')
vid = video_image(img, duration=60)
exp = os.path.join(temp, "courte2x.mp4")
video_save(vid, exp, fps=20)
self.assertExists(exp)
if __name__ == "__main__":
unittest.main()
@@ -6,15 +6,20 @@
from contextlib import redirect_stdout, redirect_stderr
import io
import os
import numpy
from pytube import YouTube
from imageio import imsave
import moviepy.audio.fx.all as afx
import moviepy.video.fx.all as vfx
from moviepy.video.VideoClip import ImageClip
from moviepy.audio.AudioClip import AudioArrayClip, CompositeAudioClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.compositing.concatenate import concatenate_videoclips
from moviepy.audio.AudioClip import concatenate_audioclips
from .moviepy_context import AudioContext, VideoContext
from PIL import Image
from skimage.io._plugins.pil_plugin import pil_to_ndarray
##########
# youtube
@@ -434,3 +439,22 @@ def check_duration(video):
if mirrory:
video = video.fx(vfx.mirror_y)
return video
def video_image(image_or_file, **kwargs):
"""
Creates a :epkg:`ImageClip`.
Créé une vidéo à partir d'une image.
@param image_or_file image or file
@param kwargs additional parameters for :epkg:`ImageClip`
@return :epkg:`ImageClip`
"""
if isinstance(image_or_file, (str, numpy.ndarray)):
return ImageClip(image_or_file, **kwargs)
elif isinstance(image_or_file, Image.Image):
img = pil_to_ndarray(image_or_file)
return ImageClip(img, **kwargs)
else:
raise TypeError(
"Unable to create a video from type {0}".format(type(image_or_file)))

0 comments on commit 4a60cf1

Please sign in to comment.