0

I want to add scriptures embedded on top of a say meditation video like below

example

scripyures i have will be in a text file and I choose a video on youtube downloaded to my local. Now I want to add the scriptures one after the other embeded on top of video like the example above?

1
  • I would suggest using Aegisub. It's free and very easy to adjust type font and size. Commented May 28 at 22:55

1 Answer 1

0

appearing text, not ideal, but start to try

#!/usr/bin/python3
import random,os
with open('/tmp/1.txt', 'w') as t:
    t.write("""ffmpeg is a universal media converter. It can read a wide variety of
inputs - including live grabbing/recording devices - filter, and transcode them
into a plethora of output formats.
ffmpeg reads from an arbitrary number of input "files" (which can be regular files,
pipes, network streams, grabbing devices, etc.), specified by the -i option, and writes
to an arbitrary number of output "files",
which are specified by a plain output url. Anything found on the command line which
cannot be interpreted as an option is considered to be an output url.
Each input or output url can, in principle,
contain any number of streams of different types (video/audio/subtitle/attachment/data).
The allowed number and/or types of streams may be limited by the container format.
Selecting which streams from which inputs will
go into which output is either done automatically or with the -map option (see the
Stream selection chapter).

""")
# text lines divisible by 3

f=open('/tmp/1.lst', 'w')
d=0
ss=0
with open('/tmp/1.txt', 'r') as t:
    for t1 in t:
        t2=next(t)
        t3=next(t)
        d+=1

        # generate shrinking circles for alphamerge
        r=40 # count of circles
        a=f"""color=black:200x200,format=rgba,
geq=lum='p(X,Y)':a='if(lte(pow(X-W/2,2)+pow(Y-H/2,2),(1-T/3)*100*100),255,0)',
split={r}"""
        b="" # pads for split
        c=f"color=white:1280x300[w];\n" # scale,overlay
        ow=10 # count width of circles
        w=0
        l=40  # middle of the current line of circles
        for i in range(r):
            b=b+f"[c{i}]"
            ow=ow+w+30
            if ow>1280:
                ow=20
                l+=70 # next line of circles
            w=80+random.randint(-50,50) # random width
            h=80+random.randint(-50,50)   # random height
            oh=l+random.randint(-25,25)-h # random deviation from center of line
            c=c+f"[c{i}]scale={w}:{h}[c{i}];\t[w][c{i}]overlay={ow}:{oh}[w];\n"
        b=b+f";\n"
        s=f"""ffmpeg -ss {ss} -i input.mp4 -filter_complex "
{a}{b}{c}
color=fefefe:1280x300,
drawtext=fontcolor=white:fontsize=h/10:x=(w-tw)/2:y=(h/5-th)/2:text='{t1}',
drawtext=fontcolor=white:fontsize=h/10:x=(w-tw)/2:y=h/5+(h/5-th)/2:text='{t2}',
drawtext=fontcolor=white:fontsize=h/10:x=w/2:y=h*2/5+(h/5-th)/2:text='{t3}'[t];
[w]avgblur=10[g];
[t][g]alphamerge,
geq=lum='p(X,Y)'
:a='if(eq(lum(X,Y),234),0,alpha(X,Y))'[t];
[0][t]overlay=(W-w)/2:H-h"""
        s+=""",drawtext=text='%{eif\\\:n+1\\\:d\\\:3}'
:x=(w-tw)/2
:y=h-th
:fontsize=h/20
:fontcolor=red" """
        s+= f"""-c:v h264_nvenc -cq 20 -c:a libopus -t 5 "/tmp/{d}.mkv" -y -hide_banner"""
        print(s)

        # alphamerge text and gray circles
        os.system(s)
        f.write(f"file {d}.mkv\n")
        # os.system(f'mpv --no-config -loop=inf --volume=0 "/tmp/{d}.mkv"')
        # break # for test
        ss += 5

f.close()
os.system('ffmpeg -f concat -i /tmp/1.lst -c copy /tmp/out.mkv -y -hide_banner')
os.system('mpv --no-config -loop=inf --volume=0 /tmp/out.mkv')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.