markszabo / tapo-c200-timelapse

This is my setup to take time-lapse videos from my balcony with a Raspberry Pi using a TP-Link Tapo C200 IP-Camera
91 stars 17 forks source link

makevideo.py failing #3

Closed dazmanic closed 3 years ago

dazmanic commented 3 years ago

Hi there, I wonder if you could help me.

I am having trouble getting makevideo.py to work, it keeps getting so far then failing with the message "killed" usually between frame 45 and 60. I've got the image taking process to work and have a cronjob doing that fine, images are being created every minute, but I'm stuck as to why makevideo.py isn't completing.

I am running the script on a Raspberry Pi 3B+, Raspbian Stretch. The pi is doing other jobs for me (Pi-hole, torrenting) So I haven't got round to updating it to the latest version of Raspbian. Could this be the issue? I'm suspecting that it's running out of RAM whilst trying to compile the video, is there any way I could get around this if this is the problem?

This is the output I get (and the furthest along the process it has got so far)

pi@raspberrypi:~/timelapse $ python3 makevideo.py ffmpeg version 3.2.15-0+deb9u2 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1+deb9u1) 20170516 configuration: --prefix=/usr --extra-version=0+deb9u2 --toolchain=hardened --libdir=/usr/lib/arm-linux-gnueabihf --incdir=/usr/include/arm-linux-gnueabihf --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libebur128 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared libavutil 55. 34.101 / 55. 34.101 libavcodec 57. 64.101 / 57. 64.101 libavformat 57. 56.101 / 57. 56.101 libavdevice 57. 1.100 / 57. 1.100 libavfilter 6. 65.100 / 6. 65.100 libavresample 3. 1. 0 / 3. 1. 0 libswscale 4. 2.100 / 4. 2.100 libswresample 2. 3.100 / 2. 3.100 libpostproc 54. 1.100 / 54. 1.100 Input #0, image2, from '*.png': Duration: 00:00:22.76, start: 0.000000, bitrate: N/A Stream #0:0: Video: png, rgb24(pc), 1920x1080, 25 fps, 25 tbr, 25 tbn, 25 tbc File '/media/usb1/timelapse/daily/2021-02-13.mp4' already exists. Overwrite ? [y/N] y No pixel format specified, yuv444p for H.264 encoding chosen. Use -pix_fmt yuv420p for compatibility with outdated media players. [libx264 @ 0x1f315c0] using cpu capabilities: ARMv6 NEON [libx264 @ 0x1f315c0] profile High 4:4:4 Predictive, level 4.0, 4:4:4 8-bit [libx264 @ 0x1f315c0] 264 - core 148 r2748 97eaef2 - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=4 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=24 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 Output #0, mp4, to '/media/usb1/timelapse/daily/2021-02-13.mp4': Metadata: encoder : Lavf57.56.101 Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv444p, 1920x1080, q=-1--1, 24 fps, 12288 tbn, 24 tbc Metadata: encoder : Lavc57.64.101 libx264 Side data: cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1 Stream mapping: Stream #0:0 -> #0:0 (png (native) -> h264 (libx264)) Press [q] to stop, [?] for help frame= 2 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 4 fps=2.7 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
frame= 6 fps=2.6 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 8 fps=2.5 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 10 fps=2.4 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
frame= 12 fps=2.4 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 14 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 16 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 18 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 20 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 22 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 24 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 26 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 28 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
frame= 30 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 32 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 34 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 36 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 38 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 40 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
frame= 42 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 44 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
frame= 46 fps=2.3 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 47 fps=1.8 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed=
frame= 48 fps=1.8 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 50 fps=1.8 q=0.0 size= 0kB time=00:00:00.00 bitrate=N/A speed= frame= 51 fps=1.8 q=28.0 size= 74kB time=-00:00:00.08 bitrate=N/A speed=N frame= 52 fps=1.8 q=28.0 size= 150kB time=-00:00:00.04 bitrate=N/A speed=N frame= 53 fps=1.8 q=28.0 size= 176kB time=00:00:00.00 bitrate=17812839.5kb frame= 54 fps=1.8 q=28.0 size= 190kB time=00:00:00.04 bitrate=37214.3kbits frame= 55 fps=1.8 q=28.0 size= 203kB time=00:00:00.08 bitrate=19982.8kbits frame= 56 fps=1.3 q=28.0 size= 260kB time=00:00:00.12 bitrate=17029.3kbits frame= 57 fps=1.3 q=28.0 size= 277kB time=00:00:00.16 bitrate=13625.1kbits frame= 58 fps=1.3 q=28.0 size= 291kB time=00:00:00.20 bitrate=11456.9kbits frame= 59 fps=1.3 q=28.0 size= 308kB time=00:00:00.25 bitrate=10094.4kbits Killeded=0.00538x

Sometimes the error message is

x264 [error]: Killed

Hope I've formatted that correctly, I'm new to GitHub! If there's any more information you need let me know.

Thanks

dazmanic commented 3 years ago

OK so I've got a little bit further ahead now with playing around with ffmpeg. I've not used it before so it's new to me.

If I try and manually create a video using ffmpeg -r 24 -pattern_type glob -i '*.png' video_test.avi it works, and I get a video, if I use ffmpeg -r 24 -pattern_type glob -i '*.png' video_test.mp4 I get the same failure as before.

So I'm not sure what's up with it if it can create an avi file but not an mp4. Could I be missing something that I need to install?

The avi file is a bit blocky, so doesn't look great, but it's something at least!

dazmanic commented 3 years ago

I think I've sorted it now.

My best guess is that it's a hardware limitation issue as I can successfully create 720p mp4s but not 1080p mp4s.

I manually ran ffmpeg -r 24 -pattern_type glob -i '*.png' -s hd720 -vcodec libx264 video_test.mp4 and was able to make a video. I edited makevideo.py to change hd1080 to hd720 in line 10, and it now works as it should. Added the edited script as a cron job, will be able to see tomorrow if it was successful. I presume I'll have to make a similar edit to monthlyvideo.py.

It's a shame I can't seem to make full HD videos from my images but the quality of a 720p mp4 is much better than a 1080 avi file and I suppose its good enough.

I'll close the issue for now, but I would still be interested in your thoughts, if you know of some way I could get a 1080p video, and what type of Pi you are using to compare.

Thanks

markszabo commented 3 years ago

Nice catch! Yeah, it could definitely be some hardware limitation. I'm running it on Raspberry Pi 4 Model B, and it works there. One thing you can try is to only use the raspberry to capture the images, and then run the daily video creation on your own PC, which would likely support 1080p videos.

Which version of Raspberry Pi are you using? Maybe google ffmpeg 1080p codec raspberry pi XYZ with your version? Just to see if there an ffmpeg codec that would support 1080p videos on your hardware.

dazmanic commented 3 years ago

Thanks for the tips, I'll look into seeing if I can get the video to compile on my PC, although I do really like how your script is all self contained and pretty much looks after itself. It's been working really well over the past few days, apart from a few camera hiccups. I've tried a few different codecs for compiling on the Pi, but I probably need to learn more about ffmpeg to make proper sense of it.

I'm running it on a Pi 3B+ so it only has 1 GB RAM so I think that is why it is failing for full HD. I do have a Pi 4B with 4GB, but it's busy doing Home Assistant at the moment. I could try using that at some point, but the 720p videos aren't too bad actually, so I may just stick with what's working!