The link that you referred to is more like object tracking. But if you want to apply moving background subtraction using opencv it would be easier. It works as more like a motion tracker.
Here's the code:
import cv2
import numpy as np
cap = cv2.VideoCapture("input.mp4")
out = cv2.createBackgroundSubtractorMOG2()
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
output = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480), isColor=False)
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,180)
outmask = out.apply(frame)
output.write(outmask)
cv2.imshow('original', frame)
cv2.imshow('Motion Tracker', outmask)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
output.release()
cap.release()
cv2.destroyAllWindows()
This code allows you to apply background subtraction in a video file and save it.