First time here? Check out the FAQ!
your codes are correct. the only reason is you did not put the dll file of opencv_ffmpeg240.dll in your project.