Log in

View Full Version : AviSynth+ Logo PNG


kira
8th November 2023, 14:32
I want to add a logo with a transparent .png extension to the upper right corner with avisynth+. Processing will be done with h264_nvenc. What path should I follow?

Emulgator
8th November 2023, 15:39
ImageSource -> Layer/Merge/Overlay

kira
8th November 2023, 16:05
ImageSource -> Layer/Merge/Overlay

DirectShowSource("C:\Users\kira\Downloads\ffmpeg-4.3.1-win64-static\ffmpeg-4.3.1-win64-static\bin\aa.mkv")

# Load the logo and resize it
logo1 = ImageReader("C:\Users\kira\Downloads\ffmpeg-4.3.1-win64-static\ffmpeg-4.3.1-win64-static\bin\logo.png").ConvertToRGB32().LanczosResize(150, 50)

# Create a mask from the alpha channel of the logo
mask = logo1.ShowAlpha()

# Extract the alpha as a grayscale image (this will represent transparency)
mask_gray = mask.ConvertToY8()

# Overlay the logo onto the video clip at the upper right corner using the mask
Overlay(last, logo1, x=Width() - Width(logo1), y=0, mask=mask_gray)

# Convert the clip to the YV12 format for the final output
ConvertToYV12()

I tried something like this, but transparent surfaces appear black. Is there an example code?

Emulgator
8th November 2023, 16:15
Upload the logo and share the link.

kira
8th November 2023, 16:25
https://imgur.com/yHkLZlA

Emulgator
8th November 2023, 16:32
Simple does it ;-)
a=ImageSource("F:\_VID\kira\yHkLZlA - Imgur.png",pixel_type="RGB32")
b=ColorBars(width=640, height=480, pixel_type="RGB32")
Layer(b,a, op="add", opacity=1.0, y=0, threshold=0, use_chroma=true)

kira
8th November 2023, 17:19
LoadPlugin("C:\Program Files (x86)\AviSynth+\plugins64+\LSMASHSource.dll")
b=DirectShowSource("C:\Users\kira\Downloads\ffmpeg-4.3.1-win64-static\ffmpeg-4.3.1-win64-static\bin\aa.mkv", pixel_type="RGB32")
a=ImageSource("C:\Users\kira\Downloads\ffmpeg-4.3.1-win64-static\ffmpeg-4.3.1-win64-static\bin\logo.png",pixel_type="RGB32")
#b=ColorBars(width=640, height=480, pixel_type="RGB32")
Layer(b,a, op="add", opacity=1.0, y=0, threshold=0, use_chroma=true)

It works like this, but how can I move the position of the logo to the upper right corner?

poisondeathray
8th November 2023, 19:03
It works like this, but how can I move the position of the logo to the upper right corner?


layer (like overlay) has x=, y= position coordinates

http://avisynth.nl/index.php/Layer

e.g. x=30 would move it 30 pixels to the right

kira
8th November 2023, 19:05
LoadPlugin("C:\Program Files (x86)\AviSynth+\plugins64+\LSMASHSource.dll")

# Load the video
video = DirectShowSource("C:\Users\kira\Downloads\ffmpeg-2023-11-02-git-4dbfb52230-full_build\ffmpeg-2023-11-02-git-4dbfb52230-full_build\bin\aa.mkv", pixel_type="RGB32")

# Load the logo image
logo = ImageSource("C:\Users\kira\Downloads\ffmpeg-2023-11-02-git-4dbfb52230-full_build\ffmpeg-2023-11-02-git-4dbfb52230-full_build\bin\logo1.png", pixel_type="RGB32")

# Set the dimensions
videoWidth = Width(video)
videoHeight = Height(video)
logoWidth = Width(logo)
logoHeight = Height(logo)

# Calculate the position for the logo in the upper right corner
positionX = videoWidth - logoWidth - 10
positionY = 30

# Overlay the logo on the video
Layer(video, logo, "add", opacity=1.0, x=positionX, y=positionY)
I did like this and working rightnow. Thanks for your help.