gopro_as_webcam_on_linux icon indicating copy to clipboard operation
gopro_as_webcam_on_linux copied to clipboard

ffmpeg freezed, wrong IP, rotation and 'nice-to-have's

Open adam-sas-on opened this issue 2 years ago • 0 comments

Thanks for your script. I would still struggle with other issues if there was no your gopro repo.
My camera is GoPro HERO10.

When ffmpeg is executed it gets freezed on this:

ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100

ifconfig shows positive values of RX packets/bytes for camera though.
It might be something with marking connection as ESTABLISHED. To remedy this I tried the script below before ffmpeg

gopro_device=`ip -4 --oneline link | grep -v "state DOWN" | grep -v "LOOPBACK" | grep -v "NO-CARRIER" | cut -f2 -d":" | tail -1`
# will succeed when goPro IP is last on the list: ip -4 --oneline link ...
gopro_ip=`ip -4 addr show dev $gopro_device | grep -Po '(?<=inet )[\d.]+'`
gopro_interface_ip=`echo "$gopro_ip" | awk -F"." '{print $1"."$2"."$3".51"}'`

# tcpdump
# GoPro has to be turned on to get its port, tcpdump will wait for the start of webcam mode: curl -s ${gopro_interface_ip}/gp/gpWebcam/START?res=480
gopro_port=`tcpdump -ni $gopro_device -c 1 dst port 8554 2>/dev/null | grep -o '51.[0-9]*' | grep -o '.[0-9]*$' | cut -c2-`
echo -n "gopro" | nc -w0 -u $gopro_interface_ip $gopro_port -s $gopro_ip -p 8554 >/dev/null

and voilà :-) ffmpeg works. Lets call it a "tcpdump script".


Wrong IP

It might be something with VPN connection when you turn on your GoPro before VPN resulting GoPro's IP being not last.
For that case

ip -4 --oneline link | grep -v "state DOWN" | grep -v "LOOPBACK" | grep -v "NO-CARRIER" | cut -f2 -d":" | tail -1

gives wrong name of device (~287 line of code).
Script will not work when -p | --device-pattern is not used.


Rotation issue

It might happen that you prefer portrait but on e.g. Zoom preview you are 'landscaped' :wink:
In ffmpeg one can add a rotation by slight change of format and add a metadata:

ffmpeg [...] -vf "rotate=PI/2,format=yuv420p" -metadata:s:v rotate=0 -f v4l2 /dev/video42

It might not be the best solutions because upper and bottom part of video are cropped, but I didn't find anything better yet.


Nice to have's

Exit webcam

One can quit webcam mode of GoPro by:
curl -s ${GOPRO_INTERFACE_IP}/gp/gpWebcam/EXIT
If it does not work, then /gopro/webcam/exit is another option to check.

"WebCam on demand"

ffmpeg consumes a lot of CPU, so option to finish it would be a better choice.
ffmpeg without -nostdin enables to press q for exit. With this option one can prepare for meeting

  1. curl -s ${GOPRO_INTERFACE_IP}/gp/gpWebcam/START?res=${GOPRO_RESOLUTION}
  2. "tcpdump script"
  3. start ffmpeg
  4. presentation, stand-up, lecture or anything else - you name it :wink: ...
  5. press q in ffmpeg
  6. stop webcam curl -s $GOPRO_INTERFACE_IP/gp/gpWebcam/STOP
  7. maybe also exit, but I didn't try that yet: curl -s ${GOPRO_INTERFACE_IP}/gp/gpWebcam/EXIT

Is there any video meeting soon? Go back to 1. step.

There are some minor challenges still, but I would still struggle with "webcam on linux user-story" if there was no your repo. Thanks for this. :)

adam-sas-on avatar Jun 16 '22 12:06 adam-sas-on