Roflkid
Posts: 6
Joined: Mon Jun 24, 2013 8:32 am

Webcam FFMPEG/AVCONV

Mon Jun 24, 2013 8:41 am

Hi zusammen,

ich habe derzeit ein Problem mit dem streaming einer Webcam vom PI aus.

Eher liegt das ganze m.E. nach an ffmpeg/avconv - ich habe hier eine Microsoft LifeCam Studio die mir der PI sowie mein Ubuntu Laptop einwandfrei auslesen und anzeigen (z.B. mit guvcview).

Nun will ich jedoch das Signal mit ffmpeg/avconv auslesen und per tcp an einen RTMP Server senden - soweit so gut funktioniert auch "alles". Um es kurz darzustellen mal hier der Log vom ffmpeg/avconv:

Code: Select all

pi@raspberrypi ~ $ avconv -loglevel 99 -f video4linux2 -r 30 -i /dev/video0 -r 30 -metadata streamName="Welpen" -f flv tcp://XX:6666/flvplayback
avconv version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers
  built on Mar 31 2013 13:58:10 with gcc 4.6.3
  configuration: --arch=arm --enable-pthreads --enable-runtime-cpudetect --extra-version='6:0.8.6-1+rpi1' --libdir=/usr/lib/arm-linux-gnueabihf --prefix=/usr --disable-yasm --enable-bzlib --enable-libdc1394 --enable-libdirac --enable-libfreetype --enable-frei0r --enable-gnutls --enable-libgsm --enable-libmp3lame --enable-librtmp --enable-libopencv --enable-libopenjpeg --enable-libpulse --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-vaapi --enable-vdpau --enable-libvorbis --enable-libvpx --enable-zlib --enable-gpl --enable-postproc --enable-swscale --enable-libcdio --enable-x11grab --enable-libx264 --enable-libxvid --shlibdir=/usr/lib/arm-linux-gnueabihf --enable-shared --disable-static
  libavutil    51. 22. 1 / 51. 22. 1
  libavcodec   53. 35. 0 / 53. 35. 0
  libavformat  53. 21. 1 / 53. 21. 1
  libavdevice  53.  2. 0 / 53.  2. 0
  libavfilter   2. 15. 0 /  2. 15. 0
  libswscale    2.  1. 0 /  2.  1. 0
  libpostproc  52.  0. 0 / 52.  0. 0
[video4linux2 @ 0x1ed87a0] [4]Capabilities: 4000001
[video4linux2 @ 0x1ed87a0] Querying the device for the current frame size
[video4linux2 @ 0x1ed87a0] Setting frame size to 640x480
[video4linux2 @ 0x1ed87a0] The V4L2 driver set input_id: 0, input: Camera 1
[video4linux2 @ 0x1ed87a0] Setting time per frame to 1/30
[rawvideo @ 0x1eda860] err{or,}_recognition separate: 1; 1
[rawvideo @ 0x1eda860] err{or,}_recognition combined: 1; 1
[video4linux2 @ 0x1ed87a0] All info found
[video4linux2 @ 0x1ed87a0] Estimating duration from bitrate, this may be inaccurate
Input #0, video4linux2, from '/dev/video0':
  Duration: N/A, start: 879.644206, bitrate: 147456 kb/s
    Stream #0.0, 1, 1/1000000: Video: rawvideo, yuyv422, 640x480, 1/30, 147456 kb/s, 30 tbr, 1000k tbn, 30 tbc
Incompatible pixel format 'yuyv422' for codec 'flv', auto-selecting format 'yuv420p'
[buffer @ 0x1ecdb80] w:640 h:480 pixfmt:yuyv422
[avsink @ 0x1ecdd20] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x1ece1a0] w:640 h:480 fmt:yuyv422 -> w:640 h:480 fmt:yuv420p flags:0x4
[flv @ 0x1ed9840] err{or,}_recognition separate: 1; 1
[flv @ 0x1ed9840] err{or,}_recognition combined: 1; 1
[flv @ 0x1ed9840] Unsupported bit depth: 0
[rawvideo @ 0x1eda860] err{or,}_recognition separate: 1; 1
[rawvideo @ 0x1eda860] err{or,}_recognition combined: 1; 1
Output #0, flv, to 'tcp://XX:6666/flvplayback':
  Metadata:
    streamName      : Welpen
    encoder         : Lavf53.21.1
    Stream #0.0, 0, 1/1000: Video: flv, yuv420p, 640x480, 1/30, q=2-31, 200 kb/s, 1k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (rawvideo -> flv)
Press ctrl-c to stop encoding
*** drop! 4 fps=  3 q=3.5 size=     157kB time=3.07 bitrate= 418.8kbits/s    
    Last message repeated 12 times
*** drop! 5 fps=  3 q=2.2 size=     201kB time=999.50 bitrate=   1.6kbits/s dup=0 drop=13    
    Last message repeated 1 times
*** drop! 6 fps=  2 q=2.0 size=     271kB time=1013.53 bitrate=   2.2kbits/s dup=0 drop=15    
    Last message repeated 11 times
*** drop! 7 fps=  2 q=2.0 size=     332kB time=1027.57 bitrate=   2.6kbits/s dup=0 drop=27    
    Last message repeated 8 times
*** drop! 9 fps=  2 q=2.0 size=     416kB time=1051.13 bitrate=   3.2kbits/s dup=0 drop=36    
    Last message repeated 12 times
*** drop!10 fps=  2 q=2.0 size=     457kB time=1072.13 bitrate=   3.5kbits/s dup=0 drop=49    
    Last message repeated 3 times
*** drop!12 fps=  3 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=53    
    Last message repeated 12 times
*** drop!12 fps=  2 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=66    
    Last message repeated 7 times
*** drop!12 fps=  2 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=74    
    Last message repeated 7 times
*** drop!12 fps=  2 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=82    
    Last message repeated 7 times
*** drop!12 fps=  2 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=90    
    Last message repeated 7 times
*** drop!12 fps=  2 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=98    
    Last message repeated 7 times
*** drop!12 fps=  2 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=106    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=114    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=122    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=130    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=138    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=146    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=154    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=162    
    Last message repeated 6 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=169    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=177    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=185    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=193    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=201    
    Last message repeated 7 times
*** drop!12 fps=  1 q=2.0 size=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=209    
^Cframe=   12 fps=  1 q=2.0 Lsize=     538kB time=1080.07 bitrate=   4.1kbits/s dup=0 drop=210    
video:538kB audio:0kB global headers:0kB muxing overhead 0.080069%
Received signal 2: terminating.
Wie zu sehen ist dropped der Pi fast alle Frames und der ganze Spaß läuft so gut wie gar nicht mehr. Bin schon etliche Tutorials durchgegangen aber bisher hat nichts geholfen, vielleicht hat ja hier noch wer eine Idee?! Das ist übrigens der Log von einem ganz frischen System - es wurde nichts geändert, lediglich ffmpeg/avconv aus dem aptitude installiert.

Freue mich sehr über jede Antwort oder Hilfestellung :)

Grüße Markus

stefan_a
Posts: 6
Joined: Wed Dec 12, 2012 5:00 am

Re: Webcam FFMPEG/AVCONV

Mon Jun 24, 2013 12:15 pm

Mahlzeit.
Also wenn ich das richtig sehe, hast Du von der Cam einen 14mbit/s stream, den Du on-the-fly zu einem flv stream transcodieren willst. Ich denk das kann der rpi nicht packen. Ich würde mal gucken, ob Du den stream nicht 1:1 zu Deinem rtsp-server schicken kannst, was wahrscheinlich mit 14mbit/s auch nicht ganz ohne ist.
Oder kann man die Datenrate der CAM einstellen?

Gruss
stefan

Roflkid
Posts: 6
Joined: Mon Jun 24, 2013 8:32 am

Re: Webcam FFMPEG/AVCONV

Mon Jun 24, 2013 2:19 pm

Naja die Datenrate zu begrenzen wäre sicherlich nicht das Problem - mittels "-r" weniger fps und "-s" geringere Auflösung. Aber selbst mit 10FPS und einer Auflösung von 154x140 oder so ähnlich komm ich nicht auf 10 FPS und er dropped etliche Frames.

Wenn ich mir die Auslastung vom Prozessor und RAM-Verbrauch ansehe ist beim transkodieren immer noch Luft nach oben :/

Die Cam unterstützt ja auch MJPEG als Ausgangsformat aber selbst dabei dropt er.

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Webcam FFMPEG/AVCONV

Mon Jun 24, 2013 3:30 pm

Alle Updates auf dem System ? Besonders USB wurde und wird ständig verbessert .

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Roflkid
Posts: 6
Joined: Mon Jun 24, 2013 8:32 am

Re: Webcam FFMPEG/AVCONV

Mon Jun 24, 2013 4:04 pm

Habs mit Raspbian Wheeze vom 25.05.2013 ohne updates sowie mit updates probiert - bei beiden kein Unterschied.

li-la
Posts: 17
Joined: Wed Aug 01, 2012 4:04 pm

Re: Webcam FFMPEG/AVCONV

Mon Jun 24, 2013 6:18 pm

Roflkid wrote:Habs mit Raspbian Wheeze vom 25.05.2013 ohne updates sowie mit updates probiert - bei beiden kein Unterschied.
Ich fuerchte die Kanonen ffmpeg/avconv sind fuer den kleinen Pi einfach zu gross. Mein Spatz hier ist mjpg-streamer-r63. Der Stream meiner webcam wird hier mit ca. 30% cpu Belastung ausgegeben.

Code: Select all

./mjpg_streamer -i "input_uvc.so -r 1280×1024 -d /dev/video0 -y" -o "output_http.so -w ./www"
wenn ich aus der Doku des Programms mal zitieren darf:
"MJPG-streamer", is a command line application that copied JPG-frame from a single input plugin to multiple output plugins. It can be used to stream JPEG files over an IP-based network from the webcam to a viewer like Firefox, Cambozola, Videolanclient or even to a Windows Mobile device running the TCPMP-Player.

It was written for embedded devices with very limited ressources in terms of RAM and CPU. Its origin, the "uvc_streamer" was written, because Linux-UVC compatible cameras directly produce JPEG-data, allowing fast and perfomant M-JPEG streams even from an embedded device running OpenWRT. The input module "input_uvc.so" captures such JPG frames from a connected webcam.

This tool can be modified and distributed according to the terms of the GPL v2.

Currently no issues are known, but since this software is quite young and not used widely it may cause problems. You must really know what you are doing, if you use this software. If you want to use the software you are obliged to check if the sourcecode does what you expect it to do and take the risk yourself to use it.

To view the stream use VLC or Firefox and open the URL:
http://127.0.0.1:8080/?action=stream

To view a single JPEG just call:
http://127.0.0.1:8080/?action=snapshot
Ein Mini Webserver mit sample Code ist auch im source dabei. Damit hab ich das hier schnell funktionsfaehig bekommen.

have fun,
cu Frank

Roflkid
Posts: 6
Joined: Mon Jun 24, 2013 8:32 am

Re: Webcam FFMPEG/AVCONV

Mon Jun 24, 2013 9:28 pm

Hi Frank,

das ganze mit dem MJPEG-Streamer habe ich ebenfalls probiert - funktioniert an sich auch nicht schlecht. Ich würde dennoch die ffmpeg Variante bevorzugen - diese wird ebenfalls des öfteren bei den neuen Camera-Boards verwendet.

Ein Tutorial dazu auch Online:
http://www.slickstreamer.info/2013/06/u ... le-to.html

und hier z.B. zu Bambuser (ich verwende einen eigenen Server)
http://www.slickstreamer.info/2012/11/u ... video.html

Ich verstehe nur nicht wieso das bei ihm so locker funktioniert, und bei mir gar nicht :/
Vielleicht liegt es ja auch gar nicht an ffmpeg sondern am Video4Linux?!

ghans
Posts: 7882
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Webcam FFMPEG/AVCONV

Tue Jun 25, 2013 12:08 pm

Probier mal rpi-update ...

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Roflkid
Posts: 6
Joined: Mon Jun 24, 2013 8:32 am

Re: Webcam FFMPEG/AVCONV

Tue Jun 25, 2013 12:12 pm

Habs ebenfalls nach rpi-update wie davor ausprobiert. Habe es gerad auch an einem anderen Raspberry probiert - auch dort kein Erfolg. Auf meinem MacBook sowie unter Ubuntu läuft es einwandfrei.

Bin gerad dabei RSE auf die SD Karte zu schmeißen und dann mal ffmpeg selber zu kompilieren - mal sehen was das wird.

Return to “Deutsch”