module art.video

Inheritance diagram of code_beatrix.art.video

Short summary

module code_beatrix.art.video

Quelques questions d’ordre général autour du langage Python.

source on GitHub

Classes

class

truncated documentation

FontError

Raised when a font cannot be found.

Functions

function

truncated documentation

audio2wav

The sound is converted into wav and returned as an AudioArrayClip. Le son est converti au format …

audio_compose

Concatenates or superposes two sounds. Ajoute ou superpose deux sons.

audio_concatenate

Concatenates sounds. Met bout à bout des sons.

audio_extract_audio

Extracts a part of an audio. Extrait une partie du son. Uses subclip. …

audio_modification

Modifies a sound. Modifie un son.

audio_save

Saves as a sound. Enregistre un son dans un fichier. Uses write_audiofile. …

check

Checks a couple of functionality works. The test takes 5-6 seconds to download, 4-5 seconds to process the video. …

download_youtube_video

Downloads a video from youtube with pytube. Télécharge une vidéo depuis youtube avec pytube. …

video_compose

Concatenates or superposes two videos. Ajoute ou superpose deux vidéos.

video_concatenate

Concatenates videos. Met bout à bout des vidéos.

video_enumerate_frames

Enumerates frames from a video. Itère sur des images depuis une vidéo.

video_extract_audio

Returns the audio of a video. Retourne le son d’une vidéo.

video_extract_video

Extracts a part of a video. Extrait une partie de la vidéo. Uses subclip. …

video_frame

Creates a video from drawing or images. fct_frame can either be a function which draws a picture at time t or …

video_image

Creates a ImageClip. Créé une vidéo à partir d’une image.

video_load

Loads a video. Charge une vidéo.

video_modification

Modifies a video. Modifie une vidéo.

video_position

Modifies the position of a position. Modifie la position d’une video. Relies on function set_position. …

video_remove_audio

Returns the same video without audio. Retourne la même vidéo sans le son.

video_replace_audio

Replaces the sound of a video. Remplace la bande-son d’une vidéo.

video_resize

Resizes a video. Modifie la taille d’une video. Relies on function resize. …

video_save

Saves as a video or as a gif. Enregistre une vidéo dans un fichier. Uses write_videofile. …

video_save_image

Saves one image from a video. Enregistre une image extraite d’une vidéo.

video_text

Creates an image with text (ImageClip). Créé une image à partir de texte.

Documentation

Quelques questions d’ordre général autour du langage Python.

source on GitHub

exception code_beatrix.art.video.FontError[source]

Bases : Exception

Raised when a font cannot be found.

source on GitHub

code_beatrix.art.video.audio2wav(audio, duration=None, **kwargs)[source]

The sound is converted into wav and returned as an AudioArrayClip. Le son est converti au format wav.

Paramètres
  • audio – sound

  • duration – change the duration of the sound before converting it

  • kwargs – see to_soundarray

Renvoie

AudioArrayClip

source on GitHub

code_beatrix.art.video.audio_compose(audio_or_file1, audio_or_file2, t1=0, t2=None)[source]

Concatenates or superposes two sounds. Ajoute ou superpose deux sons.

Paramètres
  • audio_or_file1 – son 1

  • audio_or_file2 – son 2

  • t1 – start of the first sound

  • t2 – start of the second sound (or None to add it ad

Renvoie

new sound

Example:

from code_beatrix.art.video import audio_compose
son = audio_compose('son1.mp3', 'son2.mp3', 0, 10)

source on GitHub

code_beatrix.art.video.audio_concatenate(audio_or_files, **kwargs)[source]

Concatenates sounds. Met bout à bout des sons.

Paramètres
Renvoie

AudioClip

Example:

from code_beatrix.art.video import audio_concatenate
son = audio_concatenate('son1.mp3', 'son2.mp3')

source on GitHub

code_beatrix.art.video.audio_extract_audio(audio_or_file, ta=0, tb=None)[source]

Extracts a part of an audio. Extrait une partie du son. Uses subclip.

Paramètres
  • audio_or_file – string or AudioClip

  • ta – beginning

  • tb – end

Renvoie

VideoClip

Example:

from code_beatrix.art.video import audio_extract_audio
son = audio_extract_audio('son.mp3', '00:00:01', '00:00:02')

source on GitHub

code_beatrix.art.video.audio_modification(audio, loop_duration=None, volumex=1.0, fadein=False, fadeout=False, t_start=0, t_end=None, speed=1.0, keep_duration=False, wav=False)[source]

Modifies a sound. Modifie un son.

Paramètres
  • audio – sound

  • loop_duration – loops sound

  • volumex – multiplies the sound

  • fadein – decreases the volume of the first seconds

  • fadeout – decreases the volume of the last seconds

  • t_start – shorten the audio

  • t_end – shorten the audio

  • speed – speed of the sound

  • keep_duration – parameter to ft_time

Renvoie

new sound

source on GitHub

code_beatrix.art.video.audio_save(audio_or_file, filename, verbose=False, **kwargs)[source]

Saves as a sound. Enregistre un son dans un fichier. Uses write_audiofile.

Paramètres
  • audio_or_file – string or AudioClip

  • filename – save into this filename

  • verbose – logging or not

  • kwargs

    see write_audiofile

source on GitHub

code_beatrix.art.video.check(fLOG=None)[source]

Checks a couple of functionality works. The test takes 5-6 seconds to download, 4-5 seconds to process the video.

Paramètres

logging – function

source on GitHub

code_beatrix.art.video.download_youtube_video(tag, output_path=None, res='720p', mime_type='video/mp4', **kwargs)[source]

Downloads a video from youtube with pytube. Télécharge une vidéo depuis youtube avec pytube.

Paramètres
  • tag – tag of the youtube video to download

  • output_path – output path

  • mime_type – see youtube

  • res – see youtube

  • kwargs – see youtube

Renvoie

filename (relative to output_path)

Télécharger une vidéo sur YouTube

Le module pytube permet de télécharger une vidéo youtube. Chaque vidéo est disponible selon plusieurs format dont on récupère la liste avant de choisir qui correspond à celui voulu.

from pytube import YouTube
yt = YouTube('https://www.youtube.com/watch?v=tRFHXMQP-QU')
st = yt.streams
fil = st.filter(mime_type="video/mp4", res="720p")
fil.first().download()

source on GitHub

code_beatrix.art.video.video_compose(video_or_file1, video_or_file2=None, t1=0, t2=0, place=None, **kwargs)[source]

Concatenates or superposes two videos. Ajoute ou superpose deux vidéos.

Paramètres
  • video_or_file1 – vidéo 1 or list of video

  • video_or_file2 – vidéo 2

  • t1 – start of the first sound

  • t2 – start of the second sound (or None to add it ad

  • place – predefined placements

  • kwargs – additional parameters, sent to CompositeVideoClip

Renvoie

VideoClip

Example:

from code_beatrix.art.video import video_compose
vid = video_compose('video1.mp4', 'video2.mp4', '00:00:01', '00:00:04')

The first video defines the size of the final video. List of predefined placements:

  • h2: two videos side by side horizontally

  • v2: two videos side by side vertically

  • br: two videos, second is placed at the bottom right corner

zoom can be defined as a argument, it applies on the second video if place is defined and if there are two videos.

source on GitHub

code_beatrix.art.video.video_concatenate(video_or_files, **kwargs)[source]

Concatenates videos. Met bout à bout des vidéos.

Paramètres
Renvoie

VideoClip

source on GitHub

code_beatrix.art.video.video_enumerate_frames(video_or_file, folder=None, fps=10, pattern='images_%04d.jpg', clean=False, **kwargs)[source]

Enumerates frames from a video. Itère sur des images depuis une vidéo.

Paramètres
  • video_or_file – string or VideoClip

  • folder – where to exports the images or returns arrays if None

  • pattern – image names

  • fps – frames per seconds

  • clean – clean open processes after it is done

  • kwargs – arguments to iter_frames

Renvoie

iterator on arrays or files (see parameter folder)

Example:

form code_beatrix.art.video import video_enumerate_frames
vid = 'example.mp4')
for frame in video_enumerate_frames(vid, folder=temp):
    # ...

If clean is true, it calls clean_video.

source on GitHub

code_beatrix.art.video.video_extract_audio(video_or_file)[source]

Returns the audio of a video. Retourne le son d’une vidéo.

Paramètres

video_or_file – string or VideoClip

Renvoie

AudioClip

source on GitHub

code_beatrix.art.video.video_extract_video(video_or_file, ta=0, tb=None)[source]

Extracts a part of a video. Extrait une partie de la vidéo. Uses subclip.

Paramètres
  • video_or_file – string or VideoClip

  • ta – beginning

  • tb – end

Renvoie

VideoClip

Example:

from code_beatrix.faq_faq_video import video_extract_video
vid = video_extract_video('exemple.mp4', '00:00:01', '00:00:04')

source on GitHub

code_beatrix.art.video.video_frame(fct_frame, **kwargs)[source]

Creates a video from drawing or images. fct_frame can either be a function which draws a picture at time t or a list of picture names or a folder. Créé une vidéo à partir de dessins ou d’images. fct_frame est soit une fonction qui dessine chaque image à chaque instant t, une liste de noms d’images ou un répertoire.

Paramètres
  • fct_frame – function like def make_frame(t: float) -> numpy.ndarray, or list of images or folder name

  • kwargs – additional arguments for function make_frame

Renvoie

VideoClip

source on GitHub

code_beatrix.art.video.video_image(image_or_file, duration=None, zoom=None, opacity=None, **kwargs)[source]

Creates a ImageClip. Créé une vidéo à partir d’une image.

Paramètres
  • image_or_file – image or file

  • duration – duration or None if not known

  • zoom – applies a zoom on the image

  • opacity – opacity of the image (0 for transparent, 255 for opaque)

  • kwargs – additional parameters for ImageClip

Renvoie

ImageClip

If duration is None, it will be fixed when the image is composed with another one. The image remains wherever it is placed.

source on GitHub

code_beatrix.art.video.video_load(video_or_file)[source]

Loads a video. Charge une vidéo.

Paramètres

video_or_file – string or VideoClip

Renvoie

VideoClip

source on GitHub

code_beatrix.art.video.video_modification(video_or_file, volumex=1.0, resize=1.0, speed=1.0, mirrorx=False, mirrory=False)[source]

Modifies a video. Modifie une vidéo.

Paramètres
  • video_or_file – string or VideoClip

  • volumex – multiplies the sound

  • speed – speed of the sound

  • resize – resize

  • mirrorx – mirror x

  • mirrory – mirror y

Renvoie

new video

Example:

from code_beatrix.art.video import video_modification
vid = video_modification('video.mp4', speed=2., mirrory=True, mirrorx=True)

source on GitHub

code_beatrix.art.video.video_position(video_or_file, pos, relative=False)[source]

Modifies the position of a position. Modifie la position d’une video. Relies on function set_position.

Paramètres
Renvoie

VideoClip

This function moves the video inside another one. Therefore, it has no effect if the result of this video is composed. See function video_compose. Example:

from code_beatrix.art.video import video_image, video_position, video_compose, video_text

img = '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])

You can see an example of the video it produces in notebook video_notebook.

source on GitHub

code_beatrix.art.video.video_remove_audio(video_or_file)[source]

Returns the same video without audio. Retourne la même vidéo sans le son.

Paramètres

video_or_file – string or VideoClip

Renvoie

AudioClip

source on GitHub

code_beatrix.art.video.video_replace_audio(video_or_file, new_sound, loop=True)[source]

Replaces the sound of a video. Remplace la bande-son d’une vidéo.

Paramètres
  • video_or_file – string or VideoClip

  • new_sound – sound

  • loop – loop on the audio if not long enough

Renvoie

VideoClip

The list of available transformations is at: vfx. If parameter loop=True is specified, loop_duration becomes the duration of the video.

Example:

from code_beatrix.art.video import video_replace_sound
vid = video_replace_sound('video.mp4', 'son.mp3', loop=True, volumex=5.5, t_end='00:00:05')

source on GitHub

code_beatrix.art.video.video_resize(video_or_file, newsize)[source]

Resizes a video. Modifie la taille d’une video. Relies on function resize.

Paramètres
Renvoie

VideoClip

source on GitHub

code_beatrix.art.video.video_save(video_or_file, filename, verbose=False, duration=None, **kwargs)[source]

Saves as a video or as a gif. Enregistre une vidéo dans un fichier. Uses write_videofile.

Paramètres
  • video_or_file – string or VideoClip

  • filename – video saved into this filename

  • duration – overwrite duration, see method set_duration

  • verbose – logging or not

  • kwargs

    see write_videofile

Example:

from code_beatrix.faq_faq_video import video_extract_video, video_save
vid = video_extract_video('exemple.mp4', '00:00:01', '00:00:04')
video_save(vid, 'new_video.mp4')

source on GitHub

code_beatrix.art.video.video_save_image(video_or_file, t=None, filename=None, **kwargs)[source]

Saves one image from a video. Enregistre une image extraite d’une vidéo.

Paramètres
  • video_or_file – string or VideoClip

  • filename – if not None, saves the image into this file

  • kwargs – see save_frame

Renvoie

one image if filename is None

Example:

from code_beatrix.faq_faq_video import video_extract_video, video_save_image
vid = video_extract_video('exemple.mp4', '00:00:01', '00:00:04')
video_save_image(vid, filename='new_image.jpg', t=2)

source on GitHub

code_beatrix.art.video.video_text(text, font=None, fontsize=32, size=None, color=None, background=None, opacity=None, **kwargs)[source]

Creates an image with text (ImageClip). Créé une image à partir de texte.

Paramètres
  • text – text

  • color – color

  • font – police name

  • fontsize – font size

  • size – image size, None to get the smallest one which contains the text, a float to get size times this smallest size

  • background – background of the image

  • opacity – to overwrite the opacity, color and background should be 4-uple colors, the last number in (0, 0, 0, 255) represents the opacity

  • kwargs – additional parameters sent to video_image

Renvoie

ImageClip

If duration is None, it will be fixed when the image is composed with another one. The image remains wherever it is placed. The opacity is a number between 0 (transparent) and 255 (opaque). 0 means the image cannot be seen. The number can be set up for each pixel. By default, the image background is transparent (0). You can find many font at google/fonts or msfonts.

source on GitHub