SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-11-01 03:25:59

Barnes
New Member
Registered: 2012-10-30
Posts: 8

Minimal Screencasting With FFmpeg

MINIMAL SCREENCASTING WITH FFMPEG

If you regularly screencast in full-screen mode then a quick and easy script based approach to starting and stopping ffmpeg makes a lot of sense.

Here we'll screencast losslessly to MKV and PCM with ffmpeg and convert later to lossy MP4/AAC formats using simple bash scripts.


A.  Install the necessary software:

    * media-video/ffmpeg
    * xfce-base/thunar
    * xfce-extra/xfce4-notifyd


B.  Create three bash scripts to control screencasting:

    open a terminal...
    # nano $HOME/Documents/screencast
    # nano $HOME/Documents/screencast-audio
    # nano $HOME/Documents/screencast-stop
    # chmod +x screencast screencast-audio screencast-stop
    # sudo cp screencast screencast-audio screencast-stop /usr/local/bin
   
      ---- copy and paste 1 of 3 ----

      #!/bin/bash

      # SCREENCAST = LOSSLESS SCREENCAST

      # =============
      # USER SETTINGS
      # =============
      OUTPUT="/data/files/Videos/Screencasts"
      KEYBOARDSTART="[ Alt + F1 ] keys pressed"
      KEYBOARDSTOP="[ Alt + F3 ] keys pressed"
      # =============

      # =========
      # VARIABLES
      # =========
      SIZE="1920x1080"
      RATE="24000/1001"
      VCODEC="libx264"

      PIXELS="yuv420p"
      PRESET="ultrafast"
      # =========

        # ===========
        # INFORMATION
        # ===========
       
        # ==========================================
        # keyboard bindings for chosen keys [rc.xml]
        # ==========================================
        # <keybind key="A-F1"><action name="Execute"><command>screencast</command></action></keybind>
        # <keybind key="A-F3"><action name="Execute"><command>screencast-stop</command></action></keybind>
        # ==========================================

        # ==============================
        # terminal conversion MKV >> MP4
        # ==============================
        # ffmpeg -i screencast.mkv -c:v libx264 -preset fast -crf 18 -y screencast.mp4
        # ==============================

        # ===============================
        # thunar custom action MKV >> MP4
        # ===============================
        # terminal --title="Screencast MKV Conversion to MP4" --geometry="200x35" --icon="$HOME/.icons/ffmpeg/convert.png" -e " ffmpeg -i %f -c:v libx264 -preset fast -crf 18 -y `basename %f .mkv`.mp4"
        # ===============================

      # ============
      # SCRIPT BELOW
      # ============

      # notification - starting
      notify-send -t 6000 "$KEYBOARDSTART : screencast will begin in 6 seconds"

      # pause!
      sleep 6

      # start screencasting losslessly without audio
      ffmpeg -f x11grab -s $SIZE -r $RATE -i :0.0 -c:v $VCODEC -pix_fmt $PIXELS -preset $PRESET -qp 0 -y "$OUTPUT"/screencast.mkv

      ## screencast-stop ## << script (assigned to keyboard shortcut) silently brings the ffmpeg process to a halt here! >>

      # notification - completion
      notify-send -t 3000  "$KEYBOARDSTOP : Screencast finished   :-)"

      # pause
      sleep 3

      # open thunar to show video
      thunar "$OUTPUT"
     
      ---- copy and paste 1 of 3 ----
     
      ---- copy and paste 2 of 3 ----
     
      #!/bin/bash

      # SCREENCAST-AUDIO = LOSSLESS SCREENCAST WITH AUDIO

      # =============
      # USER SETTINGS
      # =============
      OUTPUT="/data/files/Videos/Screencasts"
      KEYBOARDSTART="[ Alt + F2 ] keys pressed"
      KEYBOARDSTOP="[ Alt + F3 ] keys pressed"
      # =============

      # =========
      # VARIABLES
      # =========
      SIZE="1920x1080"
      RATE="24000/1001"
      VCODEC="libx264"
      ACODEC="pcm_s16le"
      PIXELS="yuv420p"
      PRESET="ultrafast"
      # =========

        # ===========
        # INFORMATION
        # ===========

        # ==========================================
        # keyboard bindings for chosen keys [rc.xml]
        # ==========================================
        # <keybind key="A-F2"><action name="Execute"><command>screencast-audio</command></action></keybind>
        # <keybind key="A-F3"><action name="Execute"><command>screencast-stop</command></action></keybind>
        # ==========================================

        # ======================================
        # terminal conversion MKV/PCM >> MP4/AAC
        # ======================================
        # ffmpeg -i screencast.mkv -c:a libfaac -ab 128k -ac 2 -c:v libx264 -preset fast -crf 18 -y screencast.mp4
        # ======================================
       
        # =======================================
        # thunar custom action MKV/PCM >> MP4/AAC
        # =======================================
        # terminal --title="Screencast MKV Conversion to MP4/AAC" --geometry="200x35" --icon="$HOME/.icons/ffmpeg/convert.png" -e " ffmpeg -i %f -c:a libfaac -ab 128k -ac 2 -c:v libx264 -preset fast -crf 18 -y `basename %f .mkv`.mp4"
        # =======================================
       
      # ============
      # SCRIPT BELOW
      # ============

      # notification - starting
      notify-send -t 6000 "$KEYBOARDSTART : screencast will begin in 6 seconds"

      # pause!
      sleep 6

      # start screencasting losslessly with audio
      ffmpeg -f alsa -ac 2 -i pulse -f x11grab -s $SIZE -r $RATE -i :0.0 -c:a $ACODEC -c:v $VCODEC -pix_fmt $PIXELS -preset $PRESET -qp 0 -y "$OUTPUT"/screencast.mkv

      ## screencast-stop ## << script (assigned to keyboard shortcut) silently brings the ffmpeg process to a halt here! >>

      # notification - completion
      notify-send -t 3000  "$KEYBOARDSTOP : Screencast finished   :-)"

      # pause
      sleep 3

      # open thunar to show video
      thunar "$OUTPUT"

      ---- copy and paste 2 of 3 ----

      ---- copy and paste 3 of 3 ----

      #!/bin/bash

      # Close the screencasting process gracefully
      # ==========================================
        killall -INT -w ffmpeg
      # ==========================================

      ---- copy and paste 3 of 3 ----

 
C.  Personalise the scripts:

    * Amend the script variables to your liking
   
    --> SIZE=screen size
    --> RATE=frame rate
    --> VCODEC=video codec
    --> ACODEC=audio codec
    --> PIXELS=pixel format
    --> PRESET=preset name
    --> OUTPUT=screencast output directory

    * Or, leave the defaults as they are and edit only the output and keybinding variables
   
    --> OUTPUT=screencast output directory
    --> KEYBOARDSTART="[ Alt + F2 ] keys pressed"
    --> KEYBOARDSTOP="[ Alt + F3 ] keys pressed"


D.  Create necessary keybindings to start and stop the screencasting process:

    * Set-up keyboard shortcuts to start and stop screencasting
    * The new keyboard keybindings will be available after logging out and back in

    open a terminal...
    # nano $HOME/.config/openbox/rc.xml
   
      ---- copy and paste ----

      <keyboard>

        <!-- screencasting keybinds -->
       
        <keybind key="A-F1"><action name="Execute"><command>screencast</command></action></keybind>
        <keybind key="A-F2"><action name="Execute"><command>screencast-audio</command></action></keybind>
        <keybind key="A-F3"><action name="Execute"><command>screencast-stop</command></action></keybind>
       
      </keyboard>

      ---- copy and paste ----
     
   
E.  Create scripts to convert the lossless screencast to lossy format:

    * Manually create thunar custom actions to facilitate conversion
   
      > Open Thunar >> menu : 'Edit'>> 'Configure custom actions...' >> Add a new custom action
     
     
      ---- create custom action 1 of 2 ----

      Name : MKV2MP4
      Description : Convert lossless MKV to lossy MP4
      Command : terminal -e "ffmpeg -i %f -c:v libx264 -preset fast -crf 18 -y `basename %f .mkv`.mp4"
      Icon : <choose one to your liking>

      File Pattern : *.mkv
      Appears if selection contains : Video Files
     
      ---- create custom action 1 of 2 ----
     
      ---- create custom action 2 of 2 ----     


      Name : MKV2MP4/AAC
      Description : Convert lossless MKV to lossy MP4/AAC
      Command : terminal -e " ffmpeg -i %f -c:a libfaac -ab 128k -ac 2 -c:v libx264 -preset fast -crf 18 -y `basename %f .mkv`.mp4"
      Icon : <choose one to your liking>

      File Pattern : *.mkv
      Appears if selection contains : Video Files

      ---- create custom action 2 of 2 ----


F.  Set-up notification:

    * Configure screen notifications to suit your screen
   
    open a terminal...
    # xfce4-notifyd-config
   
      ---- configuration ----

      Theme : your default theme
      Default position : place at the corner of your screen away from your panel
      Disappear after : 4 to 6 seconds seems ideal
      Opacity : up to you

      ---- configuration ----
     

G.  Finally, how to screencast:

    * According to my chosen keybinds in section D
    * Choosing to screencast without audio (you can always edit it in later with openshot)
   
    --> Alt + F1 = Start silent screencast
   
    --> Alt + F3 = Stop Screencast
   
    --> Convert MKV lossless screencast to MP4 format = via  MKV2MP4 Thunar custom action


All done

Last edited by Barnes (2012-12-03 12:08:53)

Offline

Be excellent to each other!

#2 2013-07-01 12:52:22

akovia
New Member
Registered: 2013-07-01
Posts: 1

Re: Minimal Screencasting With FFmpeg

Just fantastic and exactly what I was searching for! I was trying to build this myself when I ran across this.
I did add a couple things that might come in handy for others.

A popup window to enter the name of the screencast.
$INPUT=$(zenity --text "Name of Video?" --entry)......
"$OUTPUT"/"$INPUT".mkv

And I have it launch and stop key-mon to show onscreen keypresses for the no audio script.

Thanks again for these scripts. They were immensly helpful. big_smile
Cheers

Offline

#3 2013-10-06 09:15:58

OSuKaRu
New Member
Registered: 2013-10-06
Posts: 1

Re: Minimal Screencasting With FFmpeg

Very interesting script. And works!! big_smile
except for one little detail: neutral
I don't use OPENBOX. sad How can i configure the keybinds in Metacity?

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo