Send Motion-user mailing list submissions to motion-user@lists.sourceforge.net
To subscribe or unsubscribe via the World Wide Web, visit https://lists.sourceforge.net/lists/listinfo/motion-user or, via email, send a message with subject or body 'help' to motion-user-requ...@lists.sourceforge.net You can reach the person managing the list at motion-user-ow...@lists.sourceforge.net When replying, please edit your Subject line so it is more specific than "Re: Contents of Motion-user digest..." Today's Topics: 1. Network Stream and FPS (Valter Fukuoka) ---------------------------------------------------------------------- Message: 1 Date: Mon, 07 Mar 2022 13:35:57 +0900 From: Valter Fukuoka <alkoris...@eco.ever.jp> To: motion-user@lists.sourceforge.net Subject: [Motion-user] Network Stream and FPS Message-ID: <4e267dd9a9308b54c10b1d33d290f...@eco.ever.jp> Content-Type: text/plain; charset=US-ASCII; format=flowed Simple question about framerate, with lots of texts to support/reasoning it... QUESTION: Is there a "canonical complete" way to build a Motion JPEG for HTTP Stream, so that, it conforms to best of all which is the practice for a M-JPEG STREAM? Putting in other words: what is a good and complete example of Motion JPEG HTTP Stream that should be well interpreted by the majority of the common software like ffmpeg, Motion, Webbrowsers, etc... I am having a little trouble to get Motion (software), FFMPEG, FFPLAY to correctly interprete a HTTP MJPEG Stream, getting out of it the correct FPS... For ffmpeg and ffplay it works, besides the software guessing FPS at wrong frame rates... For Motion, it complain that was unable to get the FPS (from the stream)... WHAT I WANT? I can change the code of the Net Cam (it is opensource and very, very simple) from where the stream is coming from, so, I can try to put in there all the canonical metadata into the stream, so that Motion, ffmpeg, ffplay, etc, will work fine-tuned with the cam... My understanding of the Motion-JPEG "protocol" is something like this: STREAM HEADER { Metadata of the stream ... PART HEADER (the jpeg images) { Metadata of the image ... } PART HEADER (the jpeg images) { Metadata of the image ... } PART HEADER (the jpeg images) { Metadata of the image ... } } If this is correct, then, what should I put, and where should I put the info so that the stream can tell enough about itself to Motion, ffmpeg, ffplay alike? Data below are taken from the stream itself (using netcat). The Motion-JPEG stream is on "http://192.168.4.1:81/stream" Using netcat to dump the stream to a file (stdump.dat) $ echo -e "GET /stream HTTP/1.1\n" | nc 192.168.4.1 81 >stdump.dat Then, hexdump on the stdump.dat file. $ hexdump -C stdump.dat | head -n 25 00000000 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d |HTTP/1.1 200 OK.| 00000010 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 6d |.Content-Type: m| 00000020 75 6c 74 69 70 61 72 74 2f 78 2d 6d 69 78 65 64 |ultipart/x-mixed| 00000030 2d 72 65 70 6c 61 63 65 3b 62 6f 75 6e 64 61 72 |-replace;boundar| 00000040 79 3d 31 32 33 34 35 36 37 38 39 30 30 30 30 30 |y=12345678900000| 00000050 30 30 30 30 30 30 30 39 38 37 36 35 34 33 32 31 |0000000987654321| 00000060 0d 0a 54 72 61 6e 73 66 65 72 2d 45 6e 63 6f 64 |..Transfer-Encod| 00000070 69 6e 67 3a 20 63 68 75 6e 6b 65 64 0d 0a 41 63 |ing: chunked..Ac| 00000080 63 65 73 73 2d 43 6f 6e 74 72 6f 6c 2d 41 6c 6c |cess-Control-All| 00000090 6f 77 2d 4f 72 69 67 69 6e 3a 20 2a 0d 0a 58 2d |ow-Origin: *..X-| 000000a0 46 72 61 6d 65 72 61 74 65 3a 20 34 0d 0a 0d 0a |Framerate: 4....| 000000b0 32 34 0d 0a 0d 0a 2d 2d 31 32 33 34 35 36 37 38 |24....--12345678| 000000c0 39 30 30 30 30 30 30 30 30 30 30 30 30 39 38 37 |9000000000000987| 000000d0 36 35 34 33 32 31 0d 0a 0d 0a 34 63 0d 0a 43 6f |654321....4c..Co| 000000e0 6e 74 65 6e 74 2d 54 79 70 65 3a 20 69 6d 61 67 |ntent-Type: imag| 000000f0 65 2f 6a 70 65 67 0d 0a 43 6f 6e 74 65 6e 74 2d |e/jpeg..Content-| 00000100 4c 65 6e 67 74 68 3a 20 38 32 37 34 0d 0a 58 2d |Length: 8274..X-| 00000110 54 69 6d 65 53 74 61 6d 70 3a 20 37 31 33 33 2e |TimeStamp: 7133.| 00000120 37 30 36 32 31 35 0d 0a 0d 0a 0d 0a 32 30 35 32 |706215......2052| 00000130 0d 0a ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 |........JFIF....| 00000140 00 00 00 00 00 00 ff db 00 43 00 06 04 05 05 05 |.........C......| 00000150 04 06 05 05 05 07 06 06 07 09 0f 0a 09 08 08 09 |................| 00000160 12 0d 0e 0b 0f 16 13 17 17 15 13 15 15 18 1b 23 |...............#| 00000170 1d 18 1a 21 1a 15 15 1e 29 1e 21 24 25 27 27 27 |...!....).!$%'''| 00000180 17 1d 2a 2d 2a 26 2d 23 26 27 25 ff db 00 43 01 |..*-*&-#&'%...C.| With the help of nano editor, here is the head of the dump file above: ----------------------------- HTTP/1.1 200 OK Content-Type: multipart/x-mixed-replace;boundary=123456789000000000000987654321 Transfer-Encoding: chunked Access-Control-Allow-Origin: * X-Framerate: 4 24 --123456789000000000000987654321 4c Content-Type: image/jpeg Content-Length: 8274 X-TimeStamp: 7133.706215 ----------------------------- I am not able to account for the "24" and "4c" before and after the PART BOUNDARY... looking at the firmware code I could NOT see anything there in the section that build the stream... I think it is coming from something connected with the HTTP code... I am NOT sure what it is... These "24" and "4c" is also repeating itself on everything frame received!!! The "Network Cam" is a ESP32-CAMERA device, and it is the chepeast model out there ($6 in China)... My use for it only goes to lower resolutions, around and below 640x and low frame rates, 1 to 5 per second, so, besides the limitations of the device, it should NOT be a problem (for me) to use it as "network camera"... Right now, EVERYTHING works! Exceptions is this minor issue with ffplay, ffmpeg and 'Motion' that do not detect the framerate... ffmpeg and ffplay "guesses" to be 25fps... and yet it work ok... Motion just says that it was unable to determine FPS... Because we have access to the stream source code, I like to know what I can do to set a header, so that ffmpeg, ffplay and Motion will then, be able to get correct data about the framerate... I have set "X-Framerate: 4" on the header of the stream on the camera firmware, trying to get a "reading" of 4 FPS... (as you can see on the dump above) I also did a trick, on the firmware, so that it can ONLY send 4 frames per second, a kind of 250 millisecond hardware timed delay, it works, I checked it. The timestamp also seem to come in correct fashion, with approximate 0.250 secs separating each frame... // ----------------------- TIMESTAMPS Timestamps seems to be OK. Below are 4 frames taken from a dump file with the help nano editor. Content-Type: image/jpeg Content-Length: 8232 X-TimeStamp: 7134.385932 Content-Type: image/jpeg Content-Length: 8279 X-TimeStamp: 7134.645831 Content-Type: image/jpeg Content-Length: 8282 X-TimeStamp: 7134.885735 Content-Type: image/jpeg Content-Length: 8281 X-TimeStamp: 7135.145631 Placed on a spreadsheet, calculated the differences... THEY SEEMS OK for 4FPS (0.250 secs)... X-TimeStamp: 7134.385932 X-TimeStamp: 7134.645831 0.259898999999677 X-TimeStamp: 7134.885735 0.239904000000024 X-TimeStamp: 7135.145631 0.259896000000481 Still, ffplay, ffmpeg and motion does not see the metadata nor guess the correct number (from timestamps nor from the real data incoming rate)... OK, enough, this is it of data to support and reason my little question. About The "network camera"(ESP32 Camera Device) firmware code: It is the an ESP32 Arduino IDE example code, just install Arduino IDE (zip file), set up the ESP32 tools (extra download), and then you have all the examples code... Look for CAMERAWEBSERVER. It has a HTTP Server, a Wifi connection/access point and a camera code inside. It does still frame, stream and have a nice control panel for settings... I am doing a little basic (open) tutorial on ESP-camera stuff, almost done... I will mention this HTTP Stream server and Motion on the tutorial. Knowing the reason Motion is unable to "get" the FPS should help to resolve it by working on the firmware of the camera, or helping in giving a explanation to the readers... Also the Motion JPEG Stream stuff is a subject of my interest, and I will like to look after more understanding on the matter... and if this possible "canonical MJPEG Stream metadata format" exists, then, I like to know... I found Motion to be a very powerful tool, first using it for years with USB cams and x86 machines. Then, I just started using Motion with cheap SBCs, which, for me, made it release MUCH MORE power. Now, combined with a $6 Open Hard Open Soft "network camera"... well, this thing is about to go to "another level"!!! Thanks all, Valter ------------------------------ ------------------------------ Subject: Digest Footer _______________________________________________ Motion-user mailing list Motion-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/motion-user ------------------------------ End of Motion-user Digest, Vol 189, Issue 4 *******************************************