параллель

main
parent c7bc2092a6
commit ca551b6fc6

@ -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

@ -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) # Создаем массив для хранения результатов
files = readdir(dir, join=true)
for file in filter(valid_file, files)
meta = check_file(file)
# Создаем и запускаем потоки
for i in 1:nthreads
results[i] = Threads.@spawn begin
# Код, который нужно выполнить параллельно
return i * 2
end
end
# Получаем результаты из потоков
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()

Loading…
Cancel
Save