diff --git a/wdx/mediainfo/luajit/mediainfo-imagesize.lua b/wdx/mediainfo/luajit/mediainfo-imagesize.lua index 7a5e407..cb1e8ae 100644 --- a/wdx/mediainfo/luajit/mediainfo-imagesize.lua +++ b/wdx/mediainfo/luajit/mediainfo-imagesize.lua @@ -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" @@ -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 = "" @@ -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 @@ -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 diff --git a/wdx/mediainfo/luajit/mediainfo-video.lua b/wdx/mediainfo/luajit/mediainfo-video.lua index e9027f6..fcba75d 100644 --- a/wdx/mediainfo/luajit/mediainfo-video.lua +++ b/wdx/mediainfo/luajit/mediainfo-video.lua @@ -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! @@ -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 = "" @@ -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 @@ -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 diff --git a/wdx/mediainfo/luajit/mediainfo-video.txt b/wdx/mediainfo/luajit/mediainfo-video.txt index 67990e1..73c454d 100644 --- a/wdx/mediainfo/luajit/mediainfo-video.txt +++ b/wdx/mediainfo/luajit/mediainfo-video.txt @@ -1,5 +1,5 @@ mediainfo-video.lua -2021.08.24 +2026.06.03 Get some technical information about video files. Cross-platform. @@ -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. diff --git a/wdx/mediainfo/mediainfo-imagesize-cli.lua b/wdx/mediainfo/mediainfo-imagesize-cli.lua index 2cf9452..71fac9b 100644 --- a/wdx/mediainfo/mediainfo-imagesize-cli.lua +++ b/wdx/mediainfo/mediainfo-imagesize-cli.lua @@ -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. @@ -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) @@ -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 diff --git a/wdx/mediainfo/mediainfo-video-cli.lua b/wdx/mediainfo/mediainfo-video-cli.lua index 76663d0..08d4ec8 100644 --- a/wdx/mediainfo/mediainfo-video-cli.lua +++ b/wdx/mediainfo/mediainfo-video-cli.lua @@ -1,57 +1,57 @@ -- mediainfo-video-cli.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! -- FieldName, Units, FieldType, Context;Param local fields = { - {"General: Title", "", 8, "General;%Title%"}, - {"General: Format", "", 8, "General;%Format%"}, - {"General: Duration, ms", "", 2, "General;%Duration%"}, - {"General: Duration, s", "", 1, "General;%Duration%"}, - {"General: Duration, HH:MM:SS", "", 8, "General;%Duration/String3%"}, - {"General: Duration, HH:MM:SS.MMM", "", 8, "General;%Duration/String3%"}, - {"General: Overall bit rate", "Bps|KBps|MBps", 3, "General;%OverallBitRate%"}, - {"General: Overall bit rate, auto Bps/KBps/MBps", "", 8, "General;%OverallBitRate%"}, - {"General: Count of streams", "", 2, "General;%StreamCount%"}, - {"General: Number of audio streams", "", 2, "General;%AudioCount%"}, - {"General: Number of text streams", "", 2, "General;%TextCount%"}, - {"General: Number of image streams", "", 2, "General;%ImageCount%"}, - {"General: Number of menu streams", "", 2, "General;%MenuCount%"}, - {"Video: Format", "", 8, "Video;%Format%"}, - {"Video: Format profile", "", 8, "Video;%Format_Profile%"}, - {"Video: Codec ID", "", 8, "Video;%CodecID%"}, - {"Video: Streamsize in bytes", "", 2, "Video;%StreamSize%"}, - {"Video: Bit rate", "Bps|KBps|MBps", 3, "Video;%BitRate%"}, - {"Video: Bit rate, auto Bps/KBps/MBps", "", 8, "Video;%BitRate%"}, - {"Video: Width", "", 2, "Video;%Width%"}, - {"Video: Height", "", 2, "Video;%Height%"}, - {"Video: Width x Height", "", 8, "Video;%Width%x%Height%"}, - {"Video: Display Aspect ratio", "", 3, "Video;%DisplayAspectRatio%"}, - {"Video: DisplayAspectRatio (string)", "", 8, "Video;%DisplayAspectRatio/String%"}, - {"Video: Pixel Aspect ratio", "", 3, "Video;%PixelAspectRatio%"}, - {"Video: Frame rate mode", "", 8, "Video;%FrameRate_Mode/String%"}, - {"Video: Frame rate", "", 3, "Video;%FrameRate%"}, - {"Video: Number of frames", "", 2, "Video;%FrameCount%"}, - {"Video: Bits/(Pixel*Frame)", "", 3, "Video;%Bits-(Pixel*Frame)%"}, - {"Video: Rotation", "", 2, "Video;%Rotation%"}, - {"Audio: Format", "", 8, "Audio;%Format%"}, - {"Audio: Format profile", "", 8, "Audio;%Format_Profile%"}, - {"Audio: Codec ID", "", 8, "Audio;%CodecID%"}, - {"Audio: Streamsize in bytes", "", 2, "Audio;%StreamSize%"}, - {"Audio: Bit rate", "Bps|KBps|MBps", 3, "Audio;%BitRate%"}, - {"Audio: Bit rate, auto Bps/KBps/MBps", "", 8, "Audio;%BitRate%"}, - {"Audio: Bit rate mode", "", 8, "Audio;%BitRate_Mode%"}, - {"Audio: Channel(s)", "", 2, "Audio;%Channel(s)%"}, - {"Audio: Sampling rate, KHz", "", 8, "Audio;%SamplingRate/String%"}, - {"Audio: Bit depth", "", 2, "Audio;%BitDepth%"}, - {"Audio: Delay in the stream", "", 2, "Audio;%Delay%"}, - {"Audio: Title", "", 8, "Audio;%Title%"}, - {"Audio: Language", "", 8, "Audio;%Language%"}, - {"General:", "", 8, "General;%Duration/String3%, %OverallBitRate/String%"}, - {"Video:", "", 8, "Video;%Format%, %BitRate/String%, %Width%x%Height%, %FrameRate%"}, - {"Audio:", "", 8, "Audio;%Format%, %BitRate/String%, %SamplingRate/String%, %BitDepth/String%, %Channel(s)%"} +{"General: Title", "", 8, "General;%Title%"}, +{"General: Format", "", 8, "General;%Format%"}, +{"General: Duration, ms", "", 2, "General;%Duration%"}, +{"General: Duration, s", "", 1, "General;%Duration%"}, +{"General: Duration, HH:MM:SS", "", 8, "General;%Duration/String3%"}, +{"General: Duration, HH:MM:SS.MMM", "", 8, "General;%Duration/String3%"}, +{"General: Overall bit rate", "Bps|KBps|MBps", 3, "General;%OverallBitRate%"}, +{"General: Overall bit rate, auto Bps/KBps/MBps", "", 8, "General;%OverallBitRate%"}, +{"General: Count of streams", "", 1, "General;%StreamCount%"}, +{"General: Number of audio streams", "", 1, "General;%AudioCount%"}, +{"General: Number of text streams", "", 1, "General;%TextCount%"}, +{"General: Number of image streams", "", 1, "General;%ImageCount%"}, +{"General: Number of menu streams", "", 1, "General;%MenuCount%"}, +{"Video: Format", "", 8, "Video;%Format%"}, +{"Video: Format profile", "", 8, "Video;%Format_Profile%"}, +{"Video: Codec ID", "", 8, "Video;%CodecID%"}, +{"Video: Streamsize in bytes", "", 2, "Video;%StreamSize%"}, +{"Video: Bit rate", "Bps|KBps|MBps", 3, "Video;%BitRate%"}, +{"Video: Bit rate, auto Bps/KBps/MBps", "", 8, "Video;%BitRate%"}, +{"Video: Width", "", 1, "Video;%Width%"}, +{"Video: Height", "", 1, "Video;%Height%"}, +{"Video: Width x Height", "", 8, "Video;%Width%x%Height%"}, +{"Video: Display Aspect ratio", "", 3, "Video;%DisplayAspectRatio%"}, +{"Video: DisplayAspectRatio (string)", "", 8, "Video;%DisplayAspectRatio/String%"}, +{"Video: Pixel Aspect ratio", "", 3, "Video;%PixelAspectRatio%"}, +{"Video: Frame rate mode", "", 8, "Video;%FrameRate_Mode/String%"}, +{"Video: Frame rate", "", 3, "Video;%FrameRate%"}, +{"Video: Number of frames", "", 2, "Video;%FrameCount%"}, +{"Video: Bits/(Pixel*Frame)", "", 3, "Video;%Bits-(Pixel*Frame)%"}, +{"Video: Rotation", "", 1, "Video;%Rotation%"}, +{"Audio: Format", "", 8, "Audio;%Format%"}, +{"Audio: Format profile", "", 8, "Audio;%Format_Profile%"}, +{"Audio: Codec ID", "", 8, "Audio;%CodecID%"}, +{"Audio: Streamsize in bytes", "", 2, "Audio;%StreamSize%"}, +{"Audio: Bit rate", "Bps|KBps|MBps", 3, "Audio;%BitRate%"}, +{"Audio: Bit rate, auto Bps/KBps/MBps", "", 8, "Audio;%BitRate%"}, +{"Audio: Bit rate mode", "", 8, "Audio;%BitRate_Mode%"}, +{"Audio: Channel(s)", "", 1, "Audio;%Channel(s)%"}, +{"Audio: Sampling rate, Hz", "", 1, "Audio;%SamplingRate%"}, +{"Audio: Bit depth", "", 1, "Audio;%BitDepth%"}, +{"Audio: Delay in the stream", "", 1, "Audio;%Delay%"}, +{"Audio: Title", "", 8, "Audio;%Title%"}, +{"Audio: Language", "", 8, "Audio;%Language%"}, +{"General:", "", 8, "General;%Duration/String3%, %OverallBitRate/String%"}, +{"Video:", "", 8, "Video;%Format%, %BitRate/String%, %Width%x%Height%, %FrameRate%"}, +{"Audio:", "", 8, "Audio;%Format%, %BitRate/String%, %SamplingRate/String%, %BitDepth/String%, %Channel(s)%"} } function ContentGetSupportedField(FieldIndex) @@ -81,40 +81,43 @@ function ContentGetValue(FileName, FieldIndex, UnitIndex, flags) local res = h:read("*a") h:close() res = string.gsub(res, "[\r\n]+", "") - if FieldIndex == 3 then - return math.floor(res / 1000) + if res == "" then return nil end + if (FieldIndex == 2) or (FieldIndex == 3) then + t = string.match(res, "^(%d+)") + if FieldIndex == 3 then + return math.floor(tonumber(t) / 1000) + else + return tonumber(t) + end elseif FieldIndex == 4 then return string.match(res, "%d+:%d+:%d+") elseif (FieldIndex == 6) or (FieldIndex == 17) then - if res == '' then - return nil - else - if UnitIndex == 0 then - return res - elseif UnitIndex == 1 then - return res / 1000 - elseif UnitIndex == 2 then - return res / 1000000 - end + if UnitIndex == 0 then + return tonumber(res) + elseif UnitIndex == 1 then + return tonumber(res) / 1000 + elseif UnitIndex == 2 then + return tonumber(res) / 1000000 end elseif (FieldIndex == 7) or (FieldIndex == 18) then - if res == '' then - return nil - else - if ((res / 1000000) < 1) then - if ((res / 1000) < 1) then - return res .. " Bps" - else - return string.format("%.2f", res / 1000) .. " KBps" - end + local n = tonumber(res) + if (n / 1000000) < 1 then + if (n / 1000) < 1 then + return res .. " Bps" else - return string.format("%.2f", res / 1000000) .. " MBps" + return string.format("%.2f", n / 1000) .. " KBps" end + else + return string.format("%.2f", n / 1000000) .. " MBps" end elseif (FieldIndex == 22) or (FieldIndex == 24) or (FieldIndex == 26) or (FieldIndex == 28) then - return string.gsub(res, "%.", string.match(tostring(0.5), "([^05+])")) + t = string.gsub(res, "%.", string.match(tostring(0.5), "([^05+])")) + return tonumber(t) else - return res + if fields[FieldIndex + 1][3] < 4 then + return tonumber(res) + else + return res + end end - return nil end diff --git a/wdx/mediainfo/mediainfo-video-cli.txt b/wdx/mediainfo/mediainfo-video-cli.txt index f323d4c..643b4f0 100644 --- a/wdx/mediainfo/mediainfo-video-cli.txt +++ b/wdx/mediainfo/mediainfo-video-cli.txt @@ -1,5 +1,5 @@ mediainfo-video-cli.lua --- 2021.08.24 +-- 2026.06.03 Get some technical information about video files. diff --git a/wdx/mediainfo/mediainfo-video-cli2.lua b/wdx/mediainfo/mediainfo-video-cli2.lua index 7ea37a7..368c281 100644 --- a/wdx/mediainfo/mediainfo-video-cli2.lua +++ b/wdx/mediainfo/mediainfo-video-cli2.lua @@ -1,92 +1,92 @@ -- mediainfo-video-cli2.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! --- FieldName, Units, FieldType, Context, Param +-- 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, "StringToFloat"}, - {"Video: DisplayAspectRatio (string)", "", 8, 19, ""}, - {"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, ""}, - {"Video: Bits/(Pixel*Frame)", "", 3, 24, "StringToFloat"}, - {"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 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 g, v, a = "General;", "Video;", "Audio;" local res = {} @@ -128,10 +128,14 @@ function ContentGetValue(FileName, FieldIndex, UnitIndex, flags) local c = AddToTable(t, 1) c = AddToTable(GetInfo(FileName, v), c) AddToTable(GetInfo(FileName, a), c) + -- 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] == "StringToFloat" then + 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]) @@ -159,7 +163,7 @@ function AddToTable(s, i) local n1, t local n2 = 1 while true do - n1 = string.find(s, '|', n2, true) + n1 = string.find(s, "|", n2, true) if n1 == nil then break end res[i] = string.sub(s, n2, n1 - 1) n2 = n1 + 1 @@ -168,43 +172,50 @@ function AddToTable(s, i) return i 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 - return string.gsub(res[c], "%.", string.match(tostring(0.5), "([^05+])")) + 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 diff --git a/wdx/mediainfo/mediainfo-video-cli2.txt b/wdx/mediainfo/mediainfo-video-cli2.txt index 041722f..3f879ac 100644 --- a/wdx/mediainfo/mediainfo-video-cli2.txt +++ b/wdx/mediainfo/mediainfo-video-cli2.txt @@ -1,9 +1,9 @@ mediainfo-video-cli2.lua -2021.08.24 +2026.06.03 Get some technical information about video files. -Uses CLI-version of MediaInfo (as mediainfo-video.lua), but: +Uses CLI-version of MediaInfo (as mediainfo-video-cli.lua), but: - In some cases this version will be more faster (if you want to use 3 or more fields); - In some cases this version will be more slower (if you want to use searching with plugin and 1 or 2 fields); - Fields "Video: Width x Height", "General:", "Video:" and "Audio:" have been removed, because they are not needed in this version.