Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions wdx/mediainfo/luajit/mediainfo-imagesize.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- mediainfo-imagesize.lua
-- 2019.04.25
-- 2026.06.03
--
-- Get image size (width and height, pixels).
-- Fields: "Width","Height" and "Width x Height"
Expand All @@ -13,8 +13,8 @@ local mediaInfo = require("ffi-mediaInfo")

local mi = nil
local par_name = {
"Image;%Width%",
"Image;%Height%"
"Image;%Width%",
"Image;%Height%"
}
local res = {}
local filename = ""
Expand All @@ -31,9 +31,9 @@ end

function ContentGetSupportedField(FieldIndex)
if FieldIndex == 0 then
return "Width", "", 2; -- FieldName,Units,ft_numeric_64
return "Width", "", 1; -- FieldName,Units,ft_numeric_32
elseif FieldIndex == 1 then
return "Height", "", 2
return "Height", "", 1
elseif FieldIndex == 2 then
return "Width x Height", "", 8; -- FieldName,Units,ft_string
end
Expand Down Expand Up @@ -63,10 +63,12 @@ function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
mediaInfo.MediaInfoA_Close(mi)
filename = FileName
end
if FieldIndex == 2 then
return res[1] .. "x" .. res[2]
else
return res[FieldIndex + 1]
if res[1] ~= "" then
if FieldIndex == 2 then
return res[1] .. "x" .. res[2]
else
return tonumber(res[FieldIndex + 1])
end
end
return nil
end
204 changes: 110 additions & 94 deletions wdx/mediainfo/luajit/mediainfo-video.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- mediainfo-video.lua
-- 2021.08.24
-- 2026.06.03
--
-- NOTE: If you want to change the number of fields, see the lines after "-- ATTENTION!":
-- also you mast to change some indexes!
Expand All @@ -11,88 +11,88 @@ local mediaInfo = require("ffi-mediaInfo")

-- FieldName, Units, FieldType, index of par_name, additional function
local fields = {
{"General: Title", "", 8, 1, ""},
{"General: Format", "", 8, 2, ""},
{"General: Duration, ms", "", 2, 3, ""},
{"General: Duration, s", "", 1, 3, "ToSeconds"},
{"General: Duration, HH:MM:SS", "", 8, 4, "ShortTime"},
{"General: Duration, HH:MM:SS.MMM", "", 8, 4, ""},
{"General: Overall bit rate", "Bps|KBps|MBps", 3, 5, "BitRateUnits"},
{"General: Overall bit rate, auto Bps/KBps/MBps", "", 8, 5, "BitRateFloat"},
{"General: Count of streams", "", 2, 6, ""},
{"General: Number of audio streams", "", 2, 7, ""},
{"General: Number of text streams", "", 2, 8, ""},
{"General: Number of image streams", "", 2, 9, ""},
{"General: Number of menu streams", "", 2, 10, ""},
{"Video: Format", "", 8, 11, ""},
{"Video: Format profile", "", 8, 12, ""},
{"Video: Codec ID", "", 8, 13, ""},
{"Video: Streamsize in bytes", "", 2, 14, ""},
{"Video: Bit rate", "Bps|KBps|MBps", 3, 15, "BitRateUnits"},
{"Video: Bit rate, auto Bps/KBps/MBps", "", 8, 15, "BitRateFloat"},
{"Video: Width", "", 2, 16, ""},
{"Video: Height", "", 2, 17, ""},
{"Video: Display aspect ratio", "", 3, 18, "tonumber"},
{"Video: Display aspect ratio (string)", "", 8, 19, ""},
{"Video: Pixel aspect ratio", "", 3, 20, "tonumber"},
{"Video: Frame rate mode", "", 8, 21, ""},
{"Video: Frame rate", "", 3, 22, "tonumber"},
{"Video: Number of frames", "", 2, 23, ""},
{"Video: Bits/(Pixel*Frame)", "", 3, 24, "tonumber"},
{"Video: Rotation", "", 2, 25, ""},
{"Audio: Format", "", 8, 26, ""},
{"Audio: Format profile", "", 8, 27, ""},
{"Audio: Codec ID", "", 8, 28, ""},
{"Audio: Streamsize in bytes", "", 2, 29, ""},
{"Audio: Bit rate", "Bps|KBps|MBps", 3, 30, "BitRateUnits"},
{"Audio: Bit rate, auto Bps/KBps/MBps", "", 8, 30, "BitRateFloat"},
{"Audio: Bit rate mode", "", 8, 31, ""},
{"Audio: Channel(s)", "", 2, 32, ""},
{"Audio: Sampling rate, KHz", "", 8, 33, ""},
{"Audio: Bit depth", "", 2, 34, ""},
{"Audio: Delay in the stream", "", 2, 35, ""},
{"Audio: Title", "", 8, 36, ""},
{"Audio: Language", "", 8, 37, ""}
{"General: Title", "", 8, 1, ""},
{"General: Format", "", 8, 2, ""},
{"General: Duration, ms", "", 2, 3, "ToNumber"},
{"General: Duration, s", "", 1, 3, "ToSeconds"},
{"General: Duration, HH:MM:SS", "", 8, 4, "ShortTime"},
{"General: Duration, HH:MM:SS.MMM", "", 8, 4, ""},
{"General: Overall bit rate", "Bps|KBps|MBps", 3, 5, "BitRateUnits"},
{"General: Overall bit rate, auto Bps/KBps/MBps", "", 8, 5, "BitRateFloat"},
{"General: Count of streams", "", 1, 6, "ToNumber"},
{"General: Number of audio streams", "", 1, 7, "ToNumber"},
{"General: Number of text streams", "", 1, 8, "ToNumber"},
{"General: Number of image streams", "", 1, 9, "ToNumber"},
{"General: Number of menu streams", "", 1, 10, "ToNumber"},
{"Video: Format", "", 8, 11, ""},
{"Video: Format profile", "", 8, 12, ""},
{"Video: Codec ID", "", 8, 13, ""},
{"Video: Streamsize in bytes", "", 2, 14, "ToNumber"},
{"Video: Bit rate", "Bps|KBps|MBps", 3, 15, "BitRateUnits"},
{"Video: Bit rate, auto Bps/KBps/MBps", "", 8, 15, "BitRateFloat"},
{"Video: Width", "", 1, 16, "ToNumber"},
{"Video: Height", "", 1, 17, "ToNumber"},
{"Video: Display Aspect ratio", "", 3, 18, "StringToFloat"},
{"Video: DisplayAspectRatio (string)", "", 8, 19, "ToNumber"},
{"Video: Pixel Aspect ratio", "", 3, 20, "StringToFloat"},
{"Video: Frame rate mode", "", 8, 21, ""},
{"Video: Frame rate", "", 3, 22, "StringToFloat"},
{"Video: Number of frames", "", 2, 23, "ToNumber"},
{"Video: Bits/(Pixel*Frame)", "", 3, 24, "StringToFloat"},
{"Video: Rotation", "", 1, 25, "ToNumber"},
{"Audio: Format", "", 8, 26, ""},
{"Audio: Format profile", "", 8, 27, ""},
{"Audio: Codec ID", "", 8, 28, ""},
{"Audio: Streamsize in bytes", "", 2, 29, "ToNumber"},
{"Audio: Bit rate", "Bps|KBps|MBps", 3, 30, "BitRateUnits"},
{"Audio: Bit rate, auto Bps/KBps/MBps", "", 8, 30, "BitRateFloat"},
{"Audio: Bit rate mode", "", 8, 31, ""},
{"Audio: Channel(s)", "", 1, 32, "ToNumber"},
{"Audio: Sampling rate, Hz", "", 1, 33, "ToNumber"},
{"Audio: Bit depth", "", 1, 34, "ToNumber"},
{"Audio: Delay in the stream", "", 1, 35, "ToNumber"},
{"Audio: Title", "", 8, 36, ""},
{"Audio: Language", "", 8, 37, ""}
}
local mi = nil
local par_name = {
"General;%Title%",
"General;%Format%",
"General;%Duration%",
"General;%Duration/String3%",
"General;%OverallBitRate%",
"General;%StreamCount%",
"General;%AudioCount%",
"General;%TextCount%",
"General;%ImageCount%",
"General;%MenuCount%",
"Video;%Format%",
"Video;%Format_Profile%",
"Video;%CodecID%",
"Video;%StreamSize%",
"Video;%BitRate%",
"Video;%Width%",
"Video;%Height%",
"Video;%DisplayAspectRatio%",
"Video;%DisplayAspectRatio/String%",
"Video;%PixelAspectRatio%",
"Video;%FrameRate_Mode/String%",
"Video;%FrameRate%",
"Video;%FrameCount%",
"Video;%Bits-(Pixel*Frame)%",
"Video;%Rotation%",
"Audio;%Format%",
"Audio;%Format_Profile%",
"Audio;%CodecID%",
"Audio;%StreamSize%",
"Audio;%BitRate%",
"Audio;%BitRate_Mode%",
"Audio;%Channel(s)%",
"Audio;%SamplingRate/String%",
"Audio;%BitDepth%",
"Audio;%Delay%",
"Audio;%Title%",
"Audio;%Language%"
"General;%Title%",
"General;%Format%",
"General;%Duration%",
"General;%Duration/String3%",
"General;%OverallBitRate%",
"General;%StreamCount%",
"General;%AudioCount%",
"General;%TextCount%",
"General;%ImageCount%",
"General;%MenuCount%",
"Video;%Format%",
"Video;%Format_Profile%",
"Video;%CodecID%",
"Video;%StreamSize%",
"Video;%BitRate%",
"Video;%Width%",
"Video;%Height%",
"Video;%DisplayAspectRatio%",
"Video;%DisplayAspectRatio/String%",
"Video;%PixelAspectRatio%",
"Video;%FrameRate_Mode/String%",
"Video;%FrameRate%",
"Video;%FrameCount%",
"Video;%Bits-(Pixel*Frame)%",
"Video;%Rotation%",
"Audio;%Format%",
"Audio;%Format_Profile%",
"Audio;%CodecID%",
"Audio;%StreamSize%",
"Audio;%BitRate%",
"Audio;%BitRate_Mode%",
"Audio;%Channel(s)%",
"Audio;%SamplingRate%",
"Audio;%BitDepth%",
"Audio;%Delay%",
"Audio;%Title%",
"Audio;%Language%"
}
local res = {}
local filename = ""
Expand Down Expand Up @@ -137,11 +137,15 @@ function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
end
-- Close
mediaInfo.MediaInfoA_Close(mi)
-- Workaround
if res[3] ~= "" then res[3] = string.match(res[3], "^(%d+)") end
filename = FileName
end
-- Result = res[FieldIndex + 1]
if fields[FieldIndex + 1][5] == "tonumber" then
return tonumber(res[fields[FieldIndex + 1][4]])
if fields[FieldIndex + 1][5] == "ToNumber" then
return ToNumber(fields[FieldIndex + 1][4])
elseif fields[FieldIndex + 1][5] == "StringToFloat" then
return StringToFloat(fields[FieldIndex + 1][4])
elseif fields[FieldIndex + 1][5] == "ShortTime" then
return ShortTime(fields[FieldIndex + 1][4])
elseif fields[FieldIndex + 1][5] == "BitRateUnits" then
Expand All @@ -156,38 +160,50 @@ function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
return nil
end

function ToNumber(c)
if res[c] == "" then return nil end
return tonumber(res[c])
end

function StringToFloat(c)
if res[c] == "" then return nil end
local t = string.gsub(res[c], "%.", string.match(tostring(0.5), "([^05+])"))
return tonumber(t)
end

function ShortTime(c)
if res[c] == '' then return nil end
if res[c] == "" then return nil end
return string.match(res[c], "%d+:%d+:%d+")
end

function BitRateUnits(c, u)
if res[c] == '' then return nil end
if res[c] == "" then return nil end
if u == 0 then
return res[c]
return tonumber(res[c])
elseif u == 1 then
return res[c] / 1000
return tonumber(res[c]) / 1000
elseif u == 2 then
return res[c] / 1000000
return tonumber(res[c]) / 1000000
end
return nil
end

function BitRateFloat(c)
if res[c] == '' then return nil end
if ((res[c] / 1000000) < 1) then
if ((res[c] / 1000) < 1) then
if res[c] == "" then return nil end
local n = tonumber(res[c])
if (n / 1000000) < 1 then
if (n / 1000) < 1 then
return res[c] .. " Bps"
else
return string.format("%.2f", res[c] / 1000) .. " KBps"
return string.format("%.2f", n / 1000) .. " KBps"
end
else
return string.format("%.2f", res[c] / 1000000) .. " MBps"
return string.format("%.2f", n / 1000000) .. " MBps"
end
return nil
end

function ToSeconds(c)
if res[c] == '' then return nil end
return math.floor(res[c] / 1000)
if res[c] == "" then return nil end
return math.floor(tonumber(res[c]) / 1000)
end
21 changes: 12 additions & 9 deletions wdx/mediainfo/luajit/mediainfo-video.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mediainfo-video.lua
2021.08.24
2026.06.03

Get some technical information about video files. Cross-platform.

Expand Down Expand Up @@ -76,11 +76,14 @@ Audio: Language

3. History

2017.10.05 - First release.
2019.04.01 - ADD: Title, Format profile, audio support (by Dobrov)
2019.04.12 - FIX: Count of fields and parameters. DEL: Field "Video: Width x Height". CHG: Add table of fields, some checks, other.
2019.04.27 - UPD: Adding new fields is easier.
2019.04.28 - ADD: Video: Bits/(Pixel*Frame)
2019.04.30 - DEL: Field "General: MIME/Content-Type".
2021.08.24 - ADD: "General: Duration, s".
CHG: Rename "General: Duration*".
2017.10.05 First release.
2019.04.01 ADD: Title, Format profile, audio support (by Dobrov)
2019.04.12 FIX: Count of fields and parameters. DEL: Field "Video: Width x Height". CHG: Add table of fields, some checks, other.
2019.04.27 UPD: Adding new fields is easier.
2019.04.28 ADD: Video: Bits/(Pixel*Frame)
2019.04.30 DEL: Field "General: MIME/Content-Type".
2021.08.24 ADD: "General: Duration, s".
CHG: Rename "General: Duration*".
2026.06.03 ADD: Manual type conversion.
FIX: Workaround for "General: Duration" in some cases.
CHG: Cosmetic.
18 changes: 13 additions & 5 deletions wdx/mediainfo/mediainfo-imagesize-cli.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- mediainfo-imagesize.lua
-- 2019.04.25
-- 2026.06.03
--
-- Get image size (width and height, pixels).
-- Normal Lua, not LuaJIT. CLI version of MediaInfo.
Expand All @@ -9,9 +9,9 @@

-- FieldName, Units, FieldType, Context;Param
local fields = {
{"Width", "", 2, "Image;%Width%"},
{"Height", "", 2, "Image;%Height%"},
{"Width x Height", "", 8, "Image;%Width%x%Height%"}
{"Width", "", 1, "Image;%Width%"},
{"Height", "", 1, "Image;%Height%"},
{"Width x Height", "", 8, "Image;%Width%x%Height%"}
}

function ContentGetSupportedField(FieldIndex)
Expand All @@ -38,5 +38,13 @@ function ContentGetValue(FileName, FieldIndex, UnitIndex, flags)
if not h then return nil end
local res = h:read("*a")
h:close()
return string.gsub(res, "[\r\n]+", "")
local t = string.gsub(res, "[\r\n]+", "")
if t ~= "" then
if FieldIndex == 2 then
if string.len(t) > 1 then return t end
else
return tonumber(t)
end
end
return nil
end
Loading