Last active
August 24, 2018 18:03
-
-
Save unique1984/6786054623ebc543b60620dc0127d177 to your computer and use it in GitHub Desktop.
Screen Recorder Shell Script with ffmpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#--------------------------------------------------------------------- | |
# screenrec.sh | |
# | |
# ffmpeg shellscript screen recorder | |
# | |
# Script: screenrec.sh | |
# Version: 1.1.0 | |
# Author: Yasin KARABULAK <yasinkarabulak@gmail.com> | |
# | |
# * monitor detection automatized. (xrandr) | |
# * php eleminated. (using date) | |
# * performance issues fixed. (nice -10) | |
#--------------------------------------------------------------------- | |
if [ -z $(which ffmpeg) ]; then | |
echo -e "ffmpeg bulunamadı!" | |
exit | |
fi | |
basedir="/home/yasin/Videolar/screen_records" | |
ffcmd="nice -10 $(which ffmpeg)" | |
year=$(date +"%Y") | |
month=$(date +"%m") | |
day=$(date +"%d") | |
recdir="$basedir/$year/$month/$day" | |
framerate=12 | |
#~ monitors=$(xrandr --listmonitors | awk '{print $4}' | grep -P "[^ ]") | |
monitors=$(xrandr | grep \* |awk '{print $1}') | |
monitor_count=$(xrandr | grep \* |awk '{print $1}' | wc -l) | |
ilk=$(echo $monitors | awk '{print $1}') | |
if [ $monitor_count -gt 1 ]; then | |
iki=$(echo $monitors | awk '{print $2}') | |
ilk_width=$(echo $ilk | awk -F"x" '{print $1}') | |
ilk_height=$(echo $ilk | awk -F"x" '{print $2}') | |
iki_width=$(echo $iki | awk -F"x" '{print $1}') | |
iki_height=$(echo $iki | awk -F"x" '{print $2}') | |
full_width=$(($ilk_width+$iki_width)) | |
if [ $ilk_height -gt $iki_height ]; then | |
max_height=$ilk_height | |
elif [ $iki_height -gt $ilk_height ]; then | |
max_height=$iki_height | |
else | |
max_height=$ilk_height | |
fi | |
offset="$ilk_width,0" | |
else | |
ilk_width=$(echo $ilk | awk -F"x" '{print $1}') | |
ilk_height=$(echo $ilk | awk -F"x" '{print $2}') | |
full_width=$ilk_width | |
max_height=$ilk_height | |
offset="0,0" | |
fi | |
full=$full_width"x"$max_height | |
#~ echo $ilk $iki $full_width $max_height $full $offset | |
if [ ! -d "$recdir" ]; then | |
mkdir -p "$recdir" | |
else | |
echo "$recdir" | |
fi | |
if [ -z $1 ]; then | |
echo "Kayıt yapılacak ekranı seçin | Seçenekler => full 1st 2nd showcam webcam | 2. argüman olarak ses yazıldığında sesli kayıt aktifleştirilmiş olunur." | |
else | |
if [ "$1" = "full" ] && [ -z $2 ]; then | |
queue="$(ls $recdir/output_$1*|wc -l)" | |
$ffcmd -video_size $full -framerate $framerate -f x11grab -i :0.0+0,0 -c:v libx264 "$recdir/output_$1_screen_$queue.mp4" | |
elif [ "$1" = "full" ] && [ "$2" = "ses" ]; then | |
queue="$(ls $recdir/output_$1_sesli*|wc -l)" | |
$ffcmd -video_size $full -framerate 30 -f x11grab -i :0.0+0,0 -f pulse -ac 2 -i default -c:v libx264 -preset ultrafast "$recdir/output_$1_sesli_screen_$queue.mp4" | |
elif [ "$1" = "1st" ] && [ -z $2 ]; then | |
queue="$(ls $recdir/output_$1*|wc -l)" | |
$ffcmd -video_size $ilk -framerate $framerate -f x11grab -i :0.0+0,0 -c:v libx264 "$recdir/output_$1_screen_$queue.mp4" | |
elif [ "$1" = "1st" ] && [ "$2" = "ses" ]; then | |
queue="$(ls $recdir/output_$1_sesli*|wc -l)" | |
$ffcmd -video_size $ilk -framerate 30 -f x11grab -i :0.0+0,0 -f pulse -ac 2 -i default -c:v libx264 -preset ultrafast "$recdir/output_$1_sesli_screen_$queue.mp4" | |
elif [ "$1" = "2nd" ] && [ -z $2 ]; then | |
queue="$(ls $recdir/output_$1*|wc -l)" | |
$ffcmd -video_size $iki -framerate $framerate -f x11grab -i :0.0+$offset -c:v libx264 "$recdir/output_$1_screen_$queue.mp4" | |
elif [ "$1" = "2nd" ] && [ "$2" = "ses" ]; then | |
queue="$(ls $recdir/output_$1_sesli*|wc -l)" | |
$ffcmd -video_size $iki -framerate 30 -f x11grab -i :0.0+$offset -f pulse -ac 2 -i default -c:v libx264 -preset ultrafast "$recdir/output_$1_sesli_screen_$queue.mp4" | |
elif [ "$1" = "showcam" ]; then | |
#ffmpeg -f v4l2 -list_formats all -i /dev/video0 | |
$(which ffplay) -f video4linux2 -framerate 30 -video_size hd720 /dev/video0 | |
elif [ "$1" = "webcam" ] && [ -z $2 ]; then | |
queue="$(ls $recdir/output_$1*|wc -l)" | |
$ffcmd -f video4linux2 -video_size 1280x720 -input_format mjpeg -i /dev/video0 "$recdir/output_$1_$queue.mpeg" | |
else | |
echo "$1 argümanı için işlem tanımlanmadı !" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment