Video Playback: Difference between revisions

Jump to navigation Jump to search
 
(6 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))


video = visual.VlcMovieStim(
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 video.status != visual.FINISHED:
while not movie.isFinished:
     # Draw the current video frame
     # Draw the current video frame
     video.draw()
     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")


video = visual.VlcMovieStim(
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)
video.play()
movie.play()
video_start_time = core.getTime()
movie_start_time = core.getTime()


while video.status != visual.FINISHED:
while not movie.isFinished:
     # Draw the current video frame
     # Draw the current video frame
     video.draw()
     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 = "C_dyad1_video2_241123.mp4"
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', '44100', output_audio])
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.
You can use the [https://www.elgato.com/ww/en/p/facecam-mk2 facecam] for high quality video recording.
The TSG recomends to use the [[Elgato Facecam]] for high quality video recording.


===Video Settings===
===Video Settings===
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: