georgmartius / vid.stab

Video stabilization library
http://public.hronopik.de/vid.stab/
Other
842 stars 108 forks source link

Grey areas at border of rotated frames / content missing #79

Open mviereck opened 4 years ago

mviereck commented 4 years ago

Coming from #78 :

Stabilizing a video can lead to grey areas at the border of the frames. I've used this video generated from a series of captures: vidstab.greyborder.source.mp4.zip

This affects many frames, I'll show the last one as an example: alignimg0060 tif

ffmpeg/vidstab commands I've used:

ffmpeg -y -hide_banner -nostdin -i "align.source.mp4" \
  -vf "vidstabdetect=shakiness=10:accuracy=15:mincontrast=0.1:stepsize=6:show=1"  \
  align.show.mp4

ffmpeg -y -hide_banner -nostdin -i "align.source.mp4" \
  -vf "vidstabtransform=optzoom=0:smoothing=0:interpol=no:relative=1:crop=black:debug=1,unsharp=5:5:0.8:3:3:0.4" \
  align.result.mp4

Extracting angle and offsets from global_motions.trf and applying them with imagemagick, I get this result: preview_0060 jpg

Comparing the two images shows:

georgmartius commented 4 years ago

Thanks for the bug report. There is surely something wrong here. I looks like it has something to do with the rotations and the different channels (color vs gray).

mviereck commented 4 years ago

I found that I can avoid the bug if I split the video into .png images and generate a new video from the .png files:

  ffmpeg -y -hide_banner -nostdin -i align.source.mp4 sourceimg%04d.png

  ffmpeg -y -hide_banner -nostdin -f image2 -start_number 1 -i sourceimg%04d.png -safe 0 -vframes 1000 -vcodec libx264 -crf 25  -pix_fmt yuv420p align.source2.mp4

Using vidstab with align.source2.mp4 instead of align.source.mp4 does not show gray areas.

mviereck commented 4 years ago

If I calculate rotation and distortion from global_motions.trf and apply the values with imagemagick, the result is slightly different from vid.stab. The alignment seems to be slightly better with imagemagick. I assume there is some imprecision in the distortion of vid.stab that also might cause the difference between image and grey area as described above.