Commands to work with video.

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
Andredron
Miko-Class Veteran
Posts: 688
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Commands to work with video.

#1 Post by Andredron »

Hi all, I decided to gather in 1 pile all examples often used for working with video in renpy.

To make it easier for you to work with video, install a program on your PC ffmpeg

Create a bat file in the program and ascribe the following to it:

webm.bat

Code: Select all

for %%a IN (*.mp4) DO ffmpeg -i "%%a" -vcodec libvpx -b:v 4000k -deadline realtime -cpu-used 2 -vf scale=iw/1.5:-1 -acodec libopus "%%~na2.webm"
Insert into the folder with bat file, video format mp4 (IN (*.mp4) Or a different format, just change the format in the brackets) and run bat.

It converts it to the webm ( "%%~na2.webm") format that android supports.

How to create an alpha mask for video sprites

Type in a search engine query on video storyboarding and there lay out your video in pictures.

And then execute the following commands mentioned in this blog:

https://web.archive.org/web/20231010114 ... d.html?m=1



The alpha mask in Renpy is needed to make the video sprite transparent, not completely replace the background.

White parts - the video was displayed on the screen,

Black - was not visible, transparent.



1) Full screen video playback(works with android)

Code: Select all

label splashscreen:
 $ renpy.movie_cutscene('movie.webm')
 return
 
label start:
...... 
2) The command to have the video seen by renpy as an imageimage(Or a video sprite)

Code: Select all


init:
    image brat movie = Movie(play="videos/brat.webm", mask="brat_mask.webm")#video sprite
    
    image fon_brat movie = Movie(play="videos/main_menu.webm", loop=True )#video scene



label start:
    scene fon_brat
    pause 0.5
    show brat movie with Dissolve(1.0) 
    with Pause(1.0) 
    ".... "

3) Attributed video and immediately coordinates it with size and an audio channel to adjust the volume in the settings.

Code: Select all

image launch = Movie(size=(1280, 720), channel="m", play="oa4_launch.webm", pos=(10, 10), anchor=(0, 0), loop=False) 

screen main_menu:
    add launch
    frame:
    ........ 
loop=True - By setting this value, the video will be constantly repeated, which is necessary for background videos.

viewtopic.php?p=555751#p555751

4) Screen where you can pause the video

Code: Select all

define _confirm_quit = False

image bg intro = Movie(size=(1280, 720), channel="m", play="oa4_launch.webm", loop=False)

screen pause_screen():
    vbox:
        textbutton "Pause Movie" action PauseAudio("m", True)
        textbutton "Resume Playing" action PauseAudio("m", False)
        textbutton "Toggle Pause" action PauseAudio("m", "toggle")

label start:

    scene bg intro
    show screen pause_screen

    "(You can pause here.)"
    "(You can pause here too.)"

    hide screen pause_screen

    "..."

label main_menu:
    return
5) The video was automatically stretched to full screen

Code: Select all

init:
    image movie = Movie(size=(config.screen_width, config.screen_height))
    
label start:
    scene black
    with Pause(1)

    play movie "movie_background.ogv" loop
    show movie with dissolve

    show person at center with dissolve
    
    person "I'm in front of an animated background!"

    hide movie with dissolve
    stop movie
6) Automatically flip text on video

Code: Select all


image movie = Movie(play="Veronica.webm")

screen mytextscreen(what, t):
    modal True
    text what xalign 0.5 yalign 1.0 style "textstyle"
    timer t action Return()
    
style textstyle:
	outlines [(3, "#000")] ## Make sure to have the [] or else you get an error.
	

label start:

    show movie:
        pos (0, 0)
        size (1280, 720)

    call screen mytextscreen(_("I really like..."), 3.0)
    call screen mytextscreen(_("...that movie."), 3.0)

    hide movie
7) Play the sound of video and music.

Code: Select all

$ renpy.movie_cutscene("movies/Landing2.webm", stop_music=False)
8) Freeze a movie on the last frame(2version)

The old crutch way - viewtopic.php?f=8&t=51753#p495336

The new right way from M. Python:

keep_last_frame=True

Code: Select all

image bg mainmenu = Movie(play="bg_mainmenu.webm", loop=False, keep_last_frame=True)

9) Prevent video flicker when switching between linked movies


https://patreon.renpy.org/dev-2023-03.html#movie-groups

Code: Select all

image eileen happy movie = Movie(group="eileen", play="eileen_happy_movie.webm", side_mask=True)
image eileen sad movie = Movie(group="eileen", play="eileen_sad_movie.webm", side_mask=True)

label start:
    show eileen sad movie
    "Give me a second."
    show eileen happy movie
    "Movie groups make this much better
10) The old way to pause a video in the main menu

viewtopic.php?f=8&t=50591#p489498

11) Enable hardware video rendering mode

Option.rpy

Code: Select all

$ config.hw_video = True

12) Prescribe the image in the first frame of the video

Code: Select all

image e0m2 movie = Movie(play="e0m2.webm", start_image = "start_image.png")
13) Crutch for android which don't support video, will show picture

Code: Select all

image e0m2 movie = Movie(play="e0m2.webm", image = "images/image.png")
An image that is displayed when play has been given, but the file it refers to does not exist. (For example, this can be used to create a slimmed-down mobile version that does not use movie sprites.) Users can also choose to fall back to this image as a preference if video is too taxing for their system. The image will also be used if the video plays, and then the movie ends

14) Add Button on Main Menu to Play Video

Code: Select all

textbutton _("Teaser Video") action Replay("teaser_video", locked=False)

label teaser_video:
    $ renpy.movie_cutscene(filename)
    $ renpy.end_replay()
And

viewtopic.php?p=553245

15) Video gallery
viewtopic.php?p=556116#p556116

16) (Experimental code) fast-forward video
viewtopic.php?p=552391

Python Opencv control or ffmpeg
https://stackoverflow.com/questions/582 ... -as-custom

17) When you hover, the video appears.
viewtopic.php?p=552056#p552056

18) Transitions between videos
.
viewtopic.php?p=540048

19) Inserting a video sprite. Switching channels

Code: Select all

init python:
    # game window in the center of the screen
    import os
    os.environ['SDL_VIDEO_CENTERED'] = '1'
    # automatic image declaration
    config.automatic_images_minimum_components = 1
    config.automatic_images = [' ', '_', '/']
    config.automatic_images_strip = ['images']

    # titles of all videos
    tvchan_name = ['sitcom', 'comedy', 'sport']

    # declare all video sprites
    for i in tvchan_name:
        renpy.image("tv " + i, Movie(play= i + ".mp4", pos=(444, 44), anchor=(0, 0), size=(320, 240))))

# The game starts here.
label start:
    scene bg tvset
    $ tvchan = ""

label chan_select:
    # channel selection
    menu:
        "What are we going to watch?"
        "Serial":
            $ tvchan = "sitcom"
        "Comedy":
            $ tvchan = "comedy"
        "Sports":
            $ tvchan = "sport"
        "Nothing":
            $ tvchan = ""
            hide tv

    # if a channel is selected, start the corresponding video
    if tvchan:
        show expression "tv " + tvchan as tv
        pause
        jump chan_select

    # if no channel is selected
    "I'd better get back to work."
    return

Post Reply

Who is online

Users browsing this forum: No registered users