Load Video by PHP (only part)

Asked

Viewed 467 times

4

I have some files. MP4

When I want to display them, I create an html tav video and point to this mp4.

Only sometimes I’d like to broadcast only part of the video.

Ex: the video has 10min. But I want to display in the player only the 9 minute until the 10. After that the video ends.

Is there any way to do this via PHP? Upload via Stream only part of it?

  • Well, I may not be sure, but I think it should be done on HTML and not in the PHP. In the tags HTML5 there must be some where you indicate the start and end time of the video. But then I don’t know if you could "hide" the other part of the video.

  • Or if there is any other solution. Because doing this via HTML opens user’s move gap and can see whole.

  • If the user sees the other part of the video is serious problem, it would be interesting for you to add that to the question... So someone can help you with an even better solution.

1 answer

3

One suggestion is to generate a new video containing only the snippet that matters.

In the example below was used the ffmpeg:

// Tempo em segundos
$ini = 540; // início (9 minutos)
$end = 600; // fim (10 minutos)

$original_file = '/local/arquivo/video.mp4';
$new_file = '/local/arquivo/video_short.mp4';

// Local do ffmpeg
$lib_path = '/usr/bin/ffmpeg';

// Formatando o comando
$cmd = $lib_path.' -i '.$original_file.' 
-ss '.$ini.' 
-t '.$end.'
 '.$new_file;

// Executa o comando
exec($cmd);
  • Corrgi a small syntax error, I hope it doesn’t hurt. Good answer

  • In case, would I need to install this ffmpeg on the server? Have an example?

  • Yes. On the official website there are examples and documentation of how to install.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.