Skip to content

Commit

Permalink
error out if the area to record is outside of the root window, build …
Browse files Browse the repository at this point in the history
…intersection rectangle between desired area and root window, fixes #3
  • Loading branch information
phisch committed Jun 4, 2019
1 parent 8e52600 commit cc1af4c
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/giph
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,42 @@ function get_geometry_for_desktop() {
}

function parse_geometry_string() {
[[ $GEOMETRY_STRING =~ ([0-9]+)x([0-9]+)[+]?([+-][0-9]+)[+]?([+-][0-9]+) ]]
[[ $GEOMETRY_STRING =~ ([0-9]+)x([0-9]+)[+]?([-]?[0-9]+)[+]?([-]?[0-9]+) ]]

width=${BASH_REMATCH[1]}
height=${BASH_REMATCH[2]}
offset_x=${BASH_REMATCH[3]}
offset_y=${BASH_REMATCH[4]}
x=${BASH_REMATCH[3]}
y=${BASH_REMATCH[4]}

[ -z "$width" ] || [ -z "$height" ] || [ -z "$offset_x" ] || [ -z "$offset_y" ] && {
[ -z "$width" ] || [ -z "$height" ] || [ -z "$x" ] || [ -z "$y" ] && {
log_error "could not parse geometry string '$GEOMETRY_STRING'"
}

[ "$offset_x" -lt 0 ] && {
width=$((width+offset_x))
offset_x="+0"
get_geometry_for_desktop

[ "$x" -gt "$WIDTH" ] || [ $((x + width)) -lt 0 ] || [ "$y" -gt "$HEIGHT" ] || [ $((y + height)) -lt 0 ] && {
log_error "the area to record is fully outside of the root window"
}

[ "$x" -lt 0 ] && {
width=$((width + x))
x="0"
}

[ "$offset_y" -lt 0 ] && {
height=$((height+offset_y))
offset_y="+0"
[ "$y" -lt 0 ] && {
height=$((height + y))
y="0"
}

[ $((x+width)) -gt "$WIDTH" ] && {
let width-=$((x + width - WIDTH))
}

[ $((y+height)) -gt "$HEIGHT" ] && {
let height-=$((y + height - HEIGHT))
}

log "parsed geometry: width=$width, height=$height, offset_x=$offset_x, offset_y=$offset_y" 2 true
log "parsed geometry: width=$width, height=$height, x=$x, y=$y" 2 true
}

function create_temporary_directory() {
Expand All @@ -274,7 +288,7 @@ function start_video_recording() {
ffmpeg+=(-f x11grab)
ffmpeg+=(-framerate "$FRAMERATE")
ffmpeg+=(-s "$width"x"$height")
ffmpeg+=(-i :0.0"$offset_x","$offset_y")
ffmpeg+=(-i :0.0+"$x","$y")
ffmpeg+=(-preset ultrafast)
ffmpeg+=(-crf 0)

Expand Down

0 comments on commit cc1af4c

Please sign in to comment.