Skip to content
This repository has been archived by the owner on May 12, 2024. It is now read-only.

Add automation function to get frame #53

Closed
wants to merge 1 commit into from
Closed

Add automation function to get frame #53

wants to merge 1 commit into from

Conversation

seproDev
Copy link

@seproDev seproDev commented May 6, 2022

Adds new functionality to the Lua automation API that exposes a video frame.
Here is a lua code snippet showing how this currently works:

frame = aegisub.get_frame(current_frame) -- current_frame is integer
frameWithSubtitles = aegisub.get_frame(current_frame, true) -- subtitles are baked in to the video if needed

width = frame:width() -- The colon is important here as frame:width()  = frame.width(frame) 
print("Frame width: " .. width) -- Frame width: 1920
height = frame:height()
print("Frame height: " .. height) -- Frame height: 1080

pixelString = frame:getPixelFormatted(x, y)
print("Pixel String: " .. pixelString) -- Pixel String: &H0073FF&

pixelInt = frame:getPixel(x, y)
print("Pixel Raw: #" .. string.format("%x", pixelInt)) -- Pixel Raw: #ff7300

In general having people test this before merging would be great.

@Ristellise Ristellise marked this pull request as ready for review May 7, 2022 07:09
@Ristellise
Copy link
Owner

Ristellise commented May 7, 2022

It should be possible to use lua_automation_version to set the version as 4.1. This way those that want to check the function can check against the version string.

To enable future proofing, keep the feature in aegisub instead of aegisubdc.

@seproDev
Copy link
Author

seproDev commented May 7, 2022

Ah actually in the past functions have been added without increasing the version, so I guess it's fine. Aegisub/Aegisub@d660f7f
If someone needs to test for a specific feature this is better anyway:

if not aegisub.get_frame then
    return
end

@Ristellise
Copy link
Owner

Ah actually in the past functions have been added without increasing the version, so I guess it's fine. Aegisub/Aegisub@d660f7f If someone needs to test for a specific feature this is better anyway:

if (!aegisub.get_frame) then
    return
end

Guess that will work...

@seproDev
Copy link
Author

seproDev commented May 7, 2022

Okay I dropped the direct array access and added an option to retrieve frames with subtitles.
The last thing remaining is checking if any of the logic needs to be adjusted to account for flipped and pitch.
The avisynth provider sets flipped to true here:

out.flipped = true;

So potentially all avisynth videos are flipped? Would be great if someone with a working avisynth setup could try this out.

Edit: Looking at the code I think the flip is a flip along the x-axis, while the pitch is the total number of bytes in a line not pixels. I'll adjust the code to account for that, though I can't test if it actually works as I am not using avisynth.

@arch1t3cht
Copy link

For future reference: I tested this with AviSynth (and other) videos now, and all the pixel positions seem to come out correctly.

@seproDev seproDev closed this Feb 18, 2024
@seproDev seproDev deleted the get-frame branch February 18, 2024 14:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants