Video Playback: Difference between revisions
Jump to navigation
Jump to search
| (11 intermediate revisions by 2 users not shown) | |||
| Line 6: | Line 6: | ||
Note that the Lab Computer displays are typically set to 1920×1080 at 120Hz. We found that this is sufficient for most applications. There are possibilities to go higher. Later in this wiki we will explain how to build audio and video. We will start with playing video, both with and without audio. | Note that the Lab Computer displays are typically set to 1920×1080 at 120Hz. We found that this is sufficient for most applications. There are possibilities to go higher. Later in this wiki we will explain how to build audio and video. We will start with playing video, both with and without audio. | ||
=== Python === | === Python psychopy 2024.2.4=== | ||
Example demonstrating how to play a video with audio: | Example demonstrating how to play a video with audio: | ||
<syntaxhighlight lang="python" line> | <syntaxhighlight lang="python" line> | ||
| Line 21: | Line 21: | ||
win = visual.Window(size=(1024, 768), fullscr=False, color=(0, 0, 0)) | win = visual.Window(size=(1024, 768), fullscr=False, color=(0, 0, 0)) | ||
movie = visual.MovieStim( | |||
win, filename=video_file, | win, filename=video_file, | ||
autoStart= False | autoStart= False | ||
| Line 35: | Line 35: | ||
# Main loop for video playback | # Main loop for video playback | ||
while | while not movie.isFinished: | ||
# Draw the current video frame | # Draw the current video frame | ||
movie.draw() | |||
win.flip() | win.flip() | ||
| Line 43: | Line 43: | ||
if 'q' in keys: | if 'q' in keys: | ||
break | break | ||
movie.stop() # stop playback | |||
del movie | |||
gc.collect() | |||
win.close() | win.close() | ||
| Line 63: | Line 66: | ||
win = visual.Window(size=(1280, 720), fullscr=False, color=(0, 0, 0), units="pix") | win = visual.Window(size=(1280, 720), fullscr=False, color=(0, 0, 0), units="pix") | ||
movie = visual.MovieStim( | |||
win, filename=video_file, | win, filename=video_file, | ||
size=None, # Use the native video size | size=None, # Use the native video size | ||
| Line 85: | Line 88: | ||
audio.play() | audio.play() | ||
time.sleep(0.04) | time.sleep(0.04) | ||
movie.play() | |||
movie_start_time = core.getTime() | |||
while | while not movie.isFinished: | ||
# Draw the current video frame | # Draw the current video frame | ||
movie.draw() | |||
win.flip() | win.flip() | ||
| Line 97: | Line 100: | ||
audio.stop() | audio.stop() | ||
break | break | ||
movie.stop() # stop playback | |||
del movie | |||
gc.collect() | |||
# Close the PsychoPy window | # Close the PsychoPy window | ||
| Line 108: | Line 114: | ||
import json | import json | ||
file_path = " | file_path = "tick_rhythm_combined_1min.mp4" | ||
def check_video_file(file_path): | def check_video_file(file_path): | ||
| Line 244: | Line 250: | ||
subprocess.run(['ffmpeg', '-i', input_file, '-an', output_video]) | subprocess.run(['ffmpeg', '-i', input_file, '-an', output_video]) | ||
subprocess.run(['ffmpeg', '-i', input_file, '-vn', '-acodec', 'pcm_s16le', '-ar', ' | subprocess.run(['ffmpeg', '-i', input_file, '-vn', '-acodec', 'pcm_s16le', '-ar', '48000', output_audio]) | ||
print(f"Video saved to: {output_video}") | print(f"Video saved to: {output_video}") | ||
| Line 281: | Line 287: | ||
Stabilize the camera and avoid automatic exposure, white balance, or focus during recording to prevent inconsistencies. | Stabilize the camera and avoid automatic exposure, white balance, or focus during recording to prevent inconsistencies. | ||
Record in a controlled environment with consistent lighting and minimal background distractions. | Record in a controlled environment with consistent lighting and minimal background distractions. | ||
The TSG recomends to use the [[Elgato Facecam]] for high quality video recording. | |||
===Video Settings=== | ===Video Settings=== | ||
| Line 288: | Line 294: | ||
|- | |- | ||
!File format | !File format | ||
|.mp4 (H.264 codec(libx264)) | |.mp4 (H.264 [[media:Openh264-1.8.0-win64_.zip | codec(libx264)]]) | ||
|- | |- | ||
!Frame rate | !Frame rate | ||
| Line 428: | Line 434: | ||
=== Python === | === Python === | ||
Example demonstrating how to check and play your audio: | Example demonstrating how to check your os settings, audio file and play your audio: | ||
<syntaxhighlight lang="python" line> | <syntaxhighlight lang="python" line> | ||
#!/usr/bin/env python3.10 | #!/usr/bin/env python3.10 | ||
| Line 485: | Line 491: | ||
==FFmpeg== | ==FFmpeg== | ||
{{See also|FFmpeg}} | |||
===Synchronization=== | ===Synchronization=== | ||
Ensure the audio and video streams have consistent timestamps: | Ensure the audio and video streams have consistent timestamps: | ||