0
0
Computer Visionml~20 mins

Video writing in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Video Writing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this OpenCV video writing code?
Consider the following Python code snippet that writes a video file using OpenCV. What will be the output after running this code?
Computer Vision
import cv2
import numpy as np

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 10.0, (640,480))

frame = np.zeros((480,640,3), dtype=np.uint8)
frame[:] = (0,255,0)  # green frame

for _ in range(5):
    out.write(frame)
out.release()

print('Video written with 5 green frames')
ARuntimeError because frame size does not match
BVideo written with 10 green frames
CSyntaxError due to incorrect fourcc code
DVideo written with 5 green frames
Attempts:
2 left
💡 Hint
Check how many times the frame is written in the loop.
Model Choice
intermediate
1:30remaining
Which codec is best for writing a high-quality MP4 video using OpenCV?
You want to save a video file in MP4 format with good compression and quality using OpenCV's VideoWriter. Which fourcc codec should you choose?
Acv2.VideoWriter_fourcc(*'DIVX')
Bcv2.VideoWriter_fourcc(*'XVID')
Ccv2.VideoWriter_fourcc(*'MP4V')
Dcv2.VideoWriter_fourcc(*'MJPG')
Attempts:
2 left
💡 Hint
MP4 format usually uses MPEG-4 codecs.
Hyperparameter
advanced
1:30remaining
What happens if the frame size parameter in VideoWriter does not match the actual frame size?
In OpenCV, when creating a VideoWriter object, you specify the frame size. What is the effect if this size does not match the size of frames you write?
AThe video file is created but frames are resized automatically
BA runtime error occurs when writing frames with mismatched size
CThe video file is created but frames are cropped to the specified size
DThe VideoWriter silently ignores the size mismatch and writes frames anyway
Attempts:
2 left
💡 Hint
OpenCV expects exact frame size match for VideoWriter.
Metrics
advanced
1:00remaining
How to calculate the total duration of a video written with OpenCV?
You wrote a video with OpenCV's VideoWriter with frame rate 20 FPS and 300 frames. What is the total duration of the video in seconds?
A15 seconds
B20 seconds
C300 seconds
D6000 seconds
Attempts:
2 left
💡 Hint
Duration = number_of_frames / frames_per_second
🔧 Debug
expert
2:30remaining
Why does this OpenCV video writing code fail to save the video file?
Examine the code below. It runs without errors but the output video file is empty (0 bytes). What is the most likely cause?
Computer Vision
import cv2
import numpy as np

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi', fourcc, 10.0, (640,480))

frame = np.zeros((480,640,3), dtype=np.uint8)
frame[:] = (255,0,0)  # blue frame

# Missing frame writing loop

out.release()
ANo frames were written to the video before releasing
BThe VideoWriter object was not released properly
CThe fourcc codec 'XVID' is not supported on this system
DThe frame size is incorrect and causes no frames to be written
Attempts:
2 left
💡 Hint
Check if any frames are actually written before release.