samtap / fang-hacks

Collection of modifications for the XiaoFang WiFi Camera
1.67k stars 340 forks source link

Time-lapse possibility #15

Open mstraa opened 7 years ago

mstraa commented 7 years ago

Hey, first thanks very much for the hacks!

I bought 2 xiaofang for time lapse purposes. How do you think I can do that? I saw that motion or motion-noffmpeg could do the trick. Do I need to find binaries for armv5 ?

Another thing, how can I know the specs of the camera ?

I really want to contribute, If you can show me the direction I will follow ! :)

tobilap commented 7 years ago

The easiest way for you would be to setup a small server(e.g. raspberry pi) and use ffmpeg on it using the RTSP streams from the 2 cameras. Your could just start the rtsp server with -F 1 which reduces the FPS to 1 as you want to do a timelapse anyway. The Camera itself does not have much CPU power, most of the things have their own hardware units( e.g. the video encoding) to be efficient. It does not require lots of CPU power.

mstraa commented 7 years ago

Thanks ! I will try that !

Any idea how to get the best image feed from rtsp? The finest and the best resolution ?

tobilap commented 7 years ago

You can use any setting you want, Increasing the resolution up to 1920 * 1080 but important is that you increase the bitrate (e.g. -b 2048 on 720p streams) to get good quality Images delivered.

samtap commented 7 years ago

I think you will see that when connecting to snx_rtsp_server, the first frames are always garbage... Very inconvenient for taking a snapshot.

tobilap commented 7 years ago

How about MJPEG instead of h264 as it compresses every single frame?

magnets110 commented 7 years ago

You can try decreasing the GOP size to stop the junk frames at the start of the stream. -g 10 on the snx rtsp server

I believe this will result in worse compression rates

The camera should be powerful enough to dump the stream to disk, there isn't any encoding required. The camera does motion detection in hardware so you can pull from that. I think samtap is working on doing something like that

mstraa commented 7 years ago

So I tried with those params : snx_rtsp_server -W 1920 -H 1080 -j 25 -Q 1 -F 1 I get a good quality of my desk (>1m) but when I turn the cam to the room, quality decrease and I get some frames (not all) with an error with a buffer size :

MultiFramedRTPSink::afterGettingFrame1(): The input frame data was too large for our buffer size (263512). 71124 bytes of trailing data was dropped! Correct this by increasing "OutPacketBuffer::maxSize" to at least 333268, *before* creating this 'RTPSink'. (Current value is 262144.)

Edit : If possible I prefer to do all in the xiaofang cam, I would like to take a raw picture and put it in the sdcard. I saw this : capture v4l2. Do you think I can try to work with this to do the job ?

mstraa commented 7 years ago

Well the rtsp stream works fine with vlc but I can't get it with ffmpeg.

Server : snx_rtsp_server -W 1920 -H 1080 -j 25 -Q 1 -F 1

Ffmpeg : ffmpeg.exe -rtsp_transport tcp -i rtsp://192.168.1.164/unicast

Error : Trailing options were found on the commandline. [rtsp @ 000000000030a400] Invalid RTP/JPEG packet. Quantization tables not found. [rtsp @ 000000000030a400] Received packet without a start chunk; dropping frame. Last message repeated 118 times [rtsp @ 000000000030a400] Invalid RTP/JPEG packet. Quantization tables not found. [rtsp @ 000000000030a400] Received packet without a start chunk; dropping frame. Last message repeated 126 times [rtsp @ 000000000030a400] Invalid RTP/JPEG packet. Quantization tables not found. [rtsp @ 000000000030a400] Received packet without a start chunk; dropping frame. Last message repeated 127 times [rtsp @ 000000000030a400] Invalid RTP/JPEG packet. Quantization tables not found. [rtsp @ 000000000030a400] Received packet without a start chunk; dropping frame. Last message repeated 127 times [rtsp @ 000000000030a400] Invalid RTP/JPEG packet. Quantization tables not found. [rtsp @ 000000000030a400] Received packet without a start chunk; dropping frame. Last message repeated 123 times .

samtap commented 7 years ago

@mstraa Think your ffmpeg is broken. The RTSP stream is encoded in H264 (not MJPEG). The following command works for me, it stores one jpg per second: ffmpeg -i rtsp://cam-ip/unicast -vf fps=1 /tmp/img%03d.jpg

mstraa commented 7 years ago

I tried few ffmpeg bin (32bit 64bit / 3.2.2 Nightly) and i get always the same error. Can you tell me what params do you run the rstp server ?

virualdo commented 7 years ago

@mstraa My ffmpeg script was working fine until i've updated the snx_rtsp_server file with the version that have jpg stream. https://github.com/samtap/fang-hacks/issues/87#issuecomment-318074811 When i updated that file i've started to have this error. I've tried with other ffmpeg files in my pc without any luck. I think that the rtsp stream have some kind of incomplete metadata and ffmpeg process fails when try to use it.