AdamSpannbauer / python_video_stab

A Python package to stabilize videos using OpenCV
https://adamspannbauer.github.io/python_video_stab/html/index.html
MIT License
682 stars 118 forks source link

Not saving second time around #106

Closed AlbertoMQ closed 4 years ago

AlbertoMQ commented 4 years ago
from vidstab import VidStab, layer_overlay, layer_blend
import cv2
import os

# init vid stabilizer
stabilizer = VidStab()

INPUT_FILE_PATH = ".../image_%06d.jpg"
OUT_FILE_PATH = ".../test1_%06d.jpg"
OUT_FILE_PATH_2 = ".../test2_%06d.jpg"

stabilizer.stabilize(input_path=INPUT_FILE_PATH,
                     output_path=OUT_FILE_PATH,
                     border_type='black',
                     border_size= 'auto')

#I realize I can use apply_transform here, just doing this to highlight issue.
stabilizer.stabilize(input_path=INPUT_FILE_PATH,
                     output_path=OUT_FILE_PATH_2,
                     border_type='black',
                     border_size= 'auto', use_stored_transforms=True)

plant_ordered.zip

The second time we run stabilize we get no output. I was trying to apply second transform onto another dataset, but am doing on the same just to check it's not an issue with my data.

Installed using pip, running on Ubuntu 18

AdamSpannbauer commented 4 years ago

Notes on issue

The video writer isn't being reset if the same instance is used multiple times. This should be reset either on entering / exiting stabilize process.

Contained reproducible example:

The resulting output videos are 'stable_1.avi' & 'stable_3.avi' (no output for 'stable_2.avi')

import tempfile
from vidstab import VidStab
import vidstab.download_videos as dl

TMP_DIR = tempfile.TemporaryDirectory()
VID_PATH = f'{TMP_DIR.name}/test_video.mp4'

dl.download_ostrich_video(VID_PATH)

stabilizer = VidStab()
stabilizer.stabilize(VID_PATH, 'stable_1.avi')
stabilizer.stabilize(VID_PATH, 'stable_2.avi')

# Reset writer
stabilizer.writer = None
stabilizer.stabilize(VID_PATH, 'stable_3.avi')