quasarstream / PHP-FFmpeg-video-streaming

📼 Package media content for online streaming(DASH and HLS) using FFmpeg
https://www.quasarstream.com/op/php/ffmpeg-streaming?u=php-ff
MIT License
514 stars 117 forks source link

add WaterMark #50

Closed sh0beir closed 4 years ago

sh0beir commented 4 years ago

how can i add WaterMark ?

aminyazdanpanah commented 4 years ago

The "Watermarking Videos" is not in the scope of this project. You should use PHP FFMpeg to add a watermark to a video. (see here)

sh0beir commented 4 years ago

a problem after this lines is hls dont export all files (just one of array [$720,$1080,...]) what is problem ? may show me an example ?

aminyazdanpanah commented 4 years ago

It is not possible to add a watermark to HLS streams using this project(at this moment), but you can run an FFmpeg command line to add a watermark to the HLS files:

ffmpeg -i path/to/video.mp4 -i path/to/watermark-logo.png -filter_complex "overlay=10:10" \
-c:v libx264 -c:a aac -bf 1 -keyint_min 25 -g 250 -sc_threshold 40 -hls_list_size 0 -hls_time 10 \
-hls_allow_cache 1 -hls_segment_type mpegts -hls_segment_filename path/to/segment_%04d.ts \
-s:v 640x360 -b:v 139k -strict -2 path/to/playlist.m3u8

Alternatively, You can add a watermark to the original video and then convert the new video to HLS files:

ffmpeg -i path/to/video.mp4 -i path/to/watermark-logo.png -filter_complex "overlay=10:10" new-video.mp4

Or using PHP-FFMpeg

$ffmpeg = FFMpeg\FFMpeg::create();

$video = $ffmpeg->open('video.mpeg');

$video
    ->filters()
    ->watermark($watermarkPath, array(
        'position' => 'relative',
        'bottom' => 50,
        'right' => 50,
    ));

$video->save(new FFMpeg\Format\Video\X264(), 'new-video.mp4');

After adding the watermark, create HLS content files with your new video file(watermarked video). (How to create HLS content?)

I labeled this issue as "enhancement" to implement this feature(Watermarking HLS content) in the future.

sh0beir commented 4 years ago

thank you! now your mean is first add watermark ! and after this convert to hls

aminyazdanpanah commented 4 years ago

Yes. You can also use the command line I provided in this comment.