コード例 #1
0
ファイル: scratch.py プロジェクト: BooDoo/animecommentbot
def compose_subs(vid_file, sub_file):
    vidclip = VideoFileClip(vid_file)
    # Scale effects to input video:
    sub_opts = make_sub_opts(vidclip)
    generator = partial(sub_generator, **sub_opts)

    txtclip = SubtitlesClip(sub_file, generator)
    return CompositeVideoClip([vidclip, txtclip.set_pos("top")])
コード例 #2
0
def burn(srtPath, videoPath, outputPath):
    d = compress_dimension_with_rotation_handled(videoPath)
    videoPath = convert_mov_to_mp4(videoPath)
    sub = SubtitlesClip(srtPath, generator)
    myvideo = VideoFileClip(videoPath, target_resolution=d)

    final = CompositeVideoClip([myvideo, sub.set_pos(('center', 'bottom'))])
    temp_output = os.path.splitext(outputPath)[0] + '.mp4'
    if not os.path.isfile(temp_output):
        final.write_videofile(temp_output, fps=myvideo.fps)
    convert_mp4_to_mov(temp_output)
コード例 #3
0
    def add_subtitle(self,subtitle_file,out_name):
        try:
            generator = lambda txt: TextClip(txt, font='Times', fontsize=16, color='white')
            subtitles = SubtitlesClip(subtitle_file, generator)

            self.result = CompositeVideoClip([self.clip, subtitles.set_pos(('center','bottom'))])

            self.result.write_videofile(out_name, fps=self.clip.fps)

            """
                Metoda "add_subtitle" permite adaugarea de subtitrari in cadrul videoclipurilor.

                Aceasta metoda se foloseste atat de biblioteca "Moviepy", aceasta punand la dispozitie
                metodele de scriere/citire a fisierelor video si clasa "SubtitlesClip" ce permite adaugarea
                subtitrarilor, dar se foloseste si de utilitarul "ImageMagickDisplay", acest utilitar
                realizand procesul de adaugare a textului peste fisierul video.

                Dupa cum se poate observa mai sus, putem sa selectam fontul textului, dimensiunea acestuia,
                dar si culoarea acestuia.
            """

        except:
            print("Something went wrong with add_subtitle method")
コード例 #4
0
from moviepy.editor import *
from moviepy.video.tools.subtitles import SubtitlesClip

generator = lambda txt: TextClip(txt, font='Arial', fontsize=24, color='black')

f = open('enresult.txt', 'r', encoding='utf-8')
Lines = f.readlines()

subs = []
count = 0
for line in Lines:
    subs.append(((count, count + 10), line))
    count += 10

subtitles = SubtitlesClip(subs, generator)

video = VideoFileClip("demo.mp4")
result = CompositeVideoClip([video, subtitles.set_pos(('center', 'bottom'))])

result.write_videofile("output.mp4")
コード例 #5
0
    clip_list = []
    for i in range(len(df)):
        dummy = ImageClip(df['Image'][i]).set_duration(df['time'][i])
        audioclip = AudioFileClip('Vid' + df['mp3s'][i])
        dummy = dummy.set_audio(audioclip)
        clip_list.append(dummy)

    video = clip_list[0]

    for z in range(1, len(clip_list)):
        video = concatenate([video, clip_list[z]], method="compose")

    video.write_videofile('test.mp4', fps=1)

    # substitiles
    generator = lambda txt: TextClip(
        txt, font='Arial', fontsize=60, color='black', bg_color='white')
    subtitles = SubtitlesClip("sub.srt", generator)

    video = VideoFileClip("test.mp4")
    result = CompositeVideoClip(
        [video, subtitles.set_pos(('center', 'bottom'))])

    result.write_videofile("file.mp4",
                           fps=video.fps,
                           temp_audiofile="temp-audio.m4a",
                           remove_temp=True,
                           codec="libx264",
                           audio_codec="aac")