Permalink
Browse files

add function video_text, video_image

  • Loading branch information...
sdpython committed Jan 7, 2018
1 parent 4a60cf1 commit f77ddac6e4402921d2496696ed5babff6054adb6
@@ -73,12 +73,20 @@ Video
.. autosignature:: code_beatrix.faq.faq_video.video_extract_video
.. autosignature:: code_beatrix.faq.faq_video.video_image
.. autosignature:: code_beatrix.faq.faq_video.video_modification
.. autosignature:: code_beatrix.faq.faq_video.video_replace_sound
.. autosignature:: code_beatrix.faq.faq_video.video_position
.. autosignature:: code_beatrix.faq.faq_video.video_remove_audio
.. autosignature:: code_beatrix.faq.faq_video.video_replace_audio
.. autosignature:: code_beatrix.faq.faq_video.video_save
.. autosignature:: code_beatrix.faq.faq_video.video_text
YouTube
+++++++
@@ -76,6 +76,7 @@
epkg_dictionary['deep learning'] = 'https://en.wikipedia.org/wiki/Deep_learning'
epkg_dictionary['fcn'] = 'https://github.com/wkentaro/fcn'
epkg_dictionary['gif'] = 'https://fr.wikipedia.org/wiki/Graphics_Interchange_Format'
epkg_dictionary['ImageClip'] = 'https://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html?highlight=imageclip#imageclip'
epkg_dictionary[
'Mary Poppins'] = 'https://fr.wikipedia.org/wiki/Mary_Poppins_(film,_1964)'
epkg_dictionary['moviepy'] = 'https://zulko.github.io/moviepy/'
@@ -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_replace_sound, video_extract_audio
from src.code_beatrix.faq.faq_video import video_save, video_replace_audio, video_extract_audio, video_remove_audio
class TestAudioVideo(ExtTestCase):
@@ -59,7 +59,8 @@ def test_extract_audio_video(self):
temp = get_temp_folder(__file__, "temp_video_audio")
vid = os.path.join(temp, '..', 'data', 'videxa.mp4')
aud = os.path.join(temp, '..', 'data', 'cartoon011.wav')
vid2 = video_replace_sound(vid, aud, loop=True, volumex=5.5, fadein=True,
vid = video_remove_audio(vid)
vid2 = video_replace_audio(vid, aud, loop=True, volumex=5.5, fadein=True,
t_end='00:00:05', speed=2.)
self.assertTrue(video_extract_audio(vid2) is not None)
exp = os.path.join(temp, "courte_audio.mp4")
@@ -46,20 +46,57 @@
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
from src.code_beatrix.faq.faq_video import video_save, video_image, video_position, video_resize
class TestVideoImage(ExtTestCase):
def test_video_image(self):
def test_video_image_position(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_video_image")
temp = get_temp_folder(__file__, "temp_video_position")
img = os.path.join(temp, '..', 'data', 'GastonLagaffe_1121.jpg')
vid = video_image(img, duration=60)
exp = os.path.join(temp, "courte2x.mp4")
vid = img = video_image(img, duration=60, zoom=(200, 200))
exp = os.path.join(temp, "courte.mp4")
video_save(vid, exp, fps=20)
self.assertExists(exp)
exp = os.path.join(temp, "courte05.mp4")
vid = video_position(img, (0.5, 0.5), relative=True)
video_save(vid, exp, fps=20)
self.assertExists(exp)
exp = os.path.join(temp, "courtecb.mp4")
vid = video_position(img, ('center', 'bottom'), relative=True)
video_save(vid, exp, fps=20)
self.assertExists(exp)
exp = os.path.join(temp, "courtefct.mp4")
vid = video_position(img, lambda t: (t * 0.1, t * 0.2), relative=True)
video_save(vid, exp, fps=20)
self.assertExists(exp)
def test_video_image_resize(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_video_resize")
img = os.path.join(temp, '..', 'data', 'GastonLagaffe_1121.jpg')
vid = img = video_image(img, duration=60, zoom=(200, 200))
exp = os.path.join(temp, "courte.mp4")
video_save(vid, exp, fps=20)
self.assertExists(exp)
exp = os.path.join(temp, "courtecb.mp4")
vid = video_resize(img, 0.5)
video_save(vid, exp, fps=20)
self.assertExists(exp)
exp = os.path.join(temp, "courtefct.mp4")
vid = video_resize(img, lambda t: max(0.1, 1 - 0.1 * t))
video_save(vid, exp, fps=20)
self.assertExists(exp)
@@ -0,0 +1,96 @@
# -*- 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_text, video_position, video_compose, video_image
class TestVideoText(ExtTestCase):
def test_video_text(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_video_text")
vid = img = video_text('boule')
exp = os.path.join(temp, "courte.mp4")
video_save(vid, exp, fps=20, duration=3)
self.assertExists(exp)
exp = os.path.join(temp, "courtefct.mp4")
vid = video_position(img, lambda t: (t * 0.1, t * 0.2), relative=True)
video_save(vid, exp, fps=20, duration=4)
self.assertExists(exp)
def test_video_text_image(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_video_text_image")
img = os.path.join(temp, '..', 'data', 'GastonLagaffe_1121.jpg')
vidimg = video_image(img, duration=5, opacity=200)
vidimg = video_position(vidimg, lambda t: (0, 0), relative=True)
text = video_text('boule', size=2., color=(
255, 0, 0, 128), background=(0, 255, 0, 100))
text = video_position(text, lambda t: (
t * 0.1, t * 0.2), relative=True)
comb = video_compose([vidimg, text], t1=[0, 1])
exp1 = os.path.join(temp, "courte_text.mp4")
exp2 = os.path.join(temp, "courte_laga.mp4")
video_save(text, exp1, fps=20, duration=5)
video_save(comb, exp2, fps=20, duration=5)
self.assertExists(exp1)
self.assertExists(exp2)
if __name__ == "__main__":
unittest.main()
View
@@ -5,7 +5,8 @@ set pythonexe="%1"
goto custom_python:
:default_value_python:
set pythonexe="c:\Python363_x64\python.exe"
set pythonexe="c:\Python364_x64\python.exe"
if not exist %pythonexe% set pythonexe="c:\Python363_x64\python.exe"
if not exist %pythonexe% set pythonexe="c:\Python36_x64\python.exe"
:custom_python:
@echo [python] %pythonexe%
Oops, something went wrong.

0 comments on commit f77ddac

Please sign in to comment.