From ca551b6fc6bdfc698c87475d56ddf59bcbce2701 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B0=D1=82=D0=BE=D0=BB=D0=B8=D0=B9=20=D0=A2?= =?UTF-8?q?=D1=83=D1=85=D1=82=D0=B0=D1=80=D0=BE=D0=B2?= Date: Thu, 11 Jan 2024 09:18:31 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scan-vid.py | 2 +- test.jl | 77 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/scan-vid.py b/scan-vid.py index 265bcdf..99eb5cc 100644 --- a/scan-vid.py +++ b/scan-vid.py @@ -63,7 +63,7 @@ def humanbitrate(s): bitrate = "%8.1f" % (a / b) return bitrate.strip() -# крманда ffmpeg для получения постера +# команда ffmpeg для получения постера def poster(fn): """ The function "poster" takes a file name as input and returns a command to extract a poster image diff --git a/test.jl b/test.jl index 226de68..08e5882 100644 --- a/test.jl +++ b/test.jl @@ -3,6 +3,9 @@ using Logging using Printf using Dates +using CRC32c +using JSON +using Base.Threads debuglogger = ConsoleLogger(stderr, Logging.Debug) global_logger(debuglogger) @@ -62,6 +65,7 @@ end function file_info(filename) _, ext = splitext(filename) info = stat(filename) + crc = CRC32c.crc32c(open(filename, "r")) m = Dict( "filename" => filename, "size" => info.size, @@ -70,21 +74,76 @@ function file_info(filename) "ctime" => info.ctime, "htime" => Dates.format(Dates.unix2datetime(info.ctime), "dd.mm.yyyy"), "ext" => ext, + "crc"=> Int(crc), ) return m end +function file_meta(filename) + cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "$filename"` + out = read(cmd, String) + data = JSON.parse(out) + # println(data["format"]["duration"]) + return out +end + function check_file(filename) - println(filename) - meta = file_info(filename) - println(meta) + # println(filename) + info = file_info(filename) + meta = file_meta(filename) + # println(info) + return meta end -# -------- основная программа -------------- -dir = "d:\\vids\\ero" -@info "Обработка каталога: $dir" +function parallel_execution() + nthreads = Threads.nthreads() # Получаем количество доступных потоков + println("Running parallel execution: $(nthreads)") + results = Vector{Int}(undef, nthreads) # Создаем массив для хранения результатов + + # Создаем и запускаем потоки + for i in 1:nthreads + results[i] = Threads.@spawn begin + # Код, который нужно выполнить параллельно + return i * 2 + end + end -files = readdir(dir, join=true) -for file in filter(valid_file, files) - meta = check_file(file) + # Получаем результаты из потоков + for i in 1:nthreads + println("Результат из потока $i: $(fetch(results[i]))") + end end + +function main() + dir = "d:\\vids\\ero" + @info "Обработка каталога: $dir" + + files = readdir(dir, join=true) + n = length(files) + println("всего: $n files") + + @time begin + @sync begin + for file in filter(valid_file, files) + @async begin + meta = @spawn check_file(file) + println(file) + end + end + end + end + + # @sync begin + # for file in filter(valid_file, files) + # @async begin + # meta = check_file(file) + # end + # end + # end + + println("обработано") +end + +# -------- основная программа -------------- +# parallel_execution() +main()