Rotate by 90° extension | bug setting config to null?
Posted: 13 Feb 2024 16:40
Hi everyone!
First time poster: I have developed 2 extensions to rotate the video by 90° clockwise or counter-clockwise in 2 clicks (View > Rotate..) instead of 5 (Ctrl+E > Video Effects > Geometry > Transform > Rotate by..)
While testing I discovered that the script needs to stop and play a running video in order for the transformation to take effect. Also pauses are needed else setting changes are ignored.
There is still 1 bug and some hiccups:
The bug: starting from a standard video, rotating to 90° > 180°> 270° works but from 270° back to an un-rotated video doesn't work. (Of course exact same counter-clockwise: 270° > 180° > 90° works, but 90° > 0° doesn't). Switching to "horizontal flip" as a workaround, instead of un-rotated video, works but it is not an acceptable workaround.
Hence my thread title: I suspect a bug when setting a config field to null. In my scripts:
The hiccups: sometime the player is in a state where the transformations do not appear to work anymore. Closing and re-launching VLC shows the correct rotating state immediately (?) then rotating works again. Some other times VLC seems to be in an unrotatable state where you have to manually use Ctrl+E > Video Effects > Geometry > Transform > Rotate by.. to unlock...
Here are my scripts:
Rotate+90°.lua
Rotate-90°.lua
Any idea for fixing this?
Thanks!
Nicolas
First time poster: I have developed 2 extensions to rotate the video by 90° clockwise or counter-clockwise in 2 clicks (View > Rotate..) instead of 5 (Ctrl+E > Video Effects > Geometry > Transform > Rotate by..)
While testing I discovered that the script needs to stop and play a running video in order for the transformation to take effect. Also pauses are needed else setting changes are ignored.
There is still 1 bug and some hiccups:
The bug: starting from a standard video, rotating to 90° > 180°> 270° works but from 270° back to an un-rotated video doesn't work. (Of course exact same counter-clockwise: 270° > 180° > 90° works, but 90° > 0° doesn't). Switching to "horizontal flip" as a workaround, instead of un-rotated video, works but it is not an acceptable workaround.
Hence my thread title: I suspect a bug when setting a config field to null. In my scripts:
Code: Select all
vlc.config.set("video-filter", "") -- doesn't seem to work?
The hiccups: sometime the player is in a state where the transformations do not appear to work anymore. Closing and re-launching VLC shows the correct rotating state immediately (?) then rotating works again. Some other times VLC seems to be in an unrotatable state where you have to manually use Ctrl+E > Video Effects > Geometry > Transform > Rotate by.. to unlock...
Here are my scripts:
Rotate+90°.lua
Code: Select all
-- Rotate+90° 0.0.1 - VLC Extension --
-- Rotate a video clockwise by 90° --
function sleep (a)
local sec = tonumber(os.clock() + a)
while (os.clock() < sec) do
end
end
function descriptor()
return {
title = "Rotate +90°",
version = "0.0.1",
author = "mougino",
url = "http://mougino.free.fr",
shortdesc = "Rotate video by 90° clockwise",
description = "Rotate+90°.lua = rotate a video by 90° clockwise, "..
"Rotate-90°.lua = rotate a video by 90° counter-clockwise.",
capabilities = {"input-listener"}
}
end
function activate()
local rotated = vlc.config.get("video-filter") -- "transform", nil
local angle = vlc.config.get("transform-type") -- 90, 180, 270, hflip...
-- vlc.msg.info("[Rotate+90°.lua] BEFORE video-filter = " .. tostring(rotated) )
-- vlc.msg.info("[Rotate+90°.lua] BEFORE transform-type = " .. tostring(angle) )
-- Save current time and stop the video
local video = vlc.object.input()
local stamp = nil
if video ~= nil then
stamp = vlc.var.get(video, "time")
vlc.playlist.stop()
sleep(0.5)
end
-- Do the rotation
if rotated ~= "transform" or angle == "hflip" then
vlc.config.set("transform-type", "90")
vlc.config.set("video-filter", "transform")
elseif tostring(angle) == "270" then
vlc.config.set("transform-type", "hflip") -- works but unacceptable workaround
vlc.config.set("video-filter", "") -- doesn't seem to work?
else
vlc.config.set("transform-type", tostring((90+angle) % 360))
vlc.config.set("video-filter", "transform")
end
-- vlc.msg.info("[Rotate+90°.lua] AFTER video-filter = " .. tostring(vlc.config.get("video-filter")) )
-- vlc.msg.info("[Rotate+90°.lua] AFTER transform-type = " .. tostring(vlc.config.get("transform-type")) )
-- Set previous time back and resume the video
if video ~= nil then
sleep(0.5)
vlc.playlist.play()
sleep(0.2)
vlc.var.set(vlc.object.input(), "time", stamp)
end
vlc.deactivate()
end
function deactivate()
end
Rotate-90°.lua
Code: Select all
-- Rotate-90° 0.0.1 - VLC Extension --
-- Rotate a video counter-clockwise by 90° --
function sleep (a)
local sec = tonumber(os.clock() + a)
while (os.clock() < sec) do
end
end
function descriptor()
return {
title = "Rotate -90°",
version = "0.0.1",
author = "mougino",
url = "http://mougino.free.fr",
shortdesc = "Rotate video by 90° counter-clockwise",
description = "Rotate-90°.lua = rotate a video by 90° counter-clockwise, "..
"Rotate+90°.lua = rotate a video by 90° clockwise.",
capabilities = {"input-listener"}
}
end
function activate()
local rotated = vlc.config.get("video-filter") -- "transform", nil
local angle = vlc.config.get("transform-type") -- 90, 180, 270, hflip...
-- vlc.msg.info("[Rotate-90°.lua] BEFORE video-filter = " .. tostring(rotated) )
-- vlc.msg.info("[Rotate-90°.lua] BEFORE transform-type = " .. tostring(angle) )
-- Save current time and stop the video
local video = vlc.object.input()
local stamp = nil
if video ~= nil then
stamp = vlc.var.get(video, "time")
vlc.playlist.stop()
sleep(0.5)
end
-- Do the rotation
if rotated ~= "transform" or angle == "hflip" then
vlc.config.set("transform-type", "270")
vlc.config.set("video-filter", "transform")
elseif tostring(angle) == "90" then
vlc.config.set("transform-type", "hflip") -- works but unacceptable workaround
vlc.config.set("video-filter", "") -- doesn't seem to work?
else
vlc.config.set("transform-type", tostring((270+angle) % 360))
vlc.config.set("video-filter", "transform")
end
-- vlc.msg.info("[Rotate-90°.lua] AFTER video-filter = " .. tostring(vlc.config.get("video-filter")) )
-- vlc.msg.info("[Rotate-90°.lua] AFTER transform-type = " .. tostring(vlc.config.get("transform-type")) )
-- Set previous time back and resume the video
if video ~= nil then
sleep(0.5)
vlc.playlist.play()
sleep(0.2)
vlc.var.set(vlc.object.input(), "time", stamp)
end
vlc.deactivate()
end
function deactivate()
end
Any idea for fixing this?
Thanks!
Nicolas