Stream Webcam Feed from Pi using FFmpeg to VLC on Android
Connect webcam to raspberry pi USB 3.0 port
v4l2-ctl --list-devices - list all video capture devicessudo apt install ffmpeg - install ffmpegsudo apt v4l-utils - install v4l-utilsTest Webcam Input : ffmpeg -f v4l2 -i /dev/video0 -t 10 output.mp4 - record 10 secs from webcam into output.mp4
-f v4l2: Specifies the input format as Video4Linux2.-i /dev/video0: Sets your webcam as the input device.-t 10: Tells FFmpeg to record for 10 seconds.output.mp4: The output file where the video will be saved.Stream to Android using FFmpeg over UDP (Android phone’s IP address on the same WiFi)
ffmpeg \\
-f v4l2 -framerate 15 -video_size 640x480 -i /dev/video0 \\
-c:v libx264 -preset ultrafast \\
-tune zerolatency -f mpegts \\
udp://192.168.50.250:1234
Watch Stream on Android using VLC
Stream → udp://@:1234UDP Protocol
Stream Webcam Feed from Pi using FFmpeg to ExoPlayer on Android
Connect webcam to raspberry pi USB 3.0 port
v4l2-ctl --list-devices - list all video capture devicessudo apt install ffmpeg v4l-utils - install ffmpeg and v4l-utilsCreate a lightweight Web server: NGINX
sudo apt install nginx -y - install NGINXsudo systemctl start nginx - startsudo systemctl enable nginx - enable/var/www/html/ - NGINX serves files from herehttp://192.168.50.17/live/stream.m3u8Stream to Android using FFmpeg over HLS
Make Pi generate HLS chunks and .m3u8 playlist:
ffmpeg \\
-f v4l2 -framerate 15 -video_size 640x480 -i /dev/video0 \\
-c:v libx264 -preset ultrafast \\
-f hls -hls_time 2 -hls_list_size 4 -hls_flags delete_segments \\
/var/www/html/stream.m3u8
Test in VLC/browser first:
http://192.168.50.17/stream.m3u8In App ExoPlayer:
intent.putExtra("VIDEO_URL", "<http://192.168.50.17/stream.m3u8>");
FFmpeg Command
Input flags
-f v4l2: Use Video4Linux2 to access the webcam.-framerate 15: Capture at 15 frames per second.-video_size 640x480: Set the resolution to 640x480.-i /dev/video0: Sets webcam as the input device.Encoding flags
-c:v libx264: Encode the stream using H.264.