параллель

main
parent c7bc2092a6
commit ca551b6fc6

@ -63,7 +63,7 @@ def humanbitrate(s):
bitrate = "%8.1f" % (a / b) bitrate = "%8.1f" % (a / b)
return bitrate.strip() return bitrate.strip()
# крманда ffmpeg для получения постера # команда ffmpeg для получения постера
def poster(fn): def poster(fn):
""" """
The function "poster" takes a file name as input and returns a command to extract a poster image 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 Logging
using Printf using Printf
using Dates using Dates
using CRC32c
using JSON
using Base.Threads
debuglogger = ConsoleLogger(stderr, Logging.Debug) debuglogger = ConsoleLogger(stderr, Logging.Debug)
global_logger(debuglogger) global_logger(debuglogger)
@ -62,6 +65,7 @@ end
function file_info(filename) function file_info(filename)
_, ext = splitext(filename) _, ext = splitext(filename)
info = stat(filename) info = stat(filename)
crc = CRC32c.crc32c(open(filename, "r"))
m = Dict( m = Dict(
"filename" => filename, "filename" => filename,
"size" => info.size, "size" => info.size,
@ -70,21 +74,76 @@ function file_info(filename)
"ctime" => info.ctime, "ctime" => info.ctime,
"htime" => Dates.format(Dates.unix2datetime(info.ctime), "dd.mm.yyyy"), "htime" => Dates.format(Dates.unix2datetime(info.ctime), "dd.mm.yyyy"),
"ext" => ext, "ext" => ext,
"crc"=> Int(crc),
) )
return m return m
end 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) function check_file(filename)
println(filename) # println(filename)
meta = file_info(filename) info = file_info(filename)
println(meta) meta = file_meta(filename)
# println(info)
return meta
end end
# -------- основная программа -------------- 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
# Получаем результаты из потоков
for i in 1:nthreads
println("Результат из потока $i: $(fetch(results[i]))")
end
end
function main()
dir = "d:\\vids\\ero" dir = "d:\\vids\\ero"
@info "Обработка каталога: $dir" @info "Обработка каталога: $dir"
files = readdir(dir, join=true) files = readdir(dir, join=true)
n = length(files)
println("всего: $n files")
@time begin
@sync begin
for file in filter(valid_file, files) for file in filter(valid_file, files)
meta = check_file(file) @async begin
meta = @spawn check_file(file)
println(file)
end
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