Last active
May 13, 2020 19:05
-
-
Save notdodo/2f4e957c66ea01939843e224e8bb56f3 to your computer and use it in GitHub Desktop.
If you have some protected/licensed slides that require a non-open/compatible PDF reader (i.e. Locklizard) you can use this commands to bypass the block.
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
#!/usr/bin/bash | |
# | |
# Author notdodo | |
# | |
# | |
############################################################################### | |
# SCENARIO #################################################################### | |
############################################################################### | |
# If you have some protected/licensed slides that require a non-open/compatible | |
# PDF reader (i.e. Locklizard) you can use this commands to bypass the block. | |
# The idea is to capture the screen of the Windows VM where the slides are | |
# displayed in an automated fashion. | |
# Setup: using two screens should be better since on the first one you can open | |
# and leave the Windows VM, on the other one open this guide and a terminal. | |
# Check requirements | |
if ! hash ffcast 2>/dev/null; then | |
echo "Please install ffcast" | |
exit -1 | |
fi | |
if ! hash ffmpeg 2>/dev/null; then | |
echo "Please install ffmpeg" | |
exit -1 | |
fi | |
if ! hash xdotool 2>/dev/null; then | |
echo "Please install xdotool" | |
exit -1 | |
fi | |
# ffcast: select a portion of the screen where the protected slides are present, | |
# the command will create a video in the home directory (output.avi). | |
## Options: high quality and 1 frame per second | |
## To stop the recording press ctrl+c | |
alias screencast='ffcast -s % ffmpeg -y -f x11grab -show_region 1 -framerate 1 -video_size %s -i %D+%c -codec:v huffyuv -vf crop="iw-mod(iw\\,2):ih-mod(ih\\,2)" ~/output.avi' | |
# Once the recording is complete: | |
alias extract_frames='mkdir ~/frames/; ffmpeg ~/frames/slide%05d.png -i ~/output.avi' | |
# This command extracts all PNGs from the video creating a list of "slides" in the `frame` directory. | |
# To clean all duplicates execute in the `frame` directory: | |
alias clean_frames='md5sum * | sort | awk '"'"'BEGIN{lsthash = ""} $1 == lsthash {print $2} {lsthash=$1}'"'"' | xargs rm' | |
# Press the key Page_Down every 2 seconds | |
alias auto_press_pgdown='sleep 1; for i in {1..1000}; do xdotool key Page_Down; sleep 2; done' | |
############################################################################### | |
# FLOW ######################################################################## | |
############################################################################### | |
# | |
# 1. Open the PDF file on the VM: set the reader to the correct zoom and in | |
# full screen (the page should be fully visible and readable, if necessary use | |
# a better/bigger screen; FullHD/2k at least). | |
# | |
# 2. Execute this script to set the new aliases | |
# | |
# 3. Run the `screencast` command and select the screen region where the slide | |
# is visible | |
# | |
# 4. In another terminal rerun this script and execute `auto_press_pgdown` | |
# | |
# 5. Quickly change the focus of the window to the WindowsVM to allow the | |
# Linux host to send the keypress. | |
# | |
# 6. Wait until the PDF is scrolled to the end and then press Ctrl+c on both | |
# opened terminal (`screencast` and `auto_press_pgdown`) | |
# | |
# 7. `output.avi` should be in your home directory | |
# | |
# 8. Execute `extract_frames` to create the `frames` folder and get all frames | |
# from the AVI | |
# | |
# 9. Since it's possible that some frames are duplicated execute `clean_frames` | |
# | |
# 10. In `~/frames/` now you have all the single pages of the PDF. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment