Answers.Body: <p>appearing text, not ideal, but start to try</p>
  <pre class="lang-python prettyprint-override"><code>#!/usr/bin/python3
  import random,os
  with open('/tmp/1.txt', 'w') as t:
      t.write(&quot;&quot;&quot;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 &quot;files&quot; (which can be regular files,
  pipes, network streams, grabbing devices, etc.), specified by the -i option, and writes
  to an arbitrary number of output &quot;files&quot;,
  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).
  
  &quot;&quot;&quot;)
  # 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&quot;&quot;&quot;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}&quot;&quot;&quot;
          b=&quot;&quot; # pads for split
          c=f&quot;color=white:1280x300[w];\n&quot; # 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&quot;[c{i}]&quot;
              ow=ow+w+30
              if ow&gt;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&quot;[c{i}]scale={w}:{h}[c{i}];\t[w][c{i}]overlay={ow}:{oh}[w];\n&quot;
          b=b+f&quot;;\n&quot;
          s=f&quot;&quot;&quot;ffmpeg -ss {ss} -i input.mp4 -filter_complex &quot;
  {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&quot;&quot;&quot;
          s+=&quot;&quot;&quot;,drawtext=text='%{eif\\\:n+1\\\:d\\\:3}'
  :x=(w-tw)/2
  :y=h-th
  :fontsize=h/20
  :fontcolor=red&quot; &quot;&quot;&quot;
          s+= f&quot;&quot;&quot;-c:v h264_nvenc -cq 20 -c:a libopus -t 5 &quot;/tmp/{d}.mkv&quot; -y -hide_banner&quot;&quot;&quot;
          print(s)
  
          # alphamerge text and gray circles
          os.system(s)
          f.write(f&quot;file {d}.mkv\n&quot;)
          # os.system(f'mpv --no-config -loop=inf --volume=0 &quot;/tmp/{d}.mkv&quot;')
          # 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')
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-06-12T01:16:36.357Z
Answers.LastActivityDate: 2024-06-12T01:16:36.357Z
Answers.UserDisplayName: Баяр Гончикжапов
Body: <p>I want to add scriptures embedded on top of a say meditation video like below</p>
  <p><a href="https://www.youtube.com/watch?v=NpJCIgK4bVI" rel="nofollow noreferrer">example</a></p>
  <p>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?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-05-28T22:55:09.930Z
Comments.Text: I would suggest using Aegisub. It's free and very easy to adjust type font and size.
Comments.UserDisplayName: 1957classic
Tags: <ffmpeg><embedding>
Title: Adding many scriptures on top of a video
UserDisplayName: Jaango Jayaraj
ThreadText: # Adding many scriptures on top of a video
  
  (Asked by: username_0 on 2024-05-27)
  
  I want to add scriptures embedded on top of a say meditation video like below
  
  [example](https://www.youtube.com/watch?v=NpJCIgK4bVI)
  
  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?
  
  **Tags:** ffmpeg, embedding
  
  > **Comments:**
  > **username_1**: I would suggest using Aegisub. It's free and very easy to adjust type font and size.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-06-12. Score: 0
  
  appearing text, not ideal, but start to try
  
  ```python
  #!/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')
  
  ```
  
  
  ---
  
  