0

I want to convert and MP4 video into HLS multi-resolution (360, 720) and add watermark image inside the output segments.

I did two result but missing the watermark image with the multi scale:

// one hls with water mark image
ffmpeg \
-i input.mp4 \
-i watermark.png \
-filter_complex "[0:v][1:v] overlay=10:10:format=auto,format=yuv420p" \
-c:a copy -b:a 128k -c:v libx264 -crf 23 \
-f hls \
-hls_time 3 \
-hls_flags independent_segments \
-master_pl_name "output.m3u8" "output-%v.m3u8"
// multi hls with watermark text
ffmpeg \
-i ../input.mp4 \
-map 0:v:0 -map 0:a:0 -map 0:v:0 -map 0:a:0 \
-c:v:0 libx264 -crf 28 -preset faster -maxrate:v:0 600k -vf "drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white, scale=-1:360"  -b:a:0 64k \
-c:v:1 libx264 -crf 28 -preset faster -maxrate:v:0 3000k -vf "drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white, scale=-1:720" -b:a:0 64k \
-var_stream_map "v:0,a:0,name:360p v:1,a:1,name:460p" \
-f hls \
-hls_list_size 0 \
-threads 0 \
-hls_playlist_type event \
-hls_time 3 \
-hls_key_info_file ../keys/enc.keyinfo \
-hls_flags independent_segments \
-master_pl_name "output.m3u8" "output-%v.m3u8"

2 Answers 2

1

Instead of using multiple -vf directives, we may use -filter_complex:

ffmpeg -i input.mp4 -filter_complex "[0:v:0]drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white,scale=-1:360[v0];[0:v:0]drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white,scale=-1:720[v1]" -map "[v0]" -map "[v1]" -map 0:a:0 -map 0:a:0 -c:v:0 libx264 -crf 28 -preset faster -maxrate:v:0 600k -b:a:0 64k -c:v:1 libx264 -crf 28 -preset faster -maxrate:v:0 3000k -b:a:0 64k -var_stream_map "v:0,a:0,name:360p v:1,a:1,name:460p" -f hls -hls_list_size 0 -threads 0 -hls_playlist_type event -hls_time 3 -hls_flags independent_segments -master_pl_name "output.m3u8" "output-%v.m3u8"


  • [0:v:0]drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white,scale=-1:360[v0] - applies drawtext and scale filters to the fist video input stream and store the result in temporary name [v0].

  • [0:v:0]drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white,scale=-1:720[v1] - applies drawtext and scale filters to the fist video input stream and store the result in temporary name [v1].

  • -map "[v0]" -map "[v1]" - maps [v0] to the first output video stream and [v1] to the second output video stream.


When executing your original command, I am getting a warning message:

Multiple -filter, -af or -vf options specified for stream 0, only the last option '-filter:v drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white, scale=-1:720' will be used.

The warning message suggests that the first -vf is ignored.


Note: I placed the entire command in a single line due to Windows/Linux compatibility.

0

how to change directory file m3u8 and .ts ? in your code

ffmpeg -i input.mp4 -filter_complex "[0:v:0]drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white,scale=-1:360[v0];[0:v:0]drawtext=fontfile=font.ttf:text='Your Watermark Text':x=10:y=10:fontsize=24:fontcolor=white,scale=-1:720[v1]" -map "[v0]" -map "[v1]" -map 0:a:0 -map 0:a:0 -c:v:0 libx264 -crf 28 -preset faster -maxrate:v:0 600k -b:a:0 64k -c:v:1 libx264 -crf 28 -preset faster -maxrate:v:0 3000k -b:a:0 64k -var_stream_map "v:0,a:0,name:360p v:1,a:1,name:460p" -f hls -hls_list_size 0 -threads 0 -hls_playlist_type event -hls_time 3 -hls_flags independent_segments -master_pl_name "output.m3u8" "output-%v.m3u8"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .