rm(list=ls()) library("png") library("grid") # Set the file # frisbee filename <- "./VID_20240503_045652.mp4" # Start in seconds tstart <- 2 # End tend <- 4 # Number of frames nframes <- 10 ## ---------------------------------------------------------------- ## Extract the images from the video unlink("tmp", recursive = TRUE) dir.create("tmp") # Get the number of frames val <- system(paste0("ffprobe -select_streams v -show_streams ",filename), intern=TRUE) n <- as.integer(gsub("nb_frames=", "", val[grep("nb_frames=", val)])) duration <- as.numeric(gsub("duration=", "", val[grep("duration=", val)])) # check if(tend > duration){ stop("tend=",tend," higher than duration=",duration) } # start and end in frames istart <- floor(n * tstart/duration) iend <- ceiling(n * tend/duration) iseq <- floor(seq(istart, iend, len=nframes)) # Extract the frames and keep in list L <- list() for(i in 1:length(iseq) ){ system(paste0("ffmpeg -i ",filename," -vf 'select=eq(n\\,",iseq[i],")' -vframes 1 tmp/",i,".png")) L[[i]] <- readPNG(paste0("tmp/",i,".png")) } saveRDS(L,"tmpL.RDS") ## ---------------------------------------------------------------- ## ---------------------------------------------------------------- ## Register the positions D <- matrix(0,nrow=length(iseq),ncol=2) colnames(D) <- c("x","y") ## par(mar=c(0,0,0,0), mai=c(0,0,0,0), oma=c(0,0,0,0), xaxs='i', yaxs='i') plot.new() rasterImage(L[[1]],0,0,1,1) for(i in 1:length(iseq)){ rasterImage(L[[i]],0,0,1,1) tmp <- grid.locator("npc") D[i, ] <- unlist(tmp) } graphics.off() saveRDS(D, "tmpD.RDS") ## ---------------------------------------------------------------- ## ---------------------------------------------------------------- ## Upload ## ---------------------------------------------------------------- system("scp tmpD.RDS pbac@thinlinc.compute.dtu.dk:~/www/") system("scp tmpL.RDS pbac@thinlinc.compute.dtu.dk:~/www/")