Fixing bug caused by disregarding number of samples actually written to a frame.