Believing video is not saved without explicit save
4. Identify the error in this code snippet for recording video on Raspberry Pi:
from picamera import PiCamera
import time
camera = PiCamera()
camera.start_recording('video.h264')
time.wait(3)
camera.stop_recording()
medium
A. stop_recording() should be called before start_recording()
B. Missing camera initialization
C. File name must be .mp4 not .h264
D. Incorrect method name 'time.wait' instead of 'time.sleep'
Solution
Step 1: Check the time delay function
The code uses time.wait(3), but the correct function to pause is time.sleep(3).
Step 2: Confirm other parts are correct
Camera is initialized, start and stop recording are in correct order, and .h264 is a valid format.
Final Answer:
Incorrect method name 'time.wait' instead of 'time.sleep' -> Option D
Quick Check:
Use sleep() to pause, not wait() [OK]
Hint: Use time.sleep() to pause, not time.wait() [OK]
Common Mistakes:
Using time.wait() instead of time.sleep()
Thinking .h264 is invalid file extension
Calling stop_recording() before start_recording()
5. You want to record a video on Raspberry Pi that automatically stops after 10 seconds without using time.sleep(). Which method should you use to control recording duration?
hard
A. Use camera.wait_recording(10) after start_recording()
B. Use time.sleep(10) before start_recording()
C. Call stop_recording() immediately after start_recording()
D. Use camera.record_for(10) method
Solution
Step 1: Understand wait_recording() usage
This method pauses the program while continuing recording, allowing precise control without blocking the whole program.
Step 2: Compare with other options
time.sleep(10) pauses the entire program, stop_recording() immediately stops recording, and record_for() does not exist.
Final Answer:
Use camera.wait_recording(10) after start_recording() -> Option A
Quick Check:
wait_recording() controls duration without sleep [OK]
Hint: Use wait_recording() to record timed video without sleep [OK]
Common Mistakes:
Using sleep() which blocks whole program
Calling stop_recording() too soon
Assuming record_for() method exists
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.