You are not logged in.
Pages: 1
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
Pages: 1
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.