Challenge - 5 Problems
Video Writing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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')
Attempts:
2 left
💡 Hint
Check how many times the frame is written in the loop.
✗ Incorrect
The loop runs 5 times, writing 5 identical green frames to the video file. The fourcc code and frame size are correct, so no errors occur.
❓ Model Choice
intermediate1: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?
Attempts:
2 left
💡 Hint
MP4 format usually uses MPEG-4 codecs.
✗ Incorrect
The 'MP4V' codec is commonly used for MP4 files and provides good compression and quality. 'XVID' and 'DIVX' are for AVI containers, and 'MJPG' is motion JPEG.
❓ Hyperparameter
advanced1: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?
Attempts:
2 left
💡 Hint
OpenCV expects exact frame size match for VideoWriter.
✗ Incorrect
OpenCV raises a runtime error if the frame size does not match the size specified when creating the VideoWriter. It does not resize or crop frames automatically.
❓ Metrics
advanced1: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?
Attempts:
2 left
💡 Hint
Duration = number_of_frames / frames_per_second
✗ Incorrect
Duration = 300 frames / 20 FPS = 15 seconds.
🔧 Debug
expert2: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()
Attempts:
2 left
💡 Hint
Check if any frames are actually written before release.
✗ Incorrect
The code creates a VideoWriter and a frame but never calls out.write(frame), so no frames are saved. The file is created but empty.