Creating timelapse with ffmpeg creates artifacts in image

1

I've been trying to create (night-)timelapses with my GoPro and putting the images together afterwards with ffmpeg, but I can't see to find a good setting. All of my tries end up with some sort of artifacts.

The ffmpeg-command:

ffmpeg -r 100 -pattern_type glob -i '*.JPG' -vcodec libx264 -crf 18 -pix_fmt yuv420p -preset veryfast  timelapse18.mp4

I've also tried slow, and different -crf. High number (lower quality) creates less artifacts, but also worse image.

Se image below for example: enter image description here

EDIT: Full logg

$ ffmpeg -r 100 -pattern_type glob -i '*.JPG' -vcodec libx264 -crf 18 -pix_fmt yuv420p -preset veryfast  timelapse18.mp4
ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.8)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin -fno-stack-check' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, image2, from '*.JPG':
  Duration: 00:04:32.20, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 4000x3000, 25 fps, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[swscaler @ 0x1104c3000] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x7f8f62002a00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0x7f8f62002a00] profile High, level 6.1
[libx264 @ 0x7f8f62002a00] 264 - core 155 r2917 0a84d98 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=1 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=2 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=6 lookahead_threads=2 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=1 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=10 rc=crf mbtree=1 crf=18.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'timelapse18.mp4':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 4000x3000, q=-1--1, 100 fps, 12800 tbn, 100 tbc
    Metadata:
      encoder         : Lavc58.54.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame= 6808 fps=6.2 q=-1.0 Lsize= 1018519kB time=00:01:08.05 bitrate=122611.3kbits/s dup=3 drop=0 speed=0.0616x
video:1018436kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.008126%
[libx264 @ 0x7f8f62002a00] frame I:29    Avg QP:19.68  size:529355
[libx264 @ 0x7f8f62002a00] frame P:2320  Avg QP:22.51  size:196487
[libx264 @ 0x7f8f62002a00] frame B:4459  Avg QP:23.38  size:128207
[libx264 @ 0x7f8f62002a00] consecutive B-frames: 12.5%  0.4%  0.6% 86.5%
[libx264 @ 0x7f8f62002a00] mb I  I16..4: 32.3% 56.5% 11.1%
[libx264 @ 0x7f8f62002a00] mb P  I16..4: 31.0% 37.4%  0.1%  P16..4: 10.2%  2.4%  1.9%  0.0%  0.0%    skip:17.1%
[libx264 @ 0x7f8f62002a00] mb B  I16..4: 14.3% 22.3%  0.0%  B16..8: 12.1%  2.6%  0.1%  direct:14.6%  skip:34.1%  L0:43.4% L1:49.7% BI: 6.9%
[libx264 @ 0x7f8f62002a00] 8x8 transform intra:57.8% inter:34.6%
[libx264 @ 0x7f8f62002a00] coded y,uvDC,uvAC intra: 38.0% 9.4% 0.0% inter: 14.4% 13.5% 0.0%
[libx264 @ 0x7f8f62002a00] i16 v,h,dc,p: 35% 21% 39%  6%
[libx264 @ 0x7f8f62002a00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 13% 13% 52%  4%  4%  4%  4%  3%  3%
[libx264 @ 0x7f8f62002a00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 12% 16%  7% 15% 11% 10%  6%  8%
[libx264 @ 0x7f8f62002a00] i8c dc,h,v,p: 76% 12% 12%  0%
[libx264 @ 0x7f8f62002a00] Weighted P-Frames: Y:18.3% UV:4.1%
[libx264 @ 0x7f8f62002a00] kb/s:122547.38

Kyrremann

Posted 2019-11-04T19:04:52.837

Reputation: 113

Show the full log from your command. – llogan – 2019-11-04T19:06:50.223

@llogan added. If it's because of my laptop (MacBook Pro), I can try it on my desktop instead. – Kyrremann – 2019-11-04T19:25:24.400

Answers

1

Simplify the command, to eliminate the artifacts, and only after that try reintroducing some options.

Omit -crf, -pix_fmt, and -preset.

Use a more common rate, like -r 30.


Or, if you're desperate, use a different encoder:
cat *.JPG | ffmpeg -f image2pipe -framerate 30 -c:v mjpeg -i - out.mov

Camille Goudeseune

Posted 2019-11-04T19:04:52.837

Reputation: 1 361

I'm trying your tips with removing the options, and then reintroduce one and one. I'll try lower rate afterwards. – Kyrremann – 2019-11-04T20:03:10.693

1Or try a higher rate. 120 is much more common than 100! – Camille Goudeseune – 2019-11-04T20:11:13.337

I think the errors lies in my settings on the GoPro, as I see that there are in fact some images that should have been dark, that are bright (which I think messes up the converting). – Kyrremann – 2019-11-04T21:31:26.770

2Use a very low CRF or a low constant QP. If there are sudden changes in frame composition, that likely generates a large residual and the existing rate factor doesn't have a bit budget large enough to preserve detail. – Gyan – 2019-11-05T04:53:17.230

2-pix_fmt is not relevant here. – Gyan – 2019-11-05T04:53:44.787

@Gyan -pix_fmt is likely irrelevant, but first remove artifacts by any means, only thereafter reintroduce subtleties. – Camille Goudeseune – 2019-11-05T05:54:42.343

2I appreciate your advice on iterative problem-solving but one should avoid trials which may introduce new complications. What the screenshot shows is coarse quantization in some regions and is a classic symptom of aggressive ratecontrol. That's due to the encoder. -pix_fmt is a scaler operation which occurs pre-encoder and operates independently on one image at a time and involves no quantization step. Also, leaving it out would preserve the source pixel format (4:2:2) which is incompatible with most (all?) web players and many desktop player apps as well. – Gyan – 2019-11-05T06:18:32.130

3A lower -rmay help since the bitrate is now distributed over fewer frames but since the OP hints at unexpected luminance changes, the pheonmenon can still persist. The best candidate is to disable auto-exposure on the camera but for an existing source file, lax compression is the first remedy. – Gyan – 2019-11-05T06:18:35.397

I agree with Gyan here. The suggestions for pixel format and CRF would not help in this specific case. Reducing the framerate makes sense; choosing a slower preset will improve encoding speed here but not much else. – slhck – 2019-11-05T16:15:18.743