Created
April 26, 2017 12:27
Star
You must be signed in to star a gist
Run an Android emulator with a fake webcam
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 | |
export REAL_DEVICE="/dev/video0" | |
export FAKE_DEVICE="/dev/video1" | |
export DURATION="5" | |
export SIZE="320x240" | |
export AVD="Nexus_5X_API_25" | |
export VIDEO_FILE="./webcam.avi" | |
record_webcam() | |
{ | |
declare video_fp="${1}" | |
ffmpeg \ | |
-loglevel "quiet" \ | |
-y \ | |
-f "v4l2" \ | |
-r "30" \ | |
-s "${SIZE}" \ | |
-i "${REAL_DEVICE}" \ | |
-pix_fmt "yuv420p" \ | |
-vcodec "libx264" \ | |
-ss "00:00:0.0" -t "${DURATION}" \ | |
"${video_fp}" | |
} | |
fake_webcam() | |
{ | |
declare video_fp="${1}" | |
ffmpeg \ | |
-loglevel "quiet" \ | |
-re \ | |
-f "lavfi" \ | |
-i "movie=filename=${video_fp}:loop=0, setpts=N/(FRAME_RATE*TB)" \ | |
-f "v4l2" "${FAKE_DEVICE}" | |
} | |
run_emulator() | |
{ | |
cd "${ANDROID_HOME}/tools" | |
./emulator @${AVD} -camera-back "webcam1" | |
cd - | |
} | |
main() | |
{ | |
sudo modprobe "v4l2loopback" | |
declare action="${1:-"run"}" | |
shift | |
case "${action}" in | |
"run") | |
( | |
fake_webcam "${VIDEO_FILE}" | |
) & | |
declare ffmpeg_pid="${!}" | |
run_emulator | |
pkill -TERM -P "${ffmpeg_pid}" | |
;; | |
"record") | |
record_webcam "${VIDEO_FILE}" | |
;; | |
esac | |
} | |
main "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you tell me how to use this? thanks in advance