FE 'tkGooies' Utilities

'VIDEOtools' group

A Tk GUI for
Computer-Monitor-And-Audio
MOVIE-CAPTURE

(an 'ffmpeg' Front End)

(FE = Freedom Environment)

FE Home Page > FE Downloads Page >

FE 'tkGooies' Description Page >

FE 'tkGooies' 'VIDEOtools' Page >

This
'tkComputerMonitorAndAudioCapture'
(frontend for 'ffmpeg') Page

INTRODUCTION to Tcl-Tk script
'tkMovieCapture_ ComputerMonitorAndAudio_ ffmpegFrontEnd'

Near the bottom of my 'biography' page at the Tcler's Wiki wiki.tcl.tk, I have a list of 'done and to-do' utilities in a section labelled 'CFE' (Code - Front Ends).

In the 'to do' list, there was an item titled

Tk GUI Front End for 'ffmpeg'
for video-and-audio capture
of a computer monitor session

That is the subject of this page.


THE GOALS

My goals for the Tcl-Tk script for this GUI were:

  • Provide entry widgets for the approximately 15 parameters that can be specified to 'ffmpeg' in creating a movie file.

    Also provide working defaults for the 'ffmpeg' parameters.

  • Provide an entry widget for an output movie filename, with a default name provided.

  • Provide an entry widget to allow the user to specify a movie player program with which to view a completed movie file.

  • Provide a 'Launch' button to start the movie capture.

  • Provide an entry widget to allow the user to specify a 'delay time' before 'ffmpeg' is started up --- so that the user has time to do some preparation, such as minimizing this ffmpeg-frontend GUI window, before 'ffmpeg' recording is started.

  • Provide a 'Play' button to initiate playing of the completed movie file.

  • To avoid overwhelming the user with the number of recording parameters available, provide a 'checkbutton' on the GUI to only show the video/audio/other parameters for 'ffmpeg' (and a user-selected container format) if the user requests to see them.


THE GUI LAYOUT

Like for some image/media/animated-GIF 'find-and-play' utilities that I have posted here, I made a 'text-sketch' for the GUI for this 'movie-capture' utility.



CONVENTIONS for the GUI 'text-sketch' below:

   * SQUARE-BRACKETS indicate a comment not to be included on the GUI.
   * BRACES indicate a Tk 'button' widget.
   * UNDERSCORES indicate a Tk 'entry' widget.
   * A COLON indicates that the text before the colon is on a 'label' widget.
   * CAPITAL-O indicates a Tk 'radiobutton' widget.
   * CAPITAL-X indicates a Tk 'checkbutton' widget.

   Frame
   names      --------------------------------------------------------------------------------------
     |        Movie-and-Audio Movie-Capture - a front-end for the 'ffmpeg' command
     V        [window title]
              --------------------------------------------------------------------------------------
 .fRbuttons   {Exit} {Help} {LaunchMovieCapture} {PlayMovie}  X ShowDetailedInputParms (video,audio,other) Delay time (secs): 8__ 

 .fRmsg       'Delay time' allows some setup time before the 'ffmpeg'-window pops up and ffmpeg starts
              capturing the screen. For example: It allows time to minimize this GUI.
              [This initial message in a label widget may be changed when the 'Launch' button is clicked.]

              --------------------------------------------------------------------------------------
 .fRouthead   Output File parameters:
              --------------------------------------------------------------------------------------

 .fRcontainer Container format: O Matroska (.mkv) O Mpeg4 (.mp4) O Mpeg (.mpg) O Flash (.flv) O AVI (.avi) O WEBM (.webm)

 .fRfile      Output movie filename : /tmp/${USER}_screen_capture_movie.mkv______________  {Browse...}

 .fRplayer    Player for the movie file: totem________ Examples: totem  gmplayer  mplayer  ffplay  vlc

 [The following frames are shown if the 'ShowDetailedInputParms' checkbuttons is set ON.]

              --------------------------------------------------------------------------------------
 .fRvideohead Video parameters:
              --------------------------------------------------------------------------------------

 .fRvidsize   Video size: 1024x768____ Examples: 640x480 , 800x600 , 1024x768

 .fRvidoffset Offset on screen: +0,0_____  Examples: +0,0   +10,30   +100,50  Video-in format: x11grab__

 .fRvsource   Source (display ID): :0.0___ Examples: :0.0  :0.1               Video rate (frames/sec): 25_

 .fRvcodec    Video codec: libx264_____ Examples: libx264  mpeg4  mpeg1video  flv  ...

 .fRvother    Other video parms: -vpre /usr/share/ffmpeg/libx264-lossless_ultrafast.ffpreset_______

              -------------------------------------------------------------------------------------
 .fRaudiohead Audio parameters:
              -------------------------------------------------------------------------------------

 .fRaformat    Audio format: alsa____   Examples: alsa  oss        Audio Channels: 1_ Examples: 1  2

 .fRainterface Audio interface: pulse____   Examples: pulse  hw:0,0  /dev/dsp     

 .fRacodec     Audio codec: pcm_s16le__ Examples: pcm_s16le  libmp3lame  libfaac  vorbis

 .fRaother     Other audio parms: -ar 22050 -ab 96k_________________________________________________

              --------------------------------------------------------------------------------------
 .fRgeneral   General parameters:
              --------------------------------------------------------------------------------------

 .fRthreads   Threads: 1___ (to take advantage of a multi-core computer)

 .fRguide     NOTE: This utility runs 'ffmpeg' in an 'xterm' window. Startup and coding messages from 'ffmpeg'
              can be seen in that window. Minimize the window to get it out of the way of recording. Stop the
              recording by re-opening the 'xterm' window and typing 'q'. The terminal does not close after
              'ffmpeg' stops, so that you can examine msgs. THEN CLOSE the terminal window. The output file,
              if good, can be shown in a movie player, that you specify above.  See 'Help' for details. 
              [a 'label' widget]
             ---------------------------------------------------------------------------------------


GUI Components

From the GUI 'sketch' above, it is seen that the GUI consists of about

  • 4 'button' widgets
  • 25 'label' widgets (many are for entry fields)
  • 14 'entry' widgets
  • 1 'checkbutton' widget
  • 6 'radiobutton' widgets
  • 0 'scale' widgets
  • 0 'canvas' widgets
  • 0 'listbox' widgets
  • 0 'text' widgets

All but the 'label' widgets provide operating parameters/options in this utility.

Hence there are about 4 + 14 + 1 + 6 = 25 user-specifiable options offered on this utility.


Beautification of the GUI

I should point out here that I was not especially interested in coming up with a 'beautiful utility'.

I just wanted a utility that would make starting a recording session with 'ffmpeg' as simple as a click on a 'Launch' button.

I am certainly interested in making pretty GUI's --- as my pages on

have indicated.

But at this time, I am satisfied to implement the 'functionality', and let the 'beauty' go for a later date (when I have more beauty tools/code at hand).


SCREENSHOTS OF THE GUI

On the basis of the GUI-layout sketch above, I ended up with the GUI seen in the following image.


Poke this image to see the image
in a separate browser window or tab.

The operation can be as simple as clicking on the 'LaunchMovieCapture' button --- and then clicking on the 'PlayMovie' button, after the movie file has been created --- if you take the initial defaults.

Note that there are several radiobuttons that allow you to choose the 'container format' of the output file.

But you can simply take the default container format.

    (You can change the default by changing a 'set CONTAINERformat' statement at the bottom of the Tk script.)


Many more options

If the user wants to change (or simply check) the video and audio and 'other' parameters that are set according to a choice of the 'container format', the user can click on the 'ShowDetailedInputParms' checkbutton at the top of the GUI.

When that checkbutton is clicked, the GUI expands downward, as can be seen in the following image.


Poke this image to see the image
in a separate browser window or tab.

THE CONTAINER FORMATS

I have tested the 5 active (non-grayed-out) container-format radiobuttons to confirm that the video-audio-other parameters that I have provided for each container-format do indeed result in a successful movie file capture.

So I have created '.mkv' '.mp4' '.mpg' '.flv' and '.avi' files.

I have grayed out the WEBM radiobutton.

That radiobutton is intended to eventually allow for creating a movie in the 'webm' format that Google is promoting.

The 'webm' format uses a Matroska-like container format and a Vorbis audio format and a 'VP8' video format.

You can see some information on the WEBM format at a Wikipedia page on the WEBM format.

I do not have the video codec that is needed to make that file format --- and my 2009 version of 'ffmpeg' may not be capable of creating a WEBM file.

But I include most of the program code to easily implement and activate a 'webm' output option.


DESCRIPTION OF THE CODE

Below, I provide the Tk script code for this 'movie-capture-from-computer-screen' utility.

I follow my usual 'canonical' structure for Tk code for this Tk script:



  0) Set general window & widget parms (win-name, win-position,
     win-color-scheme, fonts-for-widgets, widget-geometry-parms,
     text-array-for-labels-etc, win-size-control).

  1a) Define ALL frames (and sub-frames, if any).
  1b) Pack   ALL frames and sub-frames.

  2) Define & pack all widgets in the frames, frame by frame.
              Within each frame, define ALL the widgets.
              Then pack the widgets.

  3) Define keyboard and mouse/touchpad/touch-sensitive-screen action
     BINDINGS, if needed.

  4) Define PROCS, if needed.

  5) Additional GUI initialization (typically with one or more of
     the procs), if needed.


This Tk coding structure is discussed in more detail on the page A Canonical Structure for Tk Code --- and variations.

This structure makes it easy for me to find code sections --- while generating and testing a Tk script, and when looking for code snippets to include in other scripts (code re-use).

I call your attention to step-zero.

One thing that I started doing in 2013 is use of a text-array for text in labels, buttons, and other widgets in the Tk GUI's that I author.

This can make it easier for people to internationalize my scripts.

I will be using a text-array like this in most of my scripts in the future.


Experimenting with the GUI

As in all my scripts that use the 'pack' geometry manager (which is all of my 100-plus scripts, so far), I provide the four main 'pack' parameters --- '-side', '-anchor', '-fill', '-expand' --- on all of the 'pack' commands for the frames and widgets.

That helps me when I am initially testing the behavior of a GUI (the various widgets within it) as I resize the main window.

I think that I have used a pretty nice choice of the 'pack' parameters.

The label and button and radiobutton widgets stay fixed in size and relative-location if the window is re-sized --- while the output-filename and 'player-program' entry widgets expand/contract horizontally whenever the window is re-sized horizontally.

You can experiment with the '-side', '-anchor', '-fill', and '-expand' parameters on the 'pack' commands for the various frames and widgets --- to get the widget behavior that you want.


Additional experimentation with the GUI:

You might want to change the fonts used for the various GUI widgets.

For example, you could change '-weight' from 'bold' to 'normal' --- or '-slant' from 'roman' to 'italic'.

Or change font families.

In fact, you may NEED to change the font families, because the families I used may not be available on your computer --- and the default font that the 'wish' interpreter chooses may not be very pleasing.

I use variables to set geometry parameters of widgets --- parameters such as border-widths and padding.

And I have included the '-relief' parameter on the definitions of frames and widgets.

Feel free to experiment with those 'appearance' parameters as well.

If you find the gray palette of the GUI is not to your liking, you can change the value of the RGB parameter supplied to the 'tk_setPalette' command near the top of the code.


Some features in the code

There are plenty of comments in the code, to describe what most of the code-sections are doing.

You can look at the top of the PROCS section of the code to see a list of the procs used in this script, along with brief descriptions of how they are called and what they do.

The main procs are :



  'set_defaults_for_container' - called by bindings on the CONTAINER
                                 radiobuttons.

                                 Sets defaults for the GUI widgets for a given
                                 container type.

  'capture_movie'              - called by the 'LaunchMovieCapture' button.

                                 Launches the 'ffmpeg' program --- with user-selected
                                 recording parameters. Calls an external shell script
                                 whose code is provided below.

  'play_movie'                 - called by the 'PlayMovie' button.

                                 Launches a user-selected movie 'player' program.

  'pack_detail_frames'         - called by button1-release binding on the
                                 ShowDetailedInputParms checkbutton.

  'popup_msgVarWithScroll'     - called by 'Help' button to show HELPtext var.


I used the following statement to allow the GUI to be expanded in the x-direction, but NOT the y-direction.

wm resizable . 1 0


A fervent hope

It is my hope that the copious comments in the code will help Tcl-Tk coding 'newbies' get started in making GUI's like this.

Without the comments, potential young Tcler's might be tempted to return to their iPhones and iPads and iPods --- to watch old George Carlin videos --- and videos of his comedy offspring, such as Bill Burr and Jim Jeffries.


CODE for the 'ffmpeg' Front End GUI

Here is a link to the code for the Tk script:

'monitorAndAudio_MovieCapture_ ffmpeg_FrontEnd.tk'


Shell script (called by the Tk script) :

And here is a link to the code for the shell script called by this Tk script:

'ffmpeg_monitorAndAudio_ MovieCapture.sh'

Having the 'ffmpeg' call in a shell script instead of embedded in the Tk script facilitates testing and debugging.

For example, this script can be tested independently of the Tk script.

    In fact, this shell script could be modified to serve as a 'hard-coded' (non-GUI, command-line) means of recording computer sessions.

You can put this script in the same directory with the Tk script.

The Tk script includes some code (involving the 'argv0' variable) to determine the location of the shell script by extracting the name of the directory in which the Tk script lies.


INSTALLING THE SCRIPTS:

The Tk script and the shell script could be put in a sub-directory of the user's home directory, such as

$HOME/apps/tkMovieCaptureComputerMonitor

Then the user can use their desktop system (such as Gnome or MATE or KDE) to set up the Tk script as an icon on the desktop.

Then, whenever the user wants to record a computer session, the user can click on the icon to startup this 'front end' to the 'ffmpeg' command.


LINK TO A MOVIE CAPTURE EXAMPLE

Here is a link to a movie capture that I did with this GUI.

It is a capture of an 800x600 portion a computer monitor screen as I demonstrate the 'dynamic-font-resizing' of the font-selector that I published at the page titled

YAFSG - Yet Another Font Selector GUI

--- as I move the 'scale' widget on that font-selector GUI.

This video indicates the impact of the recording process on other processing on the computer.

The expansion and contraction of the font-selector window goes in 'fits and starts' in this video.

When I am not recording a movie, the expansion and contraction goes quite smoothly --- and the font resizes quite smoothly.

So let the movie-recorder-person be aware of the impact.

For example, if a person records the action during a video game, the frame-rate of the video game will probably be adversely affected by the movie capture process.


SOME POSSIBLE ENHANCEMENTS

I have no major enhancements that I can think of for the Tk script at this time.

However, in the future, I may find that I may want/need to change some default video or audio or 'other' parameters for some of the container formats.

And I may find that it is worthwhile implementing the WEBM format.


Rather than try to make this Tk script also work for capturing video from a web cam (instead of from the computer monitor), I plan to work on a similar script to capture movies from a web cam --- and from the audio circuitry of a computer.

I also plan to work on at least one other 'front end' for 'ffmpeg' --- for example, for clipping, cropping, audio-extraction, audio-addition, and some other movie file editing functions.


IN CONCLUSION

As I have said on several other code-donation pages on wiki.tcl.tk ...

There's a lot to like about a utility that is 'free freedom' --- that is, no-cost and open-source so that you can modify/enhance/fix it without having to wait for someone else to do it for you (which may be never).

A BIG THANK YOU to Ousterhout for starting Tcl-Tk, and a BIG THANK YOU to the Tcl-Tk developers and maintainers who have kept the simply MAH-velous 'wish' interpreter going.


2014jun30 UPDATE - on 'ffmpeg' and its fork, 'avconv'

I should point out that members of the 'ffmpeg' development project went through a heated difference of opinion, and a result was that the 'avconv' (audio video convert?) program was started as a 'fork' of the 'ffmpeg' program.

    (This happened in the 2010-2013 time frame.)

Some rather vague details of the 'meltdown' can/could be seen at the 'ffmpeg' web site and the 'libav' web site (home of the 'avconv' program).

Also see the Wikipedia 'History' section of the 'Libav' page.

One outcome of this 'fork' is that around 2013, the Debian Linux project started providing the 'avconv' package instead of the 'ffmpeg' package.

And the two most popular Linux 'distros' at the time --- Linux Mint and Ubuntu --- (which are based on Debian Linux) --- started providing the 'avconv' package instead of 'ffmpeg'.

At this time (2014), the command-line parameters used by 'ffmpeg' and 'avconv' have not changed much.

So, if you have 'avconv', not 'ffmpeg', you can change the places where 'ffmpeg' is called (in the scripts above) to 'avconv'.

There have been some changes in command-line parameters in more recent versions of 'ffmpeg' (changes between 2009 and 2014).

For example, in recent examples of 'ffmpeg' commands at internet forums, you may see '-c:a' used instead of '-acodec' (for audio codec).

If a parameter like '-acodec' no longer works, you can simply change the occurrences of '-acodec' to '-c:a', in the calls to 'ffmeg' (or 'avconv') in the code above.

The same goes for most of the other 'ffmpeg' (or 'avconv') parameters used in this utility.

This is just one more example of the 'wonderfulness' of using Tcl-Tk scripts (and shell scripts) for making GUI's :

easy modification of the script(s)
to accomodate 'variations' over time.

Bottom of this page for
a Tk GUI for
ComputerMonitor-And-Audio
Movie-Capture

--- an 'ffmpeg' Front End
--- a utility in the FE 'tkGooies' system,
in the 'VIDEOtools' group.

To return to a previously visited web page location, click on the Back button of your web browser a sufficient number of times. OR, use the History-list option of your web browser.
OR ...

< Go to Top of Page, above. >

Page history:

The code was created in 2014 --- and posted 2014 May 30 at http://wiki.tcl.tk/40165.

This FE web page was created 2015 Jan 13.
(as a backup and alternative to the wiki.tcl.tk page)

This page was changed 2015 Oct 05.
(Small changes.)

Page was changed 2019 Feb 27.
(Added css and javascript to try to handle text-size for smartphones, esp. in portrait orientation.)

Page was changed 2019 Jun 25.
(Specified image widths in percents to size the images according to width of the browser window.)


NOTE:
The code here MAY BECOME more 'up-to-date' than the code posted on the Tcler's Wiki ---
wiki.tcl-lang.org --- formerly wiki.tcl.tk.