#!/usr/bin/perl ### ### this is a lesson recording utility ### uses scrot to get screenshots of the screen while I'm teaching ### the screenshots are taken at a given interval of seconds ### and saved in consecutively numbered files ### use Getopt::Std; getopts("so:ht:f:k"); $DFLT_DT = 10; $DFLT_FN = "screenshot"; $DFLT_VC = "out.mp4"; ### ### prepares a video out of the jpgs ### sub makevideo { my @args = @_; ### close audio track, if present if($opt_s) { print RECORD "stop\n"; close RECORD; } ### prepare video out of the snapshots $cmd = "avconv -f image2 -r 1/$delta -i $froot\%05d.jpg $video"; print "$cmd\n"; system($cmd); ### join audio and video if present if($opt_s) { $cmd = "avconv -i $video -i $audio -acodec copy -vcodec copy av_$video"; print "$cmd\n"; system($cmd); } exit; } use sigtrap 'handler' => \&makevideo, 'INT'; ### ### option handling ### if($opt_h) { print "Usage is:\nlesson.pl [-h] [-s] [-t secs] [-f filenameroot] [-o videofile.xxx] [-k]\n"; print "-h:\thelp\n"; print "-k:\tkeep existing images (default: remove)\n"; print "-s:\trecord audio as well\n"; exit; } if($opt_t) { $delta = $opt_t; } else { $delta = $DFLT_DT; } if($opt_f) { $froot = $opt_f; } else { $froot = $DFLT_FN; } $froot = $froot."_"; if($opt_o) { $video = $opt_o; } else { $video = $froot.".mp4"; } ### ### inizialization ### print "lesson.pl: capturing screen images every $delta secs in files named $froot"; print "NNN\n"; ### removing old jpg files if(!($opt_k)) { print "Removing old files $froot*.jpg\n"; $cmd = "rm -f $froot*.jpg"; print "--> $cmd\n"; system($cmd); print "Done!\n"; } ### sound processing if($opt_s) { $audio = $froot.".mp3"; open RECORD, "|ecasound -i alsa -o $audio -c" or die "cannot open ecasound\n"; } ### ### start looping ### $fcount = 0; while(1==1) { ### terminate upon ^C if($opt_s) { print RECORD "start\n"; } $cmd = sprintf("scrot %s%05d.jpg", $froot, $fcount); print "$cmd\n"; system($cmd); $fcount++; sleep $delta; ### wait delta seconds } exit;