-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo_analyse
44 lines (39 loc) · 1.4 KB
/
video_analyse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
loadNamespace("httr")
Sys.setlocale("LC_ALL","Ukrainian")
apiUrl <- "https://westus.api.cognitive.microsoft.com/emotion/v1.0/recognizeinvideo?outputStyle=perFrame"
key <- "66fa8f09419c49478fe0fcef196b1ac2"
body_video = upload_file("D://Development (online-video-cutter.com).mp4")
faceEMO <- httr::POST(
url = apiUrl,
httr::content_type('application/octet-stream'),
httr::add_headers(.headers = c('Ocp-Apim-Subscription-Key' = key)),
body = body_video,
encode = 'json'
)
operationLocation <- httr::headers(faceEMO)[["operation-location"]]
while(TRUE){
ret <- httr::GET(operationLocation,
httr::add_headers(.headers = c('Ocp-Apim-Subscription-Key' = key)))
con <- httr::content(ret)
if(is.null(con$status)){
warning("Connection Error, retry after 1 minute")
Sys.sleep(1)
} else if (con$status == "Running" | con$status == "Uploading"){
cat(paste0("status ", con$status, "\n"))
cat(paste0("progress ", con$progress, "\n"))
Sys.sleep(1)
} else {
cat(paste0("status ", con$status, "\n"))
break()
}
}
library(tidyverse)
data <- (con$processingResult %>% jsonlite::fromJSON())$fragments
data <- data[which(sapply(data$events,is.null)==F),]
data$events <- purrr::map(data$events, function(events){
events %>% purrr::map(function(event){
jsonlite::flatten(event)
}) %>% bind_rows()
})
data <-data %>% unnest(events)
write_rds(data,"Чернявський.rds")