Bird
0
0
Raspberry Piprogramming~20 mins

Recording video in Raspberry Pi - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Raspberry Pi Video Master
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 Raspberry Pi camera recording code?

Consider this Python code snippet using the picamera library to record a video for 5 seconds. What will be the output?

Raspberry Pi
import time
from picamera import PiCamera

camera = PiCamera()
camera.start_recording('test_video.h264')
time.sleep(5)
camera.stop_recording()
print('Recording complete')
ANo output
BSyntaxError
CRuntimeError: Camera not found
DRecording complete
Attempts:
2 left
💡 Hint

Think about what the print statement does after recording stops.

🧠 Conceptual
intermediate
1:30remaining
Which parameter controls the video resolution in PiCamera?

In the picamera library, which parameter sets the resolution of the recorded video?

Acamera.resolution
Bcamera.framerate
Ccamera.brightness
Dcamera.contrast
Attempts:
2 left
💡 Hint

Resolution means width and height of the video.

🔧 Debug
advanced
2:00remaining
Why does this Raspberry Pi video recording code raise an error?

Look at this code snippet. It raises an error when run. What is the cause?

Raspberry Pi
from picamera import PiCamera
import time

camera = PiCamera()
camera.start_recording('video.h264')
camera.wait_recording(5)
camera.stop_recording()
print('Done')
Atime module is not imported
Bstart_recording requires a file object, not a filename string
Cwait_recording is not a method of PiCamera
Dstop_recording must be called before wait_recording
Attempts:
2 left
💡 Hint

Check the official PiCamera documentation for method names.

📝 Syntax
advanced
2:00remaining
Which option correctly sets up a 10-second video recording with PiCamera?

Choose the code snippet that correctly records a 10-second video using PiCamera.

A
import time
from picamera import PiCamera
camera = PiCamera()
camera.record('vid.h264', 10)
camera.stop_recording()
B
import time
from picamera import PiCamera
camera = PiCamera()
camera.start_recording('vid.h264')
time.sleep(10)
camera.stop_recording()
C
from picamera import PiCamera
camera = PiCamera()
camera.start_recording('vid.h264')
camera.wait(10)
camera.stop_recording()
D
import time
from picamera import PiCamera
camera = PiCamera()
camera.start_recording('vid.h264')
time.wait(10)
camera.stop_recording()
Attempts:
2 left
💡 Hint

Remember to use time.sleep() to pause the program.

🚀 Application
expert
3:00remaining
How to save a video in MP4 format using Raspberry Pi camera?

You want to record a video and save it directly as an MP4 file using the Raspberry Pi camera. Which approach is correct?

ARecord video as H264 and then use <code>ffmpeg</code> to convert it to MP4 after recording
BUse <code>camera.start_recording('video.mp4')</code> and PiCamera saves MP4 automatically
CSet <code>camera.format = 'mp4'</code> before recording to save directly as MP4
DPiCamera cannot record video; use USB webcam instead
Attempts:
2 left
💡 Hint

Think about the default video format PiCamera records and how to convert it.