2

To create a burnt in timecode in ffmpeg, two escaping backslashes are required on the command line as so:

00\\:00\\:00\\:00

Using ffprobe to find the starting timecode produces the following output with a subprocess_output

00:00:00:00\n

I am using rstrip() to remove the new line, but how can I create a new variable that I can pass to ffmpeg's filter chain that will add those escaping backslashes?

I ultimately need my commandline to expand to something like this:

-vf 'drawtext=fontfile=/Library/Fonts/Tuffy.ttf:fontcolor=white:timecode=00\\:00\\:00\\:00:rate=25:boxcolor=0x000000AA:box=1:fontsize=40:x=360-text_w/2:y=405'

though of course in my script, it will just contain

timecode=%s
Remi Guan
  • 21,506
  • 17
  • 64
  • 87
Tandy Freeman
  • 528
  • 5
  • 15

1 Answers1

3

By using replace function you can be able to do that and after use os.system to execute the program.

In[4]: a = '00:00:00:00\n'
In[5]: a
Out[5]: '00:00:00:00\n'
In[6]: a = r'00:00:00:00\n'
In[7]: b = 'drawtext=fontfile' \
    '=/Library/Fonts/Tuffy.ttf:fontcolor=white:' \
    'timecode=%s:rate=25:' \
    'boxcolor=0x000000AA:box=1:fontsize=40:x=360-    text_w/2:y=405'%a.replace(':', '\\:').replace('\n', '')
In[8]: b
Out[8]:'drawtext=fontfile=/Library/Fonts/Tuffy.ttf:fontcolor=white:timecode=00\\:00\\:00\\:00\\n:rate=25:boxcolor=0x000000AA:box=1:fontsize=40:x=360-    text_w/2:y=405'
Alexis G
  • 1,259
  • 3
  • 14
  • 27
  • Hi Alexis, that worked great. I altered a few things, such as changing %a.replace to %s.replace. I removed the r in front of line 6 as it didn't make a difference and I didn't really know what it did. Thanks so much for helping me out. – Tandy Freeman Nov 07 '15 at 11:49