-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
88 lines (58 loc) · 2.04 KB
/
index.Rmd
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
title: "Avian Spectrograph Video Creator"
output: html_notebook
---
Original: https://marce10.github.io/2016/12/12/Create_dynamic_spectro_in_R.html
```{r}
require("warbleR")
```
```{r}
mainDir <- "./"
subDir <- "source"
ifelse(!dir.exists(file.path(mainDir, subDir)), dir.create(file.path(mainDir, subDir)), FALSE)
download.file(url = "http://marceloarayasalas.weebly.com/uploads/2/5/5/2/25524573/0.sur.2014.7.3.8.31.wav",
destfile = "source/example.wav")
wav1 <- readWave("source/example.wav", from = 0, to = 19, units = "seconds")
```
```{r}
tlimsize <- 1.5
# frames per second
fps <- 60
#margin
marg <- tlimsize / 2
#add silence
wav <-pastew(wave2 = silence(duration = marg, samp.rate = wav1@samp.rate,
xunit = "time"), wave1 = wav1, f = wav@samp.rate,
output = "Wave")
wav <-pastew(wave1 = silence(duration = marg, samp.rate = wav@samp.rate,
xunit = "time"), wave2 = wav, f = wav@samp.rate,
output = "Wave")
```
```{r}
mainDir <- "./"
subDir <- "img"
ifelse(!dir.exists(file.path(mainDir, subDir)), dir.create(file.path(mainDir, subDir)), FALSE)
#start graphic device to create image files
png("img/fee%04d.png", res = 240, width = 3840, height = 2160)
x <- 0
#loop to create image files
repeat {
tlim <- c(x, x + tlimsize)
spectro(wave = wav, f = wav@samp.rate, wl = 300, ovlp = 90,
flim = c(2, 10.5), tlim = tlim, scale = F, grid = F,
palette = gray.colors, norm = F, dBref = 2*10e-5,
osc = T, colgrid="white", colwave="chocolate2",
colaxis="white", collab="white", colbg="black")
abline(v = tlim[1]+marg, lty = 2, col = "skyblue", lwd = 2)
x <- x + 1/fps
# stop when the end is reached
if (x >= (length(wav@left)/wav@samp.rate) - tlimsize) break
}
dev.off()
```
```{r}
mainDir <- "./"
subDir <- "video"
ifelse(!dir.exists(file.path(mainDir, subDir)), dir.create(file.path(mainDir, subDir)), FALSE)
system("ffmpeg -framerate 60 -i img/fee%04d.png -c:v libx264 -profile:v high -crf 2 -pix_fmt yuv420p video/spectro_movie.mp4")
```