Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add port selection and video device selection #68

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ Options:

-V, --verbose echo every command that gets executed

-n, --video-number select the number of video device you would like to use. Default is 42. This means /dev/video42 will be created.

-P, --PORT select the port you would like to use. Default is 8554.

-h, --help display this help
Commands:
webcam start the GoPro in webcam mode
Expand Down
44 changes: 30 additions & 14 deletions gopro
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ globals() {
GOPRO_DEVICE=${GOPRO_DEVICE}
GOPRO_IP=${GOPRO_IP}
GOPRO_USER=${GOPRO_USER}
GOPRO_VIDEO_NUMBER=${GOPRO_VIDEO_NUMBER:-42}
GOPRO_PORT=${GOPRO_PORT:-8554}
}

DEPS=( "ffmpeg" "curl" )
module="v4l2loopback"
module_cmd="modprobe v4l2loopback exclusive_caps=1 card_label='GoPro' video_nr=42"
module_cmd_unload="modprobe -rf v4l2loopback"

START_PATH="/gp/gpWebcam/START?res="
START_PATH="/gp/gpWebcam/START"
# TODO: seems buggy atm, though
STOP_PATH="/gp/gpWebcam/STOP"
FOV_PATH="/gp/gpWebcam/SETTINGS?fov="
Expand Down Expand Up @@ -80,6 +82,12 @@ function run_args {
if [[ $GOPRO_USER ]]; then
>&2 echo " * User: $GOPRO_USER"
fi
if [[ $GOPRO_VIDEO_NUMBER ]]; then
>&2 echo " * Video Number: /dev/video$GOPRO_VIDEO_NUMBER"
fi
if [[ $GOPRO_PORT ]]; then
>&2 echo " * Port: $GOPRO_PORT"
fi
>&2 echo "=========================="
>&2 echo ""
}
Expand Down Expand Up @@ -115,6 +123,7 @@ function validate_arguments {
red "Please choose either \"wide\", \"linear\", or \"narrow\""
exit 1
fi
module_cmd="modprobe v4l2loopback exclusive_caps=1 card_label='GoPro'$GOPRO_VIDEO_NUMBER video_nr=$GOPRO_VIDEO_NUMBER"

if [[ ${GOPRO_RESOLUTION} -ne "1080" && ${GOPRO_RESOLUTION} -ne "720" && ${GOPRO_RESOLUTION} -ne "480" ]]; then
red "Please choose either \"1080\", \"720\", or \"480\""
Expand Down Expand Up @@ -154,6 +163,10 @@ Options:

-V, --verbose echo every command that gets executed

-n, --video-number select the number of video device you would like to use. Default is 42.

-P, --PORT select the port you would like to use. Default is 8554.

-h, --help display this help
Commands:
webcam start the GoPro in webcam mode
Expand Down Expand Up @@ -212,6 +225,14 @@ function parse_args {
DEPS+=('vlc')
GOPRO_PREVIEW=1
;;
-n|--video-number)
GOPRO_VIDEO_NUMBER=$2
shift
;;
-P|--PORT)
GOPRO_PORT=$2
shift
;;
-)
_EXTRA_ARGS+=("$(cat $2)")
_RAW_INPUT=1
Expand Down Expand Up @@ -340,20 +361,15 @@ function start_gopro_webcam_mode {

local response
# Switching to the GoPro Webcam mode
response=$(curl -s ${GOPRO_INTERFACE_IP}${START_PATH}${GOPRO_RESOLUTION})
# 一度にすべての設定を送信
response=$(curl -s "${GOPRO_INTERFACE_IP}${START_PATH}?res=${GOPRO_RESOLUTION}&fov=${GOPRO_FOV}&port=${GOPRO_PORT}")
if [ $? -ne 0 ]; then
red "Error while starting the Webcam mode. # TODO Useful message."
exit 1
fi
echo $response
if [[ -z "${response}" ]]; then
red "Did not receive a valid response from your GoPro. Please try again to run this script, timing is sometimes crucial."
red "Error while starting the Webcam mode."
exit 1
fi
response=$(curl -s ${GOPRO_INTERFACE_IP}${FOV_PATH}${GOPRO_FOV_ID})
echo $response
if [[ -z "${response}" ]]; then
red "Did not receive a valid response from your GoPro. Please try again to run this script, timing is sometimes crucial."
red "Did not receive a valid response from your GoPro. Please try again."
exit 1
fi

Expand Down Expand Up @@ -381,7 +397,7 @@ function expose_device {
if [ -n "${GOPRO_CROP}" ]; then
CROP=",crop=${GOPRO_CROP}"
fi
ffmpeg -nostdin -threads 1 -i 'udp://@0.0.0.0:8554?overrun_nonfatal=1&fifo_size=50000000' -f:v mpegts -fflags nobuffer -vf format="yuv420p${CROP}" -f v4l2 /dev/video42
ffmpeg -nostdin -threads 1 -i "udp://@0.0.0.0:${GOPRO_PORT}?overrun_nonfatal=1&fifo_size=50000000" -f:v mpegts -fflags nobuffer -vf format="yuv420p${CROP}" -f v4l2 /dev/video${GOPRO_VIDEO_NUMBER}
elif [[ ${GOPRO_PREVIEW} -eq 1 ]]; then
echo "Starting preview.."
start_preview
Expand All @@ -395,18 +411,18 @@ function expose_device {
function start_preview {

echo -e "To test this try this command(vlc needs to be installed): \n"
sudo -u $GOPRO_USER vlc -vvv --network-caching=300 --sout-x264-preset=ultrafast --sout-x264-tune=zerolatency --sout-x264-vbv-bufsize 0 --sout-transcode-threads 4 --no-audio udp://@:8554
sudo -u $GOPRO_USER vlc -vvv --network-caching=300 --sout-x264-preset=ultrafast --sout-x264-tune=zerolatency --sout-x264-vbv-bufsize 0 --sout-transcode-threads 4 --no-audio udp://@:${GOPRO_PORT}
}

function info_only {
echo -e "\n\nYou should be ready to use your GoPro on your prefered videostreaming tool. Have Fun!"

echo -e "\n\nIf you want to use the GoPro in your prefered Video conferencing software (browser and apps works alike) pipe the UDP stream to a video device (that was created already) with this command: \n"
green "ffmpeg -nostdin -threads 1 -i 'udp://@0.0.0.0:8554?overrun_nonfatal=1&fifo_size=50000000' -f:v mpegts -fflags nobuffer -vf format=yuv420p -f v4l2 /dev/video42"
green "ffmpeg -nostdin -threads 1 -i 'udp://@0.0.0.0:${GOPRO_PORT}?overrun_nonfatal=1&fifo_size=50000000' -f:v mpegts -fflags nobuffer -vf format=yuv420p -f v4l2 /dev/video${GOPRO_VIDEO_NUMBER}"

echo -e "\nTo get a preview of the output in vlc you can run this command"
echo -e "To test this try this command(vlc needs to be installed): \n"
green "vlc -vvv --network-caching=300 --sout-x264-preset=ultrafast --sout-x264-tune=zerolatency --sout-x264-vbv-bufsize 0 --sout-transcode-threads 4 --no-audio udp://@:8554"
green "vlc -vvv --network-caching=300 --sout-x264-preset=ultrafast --sout-x264-tune=zerolatency --sout-x264-vbv-bufsize 0 --sout-transcode-threads 4 --no-audio udp://@:${GOPRO_PORT}"
}


Expand Down