Are there any best practices for extracting and storing video duration using PHP?

When extracting and storing video duration using PHP, a best practice is to use a library like FFmpeg for accurate duration retrieval. You can use FFmpeg to extract the duration of a video file and then store it in a database for future reference.

// Path to the video file
$videoPath = 'path/to/video.mp4';

// Use FFmpeg to get the duration of the video
$duration = shell_exec("ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $videoPath");

// Store the duration in a database or use it as needed
// For example, if using MySQL:
$mysqli = new mysqli("localhost", "username", "password", "database");
$mysqli->query("INSERT INTO videos (duration) VALUES ('$duration')");