0

I am using a python script to take images and create a time-lapse using the PiCamera module on a Pi Zero W.

The image capture part of the script works fine but the time-lapse conversion always fails.

I'm using this command (and have tried a few variations):

os.system('avconv -y -r 24 -i ' + dir + '/image%05d.jpg -vcodec libx264 ' + dir + '/timelapse.mp4')

The .mp4 file is created but the avconv makes it through about 40 frames before hanging and ultimately killing itself and the .mp4 is 0KB.

Here is a typical output when the script is run in Terminal:

ffmpeg version 3.2.10-1~deb9u1+rpt1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.3.0 (Raspbian 6.3.0-18+rpi1) 20170516
  configuration: --prefix=/usr --extra-version='1~deb9u1+rpt1' --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-rpi --enable-mmal --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 '/home/pi/pi-timelapse/series-2018-04-17/image%05d.jpg':
  Duration: 00:00:02.40, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 1920x1080, 25 fps, 25 tbr, 25 tbn, 25 tbc
No pixel format specified, yuvj420p for H.264 encoding chosen.
Use -pix_fmt yuv420p for compatibility with outdated media players.
[libx264 @ 0x202e970] using cpu capabilities: none!
[libx264 @ 0x202e970] profile High, level 4.0
[libx264 @ 0x202e970] 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=-2 threads=1 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 '/home/pi/pi-timelapse/series-2018-04-17/timelapse.mp4':
  Metadata:
    encoder         : Lavf57.56.101
    Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuvj420p(pc), 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 (mjpeg (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.1 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=    6 fps=2.2 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=    7 fps=2.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=    8 fps=1.9 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=    9 fps=1.9 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   10 fps=1.9 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   12 fps=1.9 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   14 fps=2.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   16 fps=2.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   18 fps=2.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   20 fps=2.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   22 fps=2.0 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   23 fps=1.8 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   24 fps=1.7 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   25 fps=1.7 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   26 fps=1.7 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   27 fps=1.7 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   29 fps=1.6 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   31 fps=1.7 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   33 fps=1.7 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   35 fps=1.7 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   37 fps=1.7 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   38 fps=1.4 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   39 fps=1.3 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   40 fps=1.3 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   frame=   41 fps=1.1 q=0.0 size=       0kB time=00:00:00.00 bitrate=N/A speed=   Killed

I'm new to Raspberry Pi and not much of a coder so any help would be greatly appreciated.

  • @Fabian I'm not sure what else to say. I posted the attempted command and the failure results and asked for assistance. How precise do I need to be? – rvajayh Apr 18 '18 at 1:09
  • do all the images (image?????.jpg) exist or are you trying to do the same thing this person – Jaromanda X Apr 18 '18 at 2:08
  • Yes, all images from image00000.jpg to image00059.jpg exist in the target directory. – rvajayh Apr 18 '18 at 2:15
  • Try the command directly without Python. Are there any spaces in the directory name for example? – John Hawthorne Apr 18 '18 at 17:19
  • @JohnHawthorne same result in Terminal. After additional research, it seems that 'libx264' is a memory hog and that's what is killing the process. I changed to mpeg codec and it now works fine. Since I'm a noob, I don't know how to change the memory available to a process and since mpeg seems to work, I'll not worry about it for now. – rvajayh Apr 18 '18 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.