-
Notifications
You must be signed in to change notification settings - Fork 48
Description
Hello!
TL;DR: Using VideoWriter creates empty files containing only video metadata, not writing any frames.
Im currently trying to get a CudaTensor (size 1,3,210,160) which represents a frame of an Atari Game to be part of a video, using VideoWriter.
After going through the code and the issues here I have reshaped the CudaTensor into a ByteTensor of shape (210, 160, 3) and my calls to VideoWriter:write accept it. However the video file it creates is empty, bar some metadata. When I write the frame to file as an image, It works and is correct.
I don't think its something external to this package, as I tried VideoWriter on python which worked fine.
I'm not really sure what I have done wrong.
I'm using the latest luarocks cv package, with opencv 3.1.0 (locally compiled), on ubuntu 16.04.4 LTS.
Im creating the VideoWriter like so:
-- Tried MPEG, MJPG, MP4V
out_fourcc = cv.VideoWriter.fourcc { 'X', 'V', 'I', 'D' }
video = cv.VideoWriter{
"/data/out_video.avi",
out_fourcc,
16,
{210, 160}
}
Then running it:
video:open {
"/data/out_video.avi",
out_fourcc,
16,
{210, 160}
}
for estep=1,opt.eval_steps do
...
screen, reward, terminal = game_env:step(game_actions[action_index])
screen_rgb = torch_to_opencv(screen:squeeze())
video:write { screen_rgb }
end
video:release()
torch_to_opencv
being based off of a comment in #185
function torch_to_opencv(img)
local img_opencv
if img:nDimension() == 2 then
img_opencv = img
else
img_opencv = img:permute(2,3,1):contiguous()
end
-- video:write errors if byte() not appended
img_opencv:mul(255):byte()
return img_opencv
end