What are some best practices for optimizing video streaming platforms in terms of file formats and codecs?

To optimize video streaming platforms, it is important to use file formats and codecs that are efficient for streaming over the internet. This can help reduce buffering times and improve overall video quality for viewers. Some best practices include using formats like MP4 or WebM and codecs such as H.264 or VP9.

// Example code snippet for optimizing video streaming platforms with PHP
$videoFile = 'example.mp4';
$ffmpegPath = '/usr/bin/ffmpeg';
$outputFile = 'optimized_video.mp4';

// Use ffmpeg to convert the video to a more efficient format and codec
exec("$ffmpegPath -i $videoFile -c:v libx264 -c:a aac -strict -2 $outputFile");