Video Playback: Difference between revisions
Jump to navigation
Jump to search
Created page with "When using video in your experiment, especially when presenting time-critical stimuli, special care should be taken to optimize the video and audio settings on multiple levels..." |
No edit summary |
||
| Line 3: | Line 3: | ||
This page outlines some best practices; however, we advise to always consult a TSG member if you plan to run a video experiment in the labs. | This page outlines some best practices; however, we advise to always consult a TSG member if you plan to run a video experiment in the labs. | ||
== | ==Video encoding== | ||
When recording video for stimulus material or as input for your experiment, please: | When recording video for stimulus material or as input for your experiment, please: | ||
Use a high-quality camera, with settings appropriate for your application (e.g., frame rate, resolution). | Use a high-quality camera, with settings appropriate for your application (e.g., frame rate, resolution). | ||
| Line 10: | Line 10: | ||
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 facecam for high quality video recording. | You can use the facecam for high quality video recording. | ||
==Audio encoding== | |||
• Codec: Use lossless or high-quality codecs to preserve timing: | |||
o PCM (WAV): Best for accuracy, as it is uncompressed and avoids delays. | |||
o AAC (Advanced Audio Codec): Good compromise between quality and size. | |||
• Sample Rate: Use a standard sample rate (e.g., 44.1 kHz or 48 kHz) for synchronization with video. | |||
o Example: -ar 44100 for 44.1 kHz. | |||
• Channel Count: Maintain the original channel configuration (e.g., stereo or mono) for time-accurate playback. | |||
==Synchronization== | |||
• Ensure the audio and video streams have consistent timestamps: | |||
o FFmpeg Options: | |||
-fflags +genpts: Generates accurate presentation timestamps (PTS) for the video. | |||
-async 1: Synchronizes audio and video when they drift. | |||
-map 0:v:0 and -map 0:a:0: Explicitly map video and audio streams to avoid accidental mismatches. | |||
==Editing== | ==Editing== | ||
We recommend using DaVinci Resolve for editing and converting video files. DaVinci Resolve is a free, professional-grade editing program, available here: https://www.blackmagicdesign.com/products/davinciresolve | We recommend using DaVinci Resolve for editing and converting video files. DaVinci Resolve is a free, professional-grade editing program, available here: https://www.blackmagicdesign.com/products/davinciresolve | ||
==Recommended FFmpeg Command== | |||
Here’s a command that encodes video and audio while maintaining high time accuracy: | |||
ffmpeg -i input.mp4 \ | |||
-c:v libx264 -preset slow -crf 18 -vsync cfr -g 30 \ | |||
-c:a pcm_s16le -ar 44100 \ | |||
-fflags +genpts -async 1 \ | |||
output.mp4 | |||
• -c:v libx264: Encode video using H.264. | |||
• -preset slow: Optimize for quality and compression efficiency. | |||
• -crf 18: Adjusts quality (lower = better; range: 0–51). | |||
• -vsync cfr: Enforces constant frame rate. | |||
• -c:a pcm_s16le: Encodes audio in uncompressed WAV format. | |||
• -ar 44100: Sets audio sample rate to 44.1 kHz. | |||
• -fflags +genpts: Ensures accurate timestamps. | |||
• -async 1: Synchronizes audio and video streams. | |||
===Tips=== | |||
• Ensure Low Latency: If you're processing video/audio in real time, use low-latency settings (e.g., -tune zerolatency for H.264). | |||
• Avoid Resampling: If possible, use the original frame rate and sample rate to avoid timing mismatches. | |||
• Testing: Always test playback on different devices or players to confirm synchronization. | |||
Alternatively, you can use Shotcut, a simple open-source editor, available here: https://shotcut.org/ | Alternatively, you can use Shotcut, a simple open-source editor, available here: https://shotcut.org/ | ||