Beispiel #1
0
def main(url, output):
    driver = webdriver.Chrome()
    remote_url = url
    driver.get(remote_url)
    
    png = chrome_takeFullScreenshot(driver)
    with open("website_image.png", 'wb') as f:
        f.write(png)

    driver.close()

    clip = ImageClip('website_image.png')
    
    video_width = int(clip.size[0] + 800)
    video_height = int(video_width/1.5)

    bg_clip = ColorClip(size=(video_width, video_height), color=[228, 220, 220])

    scroll_speed = 180
    total_duration = (clip.h - 800)/scroll_speed

    fl = lambda gf,t : gf(t)[int(scroll_speed*t):int(scroll_speed*t)+800,:]
    clip = clip.fl(fl, apply_to=['mask'])

    video = CompositeVideoClip([bg_clip, clip.set_pos("center")])
    video.duration = total_duration
    if not output.endswith('.mp4'):
        output += '.mp4'
    video.write_videofile(output, fps=26)
    os.remove('website_image.png')
Beispiel #2
0
    def thumbnail(self, time, dest, text):
        text_clip = VideoFile._generate_text(text)
        text_clip.duration = self.video_clip.duration
        video = CompositeVideoClip([self.video_clip, text_clip])
        video.duration = self.video_clip.duration

        try:
            video.save_frame(dest, t=(time + 1.0))
            logger.info("writing out thumbnail: {}", dest)
        except ValueError:
            logger.opt(
                exception=True).debug("Exception logged with debug level:")
Beispiel #3
0
def build_title(vid, title_start, title_end, texts, text_i, conf):
    t = texts[text_i]
    t = t.replace('\\n', '\n')

    clip = vid.subclip(title_start, title_end)

    text = TextClip(f"{t}", fontsize=conf.titlesize, font=conf.titlefont, color=conf.titlecolor).set_pos(("center", "bottom"))

    comp_clip = CompositeVideoClip([clip, text])
    comp_clip.duration = clip.duration

    return comp_clip, text_i + 1
Beispiel #4
0
    def edit_gif(self, info, gif_path, mark = None):
        out_file = str(uuid.uuid4()) + '.mp4'
        base = VideoFileClip(gif_path)

        if mark is None:
            wmark = self.txt_mark(base.size, info)
        else:
            wmark = Image.open(BytesIO(mark)).convert('RGBA')

        wmark = self.preparation_mark(info, wmark, base.size)   
        mark = ImageClip( np_arr(wmark) ).set_position(
            self.pos_conf(*base.size, *wmark.size, info))
        
        out = CompositeVideoClip([base, mark])
        out.duration = base.duration
        out.write_videofile(out_file, threads = None)
        return out_file, base.size
def main():
    image_clip_1 = ImageClip("planet.jpeg")
    image_clip_2 = ImageClip("ocean.jpeg")
    image_clip_3 = ImageClip("mountains.jpeg")
    background_music = AudioFileClip("Ticker.mp3").set_end(45)

    # TextClip template
    # clip = TextClip("Next paragraph",
    #                  font="Tahoma",
    #                  fontsize=350,
    #                  color="gray",
    #                  size=(1920, 1080),
    #                  bg_color="red")

    clip1 = TextClip("Sample text",
                     font='Courier',
                     fontsize=150,
                     color="white",
                     size=(1920, 1080))
    clip2 = TextClip("Next paragraph",
                     font="Tahoma",
                     fontsize=350,
                     color="gray",
                     size=(1920, 1080))
    clip3 = TextClip("It'll be awesome one day",
                     font="Times New Roman",
                     fontsize=90,
                     color="Yellow",
                     size=(1920, 1080))
    clip1_music = clip1.set_audio(background_music)

    #
    # cut_video(my_video, 33, 110, "cutted_video")
    # make_gif(my_video, 10, 12, 2)

    # making clip out of the text

    clip1.save_frame("text.png")
    clip1.duration = 5
    clip2.save_frame("text2.png")
    clip2.duration = 5
    clip3.save_frame("text3.png")
    clip3.duration = 5
    # clip.write_videofile("text.mov", codec="libx264", fps=25)

    # final_clip = concatenate_videoclips([clip1, clip2, clip3])
    # final_clip.write_videofile("final_clip.mp4", fps=25)

    alt_clip_1 = CompositeVideoClip([image_clip_1, clip1_music],
                                    size=(1920, 1080))
    alt_clip_1.duration = 15
    alt_clip_2 = CompositeVideoClip([image_clip_2, clip2], size=(1920, 1080))
    alt_clip_2.duration = 15
    alt_clip_3 = CompositeVideoClip([image_clip_3, clip3], size=(1920, 1080))
    alt_clip_3.duration = 15

    # alt_clip.write_videofile("image_clip.mp4", fps=25)
    # final_clip = concatenate_videoclips([alt_clip_1, alt_clip_2, alt_clip_3])
    final_clip = concatenate_videoclips([alt_clip_1, alt_clip_2, alt_clip_3])
    final_clip.write_videofile("final_clip.mp4", fps=25)
    print("Video length is {} minutes and it is {} fps".format(
        hours_in_video(final_clip), final_clip.fps))
Beispiel #6
0
def test_issue_334():
    # NOTE: this is horrible. Any simpler version ?
    last_move = None
    last_move1 = None

    lis = [
        (0.0, 113, 167, 47),
        (0.32, 138, 159, 47),
        (0.44, 152, 144, 47),
        (0.48, 193, 148, 47),
        (0.6, 193, 148, 47),
        (0.76, 205, 138, 55),
        (0.88, 204, 121, 63),
        (0.92, 190, 31, 127),
        (1.2, 183, 59, 127),
        (1.4, 137, 22, 127),
        (1.52, 137, 22, 127),
        (1.72, 129, 67, 127),
        (1.88, 123, 69, 127),
        (2.04, 131, 123, 63),
        (2.24, 130, 148, 63),
        (2.48, 130, 148, 63),
        (2.8, 138, 180, 63),
        (3.0, 138, 180, 63),
        (3.2, 146, 192, 63),
        (3.28, 105, 91, 151),
        (3.44, 105, 91, 151),
        (3.72, 11, 48, 151),
        (3.96, 5, 78, 151),
        (4.32, 4, 134, 1),
        (4.6, 149, 184, 48),
        (4.8, 145, 188, 48),
        (5.0, 154, 217, 48),
        (5.08, 163, 199, 48),
        (5.2, 163, 199, 48),
        (5.32, 164, 187, 48),
        (5.48, 163, 200, 48),
        (5.76, 163, 200, 48),
        (5.96, 173, 199, 48),
        (6.0, 133, 172, 48),
        (6.04, 128, 165, 48),
        (6.28, 128, 165, 48),
        (6.4, 129, 180, 48),
        (6.52, 133, 166, 48),
        (6.64, 133, 166, 48),
        (6.88, 144, 183, 48),
        (7.0, 153, 174, 48),
        (7.16, 153, 174, 48),
        (7.24, 153, 174, 48),
        (7.28, 253, 65, 104),
        (7.64, 253, 65, 104),
        (7.8, 279, 116, 80),
        (8.0, 290, 105, 80),
        (8.24, 288, 124, 80),
        (8.44, 243, 102, 80),
        (8.56, 243, 102, 80),
        (8.8, 202, 107, 80),
        (8.84, 164, 27, 104),
        (9.0, 164, 27, 104),
        (9.12, 121, 9, 104),
        (9.28, 77, 33, 104),
        (9.32, 52, 23, 104),
        (9.48, 52, 23, 104),
        (9.64, 33, 46, 104),
        (9.8, 93, 49, 104),
        (9.92, 93, 49, 104),
        (10.16, 173, 19, 104),
        (10.2, 226, 173, 48),
        (10.36, 226, 173, 48),
        (10.48, 211, 172, 48),
        (10.64, 208, 162, 48),
        (10.92, 220, 171, 48),
    ]

    lis1 = [
        (0.0, 113, 167, 47),
        (0.32, 138, 159, 47),
        (0.44, 152, 144, 47),
        (0.48, 193, 148, 47),
        (0.6, 193, 148, 47),
        (0.76, 205, 138, 55),
        (0.88, 204, 121, 63),
        (0.92, 190, 31, 127),
        (1.2, 183, 59, 127),
        (1.4, 137, 22, 127),
        (1.52, 137, 22, 127),
        (1.72, 129, 67, 127),
        (1.88, 123, 69, 127),
        (2.04, 131, 123, 63),
        (2.24, 130, 148, 63),
        (2.48, 130, 148, 63),
        (2.8, 138, 180, 63),
        (3.0, 138, 180, 63),
        (3.2, 146, 192, 63),
        (3.28, 105, 91, 151),
        (3.44, 105, 91, 151),
        (3.72, 11, 48, 151),
        (3.96, 5, 78, 151),
        (4.32, 4, 134, 1),
        (4.6, 149, 184, 48),
        (4.8, 145, 188, 48),
        (5.0, 154, 217, 48),
        (5.08, 163, 199, 48),
        (5.2, 163, 199, 48),
        (5.32, 164, 187, 48),
        (5.48, 163, 200, 48),
        (5.76, 163, 200, 48),
        (5.96, 173, 199, 48),
        (6.0, 133, 172, 48),
        (6.04, 128, 165, 48),
        (6.28, 128, 165, 48),
        (6.4, 129, 180, 48),
        (6.52, 133, 166, 48),
        (6.64, 133, 166, 48),
        (6.88, 144, 183, 48),
        (7.0, 153, 174, 48),
        (7.16, 153, 174, 48),
        (7.24, 153, 174, 48),
        (7.28, 253, 65, 104),
        (7.64, 253, 65, 104),
        (7.8, 279, 116, 80),
        (8.0, 290, 105, 80),
        (8.24, 288, 124, 80),
        (8.44, 243, 102, 80),
        (8.56, 243, 102, 80),
        (8.8, 202, 107, 80),
        (8.84, 164, 27, 104),
        (9.0, 164, 27, 104),
        (9.12, 121, 9, 104),
        (9.28, 77, 33, 104),
        (9.32, 52, 23, 104),
        (9.48, 52, 23, 104),
        (9.64, 33, 46, 104),
        (9.8, 93, 49, 104),
        (9.92, 93, 49, 104),
        (10.16, 173, 19, 104),
        (10.2, 226, 173, 48),
        (10.36, 226, 173, 48),
        (10.48, 211, 172, 48),
        (10.64, 208, 162, 48),
        (10.92, 220, 171, 48),
    ]

    def posi(t):
        global last_move
        if len(lis) == 0:
            return (last_move[1], last_move[2])
        if t >= lis[0][0]:
            last_move = item = lis.pop(0)
            return (item[1], item[2])
        else:
            if len(lis) > 0:
                dura = lis[0][0] - last_move[0]
                now = t - last_move[0]
                w = (lis[0][1] - last_move[1]) * (now / dura)
                h = (lis[0][2] - last_move[2]) * (now / dura)
                # print t, last_move[1] + w, last_move[2] + h
                return (last_move[1] + w, last_move[2] + h)
            return (last_move[1], last_move[2])

    def size(t):
        global last_move1
        if len(lis1) == 0:
            return (last_move1[3], last_move1[3] * 1.33)
        if t >= lis1[0][0]:
            last_move1 = item = lis1.pop(0)
            return (item[3], item[3] * 1.33)
        else:
            if len(lis) > 0:
                dura = lis1[0][0] - last_move1[0]
                now = t - last_move1[0]
                s = (lis1[0][3] - last_move1[3]) * (now / dura)
                nsw = last_move1[3] + s
                nsh = nsw * 1.33
                # print t, nsw, nsh
                return (nsw, nsh)
            return (last_move1[3], last_move1[3] * 1.33)

    avatar = VideoFileClip("media/big_buck_bunny_432_433.webm", has_mask=True)
    avatar.audio = None
    maskclip = ImageClip("media/afterimage.png", ismask=True, transparent=True)
    avatar.set_mask(maskclip)  # must set maskclip here..
    concatenated = concatenate_videoclips([avatar] * 3)

    tt = VideoFileClip("media/big_buck_bunny_0_30.webm").subclip(0, 3)
    # TODO: Setting mask here does not work:
    # .set_mask(maskclip).resize(size)])
    final = CompositeVideoClip(
        [tt, concatenated.set_position(posi).resize(size)])
    final.duration = tt.duration
    final.write_videofile(os.path.join(TMP_DIR, "issue_334.mp4"), fps=10)
Beispiel #7
0
PEP-0008, with exceptions made for the purposes of improving book
formatting. Example code is provided "as is".
Permissions
============
In general, you may use the code we've provided with this book in your
programs . You do not need to contact us for permission unless you're
reproducing a significant portion of the code and using it in educational
distributions. Examples:
* Writing an education program or book that uses several chunks of code from
    this course requires permission. 
* Selling or distributing a digital package from material taken from this
    book does require permission.
* Answering a question by citing this book and quoting example code does not
    require permission.
Attributions usually include the title, author, publisher and an ISBN. For
example, "Practical Python Projects, by Yasoob Khalid. Copyright 2020 Yasoob."
If you feel your use of code examples falls outside fair use of the permission
given here, please contact me at [email protected].
"""

from moviepy.editor import ImageClip, ColorClip, CompositeVideoClip
clip = ImageClip('website_image.png')
bg_clip = ColorClip(size=(1600, 1000), color=[228, 220, 220])
scroll_speed = 180
total_duration = (clip.h - 800) / scroll_speed
fl = lambda gf, t: gf(t)[int(scroll_speed * t):int(scroll_speed * t) + 800, :]
clip = clip.fl(fl, apply_to=['mask'])
video = CompositeVideoClip([bg_clip, clip.set_pos("center")])
video.duration = total_duration
video.write_videofile("movie.mp4", fps=26)
Beispiel #8
0
def main():
    '''
  Main method.
  Depends on global variables: lang, full, cache, subtitles

  :returns: Nothing.
  '''

    global lang, full, cache, subtitles

    getargs()

    checkdir('Data_TxtToSL/')

    checkdir('Data_TxtToSL/phrases/')
    checkdir('Data_TxtToSL/autoskip/')

    checkdir('Data_TxtToSL/cache/')

    print()

    if lang == None:
        while True:
            print(
                "Select Sign Language:\n1) BSL (British Sign Language)\n2) ASL (American Sign Language)\n3) DGS (German Sign Language / Deutsche Gebärdensprache)\n"
            )
            innum = input("Number: ")

            if innum == "1":
                lang = "BSL"
                break
            elif innum == "2":
                lang = "ASL"
                break
            elif innum == "3":
                lang = "DGS"
                break

    print()

    checklang(lang.lower())

    print()

    loadautoskip(lang.lower())

    print()

    loadphrases(lang.lower())

    print()

    if full == None:
        full = input("\nInput: ")

    words = interpret(full)

    print(words)

    for word in copy.deepcopy(words):
        if lang == "BSL" or lang == "ASL":
            content = signorg_getvid(word)
        elif lang == "DGS":
            content = dgs_getvid(word)

        if content != "cache" and content is not False and not isinstance(
                content, list):
            savevid(content, word)
        elif isinstance(content, list):
            index = words.index(word)

            words.remove(word)

            words[index:index] = content
        elif content is False:  # Skip word
            words.remove(word)

        print()

    print(words)
    print()

    clips = []

    for word in words:
        replaced = word.replace('[', '').replace(']', '')

        if not os.path.isfile("Data_TxtToSL/cache/{}/words/{}.mp4".format(
                lang.lower(), replaced.replace(' ', '-'))):
            continue

        originalClip = VideoFileClip(
            "Data_TxtToSL/cache/{}/words/{}.mp4".format(
                lang.lower(), replaced.replace(' ', '-')))

        if subtitles:
            with yaspin(
                    text="Generating subtitles for '{}'".format(word)) as sp:
                txt = TextClip(replaced,
                               font='Arial',
                               color='white',
                               fontsize=24)

                txt_col = txt.on_color(size=(originalClip.w, txt.h + 30),
                                       color=(0, 0, 0),
                                       pos=('center', 'center'),
                                       col_opacity=0.2)

                txt_mov = txt_col.set_pos(('center', 0.7), relative=True)

                composite = CompositeVideoClip([originalClip, txt_mov])
                composite.duration = originalClip.duration

                clips.append(composite)

                sp.ok(ansi.GREEN + "✓" + ansi.END)
        else:
            clips.append(originalClip)

    print()
    print(clips)
    print()

    final = concatenate_videoclips(clips, method="compose")

    final.write_videofile("finished.mp4", fps=30, audio=False, threads=4)

    if not cache:
        with yaspin(text="Deleting video files (because caching is disabled)"
                    ) as sp2:  # Use pymovie to combine video files
            for word in words:
                os.remove("cache/{}/words/{}.mp4".format(
                    lang.lower(), word.replace(' ', '-')))

            sp2.ok(ansi.GREEN + "✓" + ansi.END)
Beispiel #9
0
def ttsMerge(
    submission,
    words=50,
    fontSize=60,
    title_fontSize=100,
    font="Quadrat-Grotesk-W01-Black",
    voice="en-uk",
):
    title = submission.title
    text = submission.selftext.lower()
    text = re.sub(r"https\S+", " ", text, flags=re.MULTILINE)
    text = re.sub(r"#\w+ ?", "", text, flags=re.MULTILINE)
    whitelist = set(
        """1234567890abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ,.?!():#$%"'=-\n/@^"""
    )
    text = "".join(filter(whitelist.__contains__, text))

    titleSpeech = profanity.censor(title, " ")
    speech = profanity.censor(text, " ")
    title = profanity.censor(title, "*")
    print(text)

    tts = gTTS(titleSpeech + ". " + speech, lang=voice)
    tts.save("tts/audio/" + submission.id + ".mp3")

    text_list = text.split(" ")
    i = 0

    chunks = len(text_list) // words + (len(text_list) % words > 0)

    tts = gTTS(title, lang=voice)
    tts.save("tts/tmp/" + submission.id + ".mp3")
    intro = AudioFileClip("tts/tmp/" + submission.id + ".mp3").duration

    try:
        txt_clip = TextClip(
            title,
            font=font,
            fontsize=title_fontSize,
            color="white",
            size=(1920, 1080),
            method="caption",
            align="West",
            stroke_color="black",
            stroke_width=3,
        ).set_pos("center")

    except UnicodeEncodeError:
        txt_clip = TextClip(
            title.encode("utf-8"), fontsize=title_fontSize, color="white"
        ).set_duration(intro)
    img = ImageClip("./assets/bg.jpg")
    final_clip = CompositeVideoClip([img, txt_clip])
    final_clip.duration = intro
    final_clip.write_videofile(
        "tts/videos/" + submission.id + ".mp4",
        fps=30,
        temp_audiofile="tts/tmp/tmp_audio.mp3",
    )

    while i < chunks:
        text = " ".join(text_list[i * words : (i * words) + words])
        extra = 0
        if profanity.contains_profanity(text) is True:
            extra = 4
        text = profanity.censor(text, "*")
        if re.search("[a-zA-Z]", text) != None:
            if len(text_list[i * words : (i * words) + words]) < 49:
                print("last slide")
            else:
                text += "..."
            tts = gTTS(text, lang=voice)
            tts.save("tts/tmp/" + submission.id + str(i).rjust(2, "0") + ".mp3")
            duration = AudioFileClip(
                "tts/tmp/" + submission.id + str(i).rjust(2, "0") + ".mp3"
            ).duration
            try:
                txt_clip = TextClip(
                    text,
                    font=font,
                    fontsize=fontSize,
                    color="white",
                    size=(1920, 1080),
                    method="caption",
                    align="West",
                    stroke_color="black",
                    stroke_width=3,
                ).set_pos("center")

            except UnicodeEncodeError:
                txt_clip = TextClip(
                    text.encode("utf-8"), fontsize=fontSize, color="white"
                ).set_duration(duration - 0.7 - extra)
            img = ImageClip("./assets/bg.jpg")
            final_clip = CompositeVideoClip([img, txt_clip])
            final_clip.duration = duration - 0.5 - extra
            final_clip.write_videofile(
                "tts/videos/" + submission.id + str(i).rjust(2, "0") + ".mp4",
                fps=30,
                temp_audiofile="tts/tmp/tmp_audio.mp3",
            )
            i = i + 1