# How to add a text-info into the View1 before I try to capture a video

**URL:** <https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346>\
**Category:** Development\
**Created:** [June 28, 2019, 2:39am UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346 "2019-06-28T02:39:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [June 28, 2019, 2:39am UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346/1 "2019-06-28T02:39:47Z")

</div>

Operating system: Windows  
Slicer version: 4.11.0-2019-06-23 r28335  
Expected behavior: text inside View1  
Actual behavior: no idea

@all Hi all,  
I am a new in Slicer community. I would like to add some text info into View1 region, how may I do that?  
Thanks a lot

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [June 28, 2019, 8:02am UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346/2 "2019-06-28T08:02:36Z")

</div>

I’m on my phone so I don’t have the options in front of me, but if the windows version of slicer uses ffmpeg to make videos, you can feed all sorts of options to it to do text overlays. In the screen capture module, there’s a box to add options to give to ffmpeg. Sorry this post is short on specifics, but hopefully it will point you in the right direction. Check out the ffmpeg documentation, and there are lots of examples of text overlays using ffmpeg if you search around.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [June 28, 2019, 3:40pm UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346/3 "2019-06-28T15:40:54Z")

</div>

There is an example [here](https://www.slicer.org/wiki/Documentation/Nightly/Modules/ScreenCapture) of specifying extra ffmpeg options for Screen Capture module to display a logo in the corner of the video.

For adding titles, subtitles, and transitions we used Windows Movie Maker (free, now replaced by Microsoft Photos) nowadays we mostly switched to Camtasia (not free, but quite good and simple to learn).

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [June 28, 2019, 5:31pm UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346/4 "2019-06-28T17:31:59Z")

</div>

Thanks a lot, I will try as you suggested.

Aiden

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 5, 2019, 2:17pm UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346/5 "2019-08-05T14:17:09Z")

</div>

@lassoan Hi Thanks a lot again for the hint.

I tried as you suggested using drawtext from ffmpeg. Sort of I did reach my aim right after the original ffmpeg running in Screen Capture (Thanks a lot one more time, LOL), I did one more time running of ffmpeg as to add drawtext to the \*.mp4 file to make a new file. The code is as follows (excuse my non-professional coding way since I am still kind new to python.)

```python
    print('..........................before second ffmpeg running ....................................')
    #No idea how to decide arialbd.ttf location
    #use an alternate way: copy a *.ttf to the current working dir
    #that is, copy my arialbd.ttf to the outputDir
    ttf_dirname =outputDir + '\\arialbd.ttf'
    if not os.path.isfile(ttf_dirname):
        from shutil import copyfile
        src = os.path.dirname(ffmpegPath)+'\\arialbd.ttf'
        dst = ttf_dirname
        print('copying file =' , src )
        print('to here = ', dst)
        copyfile(src , dst )

    #run_ffmpeg2 = 'C:\\Anaconda3\\envs\\aiden_00\\Scripts\\ffmpeg.exe '+ ' -i '+ outputVideoFilePath \
    run_ffmpeg2 = ffmpegPath + ' -i '+ outputVideoFilePath \
      + ' -y -vf \"format=yuv420p, drawtext=fontfile=arialbd.ttf:text=\'DigiM 2019\':fontcolor=yellow@0.7:fontsize=28:x=15:y=20, format=yuv420p\" '\
      + ' -c:v libx264 -c:a copy -movflags faststart '\
      + outputVideoFilePath.replace('.mp4', '_digim.mp4')
    
    print(run_ffmpeg2)
    print('...................... before second ffmpeg running........................................')

    
    p2 = subprocess.Popen(run_ffmpeg2, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=outputDir)
    stdout2, stderr2 = p2.communicate()
    if p2.returncode != 0:
      self.addLog("ffmpeg error output: " + stderr2.decode())
      raise ValueError("ffmpeg returned with error")
    else:
      self.addLog("Video export succeeded to file: "+ outputVideoFilePath.replace('.mp4', '_digim.mp4') )
      logging.debug("ffmpeg standard output: " + stdout2.decode())
      logging.debug("ffmpeg error output: " + stderr2.decode())

    try: 
      os.remove(ttf_dirname)
    except:
      pass
    print('Supposed to be done successfully!')

```

The big issue I encountered was how to set up the ttf file in drawtext between two ’ " ’ which always brought me trouble with escaping.  
I have not still figure out how to set up that drawtext format, especially with the ttf-file part. So alternately I copied a ttf to the current working directory. It works fine but not professional. So please, if anybody, know how to figure it out, I will be well grateful and appreciate the help and effort.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 5, 2019, 4:00pm UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346/6 "2019-08-05T16:00:08Z")

</div>

There is no need to modify any source code. You can add any extra options to “Video extra options” field in advanced section. You can hardcode full path of .ttf file there (enclosed in double-quotes if the path contains space).

---

<div class="post-metadata">

**Author:** ![aiden.zhu](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/aiden.zhu/32/67145_2.png) [@aiden.zhu](https://discourse.slicer.org/u/aiden.zhu)\
**Post date:** [August 12, 2019, 2:16pm UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346/7 "2019-08-12T14:16:15Z")

</div>

This topic will be closed right after this new updated from my exploration experience:

the other way to show text in the view is to use ConerAnnotation:  
view=slicer.app.layoutManager().threeDWidget(0).threeDView()

# Set text to “Something”

view.cornerAnnotation().SetText(vtk.vtkCornerAnnotation.UpperRight,“Something”)

# Set color to red

view.cornerAnnotation().GetTextProperty().SetColor(1,0,0)

# Update the view

view.forceRender()

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 12, 2019, 3:05pm UTC](https://discourse.slicer.org/t/how-to-add-a-text-info-into-the-view1-before-i-try-to-capture-a-video/7346/8 "2019-08-12T15:05:59Z")

</div>

Good idea!

You can also add a logo as described on the screen capture module documentation page.
