PHP: How can I improve video loading time?

Hello,

I have the following problem:

I created this PHP file, and on my iPhone, the video file loads very slowly, if not at all. However, when I watch Netflix on my PC in the same browser, it loads very quickly.

I had other friends who also have iPhones test it. For one person, it charges very quickly, but for another, it doesn't, just like for me. For me, it only charges quickly when I have mobile data on.

The video files are 2-7 GB in size.

Maybe someone can find a solution for me to fix this. The important thing is that I can't reduce the size of the video files. This means the video file still has to load quickly.

I would like to thank the person who took the time and effort to help me.

When connected to the normal home network, it looks like this on the iPhone:

When I charge via LTE (mobile data):

The PHP code:

 <?php require 'db.php'; // Die Datenbankverbindung einbinden require 'is_premium.php'; // Die Datenbankverbindung einbinden // Überprüfen, ob eine ID übergeben wurde if (!isset($_GET['id']) || !is_numeric($_GET['id'])) { die('Ungültige Film-ID.'); } $movie_id = intval($_GET['id']); // Film aus der Datenbank abfragen $stmt = $db->prepare('SELECT * FROM movies WHERE id = ?'); $stmt->bind_param('i', $movie_id); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 0) { die('Film nicht gefunden.'); } $movie = $result->fetch_assoc(); $stmt->close(); $db->close(); // Erkennen, ob die URL ein lokales Video ist oder über HTTPS geladen werden soll $is_local_video = strpos($movie['video'], 'uploads/videos/') === 0; $is_https = strpos($movie['video'], ' https:// ') === 0; $thumbnail = htmlspecialchars($movie['thumbnail']); // Thumbnail aus der Datenbank ?> <!DOCTYPE html> <html lang="de"> <head> <meta charset="UTF-8">  <meta name="viewport" content="width=device-width, initial-scale=1.0">  <title><?php echo htmlspecialchars($movie['name']); ?> - MovieVel</title>  <style>   #css code  </style> </head> <body>  <div class="container">    <div class="movie-detail">      <h1><?php echo htmlspecialchars($movie['name']); ?></h1>      <!-- Movie Video -->      <div class="<?php echo $is_local_video ? 'video-container' : 'iframe-container'; ?>">        <div class="play-btn">          ▶ <!-- Play-Symbol -->        </div>        <?php if ($is_local_video): ?>          <!-- Video für progressive Web-Optimierung mit Bild-in-Bild-Unterstützung -->          <video id="video-player" controls autoplay preload="auto" poster="<?php echo $thumbnail; ?>"              onclick="this.requestPictureInPicture()" muted playsinline>            <source src="<?php echo htmlspecialchars($movie['video']); ?>" type="video/mp4">            Ihr Browser unterstützt dieses Videoformat nicht.          </video>        <?php elseif ($is_https): ?>          <iframe             src="<?php echo htmlspecialchars($movie['video']); ?>"             allowfullscreen>          </iframe>        <?php else: ?>          <p>Video konnte nicht geladen werden. Überprüfen Sie die URL oder die Serverkonfiguration.</p>        <?php endif; ?>      </div>      <!-- Movie Description -->      <div class="description-box">        <h2>Über den Film</h2>        <p><?php echo htmlspecialchars($movie['description']); ?></p>      </div>      <!-- Back Button -->      <a href="index.php" class="back-btn">Zurück zur Übersicht</a>    </div>  </div>  <script>    const video = document.getElementById('video-player');         // Überprüfen, ob Picture-in-Picture unterstützt wird    if ('pictureInPictureEnabled' in document) {      video.addEventListener('click', async () => {        try {          // Versuchen, Bild-in-Bild zu aktivieren          if (document.pictureInPictureElement !== video) {            await video.requestPictureInPicture();          } else {            // Wenn das Video schon im Bild-in-Bild-Modus ist, es wieder schließen            await document.exitPictureInPicture();          }        } catch (err) {          console.error('Fehler beim Wechseln in den Bild-in-Bild-Modus:', err);        }      });    }  </script> </body> </html>
(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
3 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
 Mirko Marek
2 months ago

Hi,

that has something to do with PHP indirectly. It depends on the charging technology and what format you use. As has already been written, video stream services such as Netflix and Co. use the technology to load blessings of the video instead of the entire video material at once. The advantage is that videos can be loaded quickly and you don’t have to wait 2 minutes, 3 minutes or longer until a video is loaded, but you often work ad-hoc.

This technique is also called Adaptive Bitrate Streaming (ABR) and Time intervals name Chunks.

Btw: This technique has been used intensively from the outset by adult providers and has contributed to the essential further development, as many adults particularly men often looked at and watch certain video material.

GamersGame
2 months ago

You won’t get much in PHP to download 2-7GB of material before you can watch it is just mentally ill xD

Rather, you should think about how to reduce or optimize the amount of data.

The greatest advantage is if you convert the video into a m3u8 with (WICHTIG) H.264 format.

At m3u8 not first the complete video is downloaded, but the video consists of very many small video segments. A video segment is for example 15 seconds. Then you only have to download the first segment, which is only 15 seconds long and therefore is very small. During these 15 seconds, the browser has time to download the next segments. This allows the video to load quickly and it runs like a normal mp4 video, so the user does not notice any difference.
If you spin at the player on minute 5 the corresponding video segment is queried, downloaded and played, then automatically download the next video segments.
This gives you fast and liquid videos. You can change the whole thing with “ffmpeg”.

Alternatively compress the mp4 video (e.g. with handbrake), then it is much smaller with the same quality, then you can use webm instead of mp4 (but not supported by all devices & browsers).