如何在动画期间保留标签、指南针和标题的同时将光线着色器贴图转换为 mp4 视频?
How can I convert a rayshader map into a mp4 video while keeping the labels, compass and title during the animation?
多亏了这个精彩 tutorial 我创建了 3D 地图的 gif 以可视化惠灵顿市中心海平面上升 12 米的范围!
地图截图:
现在我想知道是否可以在使用 "render_movie" 功能创建的视频中保留标签、比例尺和指南针?我一直在寻找许多教程,但到目前为止没有成功!有人可以帮我解决这个问题吗?
#GENERATE MP4:
n_frames <- 1080
waterdepths <- transition_values(from = 0, to = 12.3, steps = n_frames)
# video transition variables
theta <- transition_values(from = -45, to = 180, steps = n_frames, one_way = TRUE, type = "lin")
phi <- transition_values(from = 40, to = 10, steps = n_frames, one_way = TRUE, type = "cos")
zoom <- transition_values(from = 0.8, to = 0.3, steps = n_frames, one_way = TRUE, type = "cos")
library(av)
zscale <- 2
elev_matrix %>%
sphere_shade(sunangle = 270, texture = "imhof1", zscale = zscale) %>%
add_water(detect_water(elev_matrix), color = "imhof4") %>%
add_shadow(ambient_shade(elev_matrix, zscale = zscale), 0.5) %>%
add_shadow(ray_shade(elev_matrix, zscale = zscale, lambert = TRUE), 0.5) %>%
add_overlay(overlay_img, alphalayer = 0.8) %>%
plot_3d(elev_matrix, solid = TRUE, shadow = TRUE, zscale = zscale,
water = TRUE, watercolor = "imhof3", wateralpha = 0.8,
waterlinecolor = "#ffffff", waterlinealpha = 0.5,
waterdepth = waterdepths/zscale, windowsize = c(1500, 1250))
render_label(elev_matrix, x = 700, y = 650, z = 1500,
zscale = 4, text = "Wellington", linecolor="black", freetype=FALSE)
render_label(elev_matrix, x = 1405, y = 1190, z = 800,
zscale = 4, text = "Mount Victoria", textcolor = "black", linecolor="darkred",dashed = TRUE, freetype=FALSE)
render_scalebar(limits=c(0, 5, 10),label_unit = "km",position = "W", y=50,
scale_length = c(0.33,1))
render_compass(position = "E")
render_movie(
filename = "wellington.mp4", type = "custom",
frames = 1080,
phi = phi,
theta = theta,
zoom = zoom
)
不幸的是,我只能用代码的最后一部分在惠灵顿周围拍到漂亮的风景(但没有标签,也没有海平面上升……):(
问题已解决(确保 ffmpeg 路径设置正确):
代码:
#generate mp4
n_frames <- 1080
waterdepths <- transition_values(from = 0.5, to = 12.3, steps = n_frames)
#video transition variables
theta <- transition_values(from = -15, to = 180, steps = n_frames, one_way = FALSE, type = "lin")
phi <- transition_values(from = 40, to = 15, steps = n_frames, one_way = FALSE, type = "cos")
zoom <- transition_values(from = 0.8, to = 0.3, steps = n_frames, one_way = FALSE, type = "cos")
library(av)
zscale <- 2
elev_matrix %>%
sphere_shade(sunangle = 270, texture = "imhof1", zscale = zscale) %>%
add_shadow(ambient_shade(elev_matrix, zscale = zscale), 0.5) %>%
add_shadow(ray_shade(elev_matrix, zscale = zscale, lambert = TRUE), 0.5) %>%
add_overlay(overlay_img, alphalayer = 0.8) %>%
plot_3d(elev_matrix, solid = TRUE, shadow = TRUE, zscale = zscale,
windowsize = c(1200, 1000))
render_label(elev_matrix, x = 700, y = 650, z = 1500,
zscale = 2, text = "Wellington", linecolor="black", freetype=FALSE)
render_label(elev_matrix, x = 1405, y = 1190, z = 800,
zscale = 2, text = "Mount Victoria", textcolor = "black", linecolor="darkred",dashed = TRUE, freetype=FALSE)
for(i in 1:1080) {
render_water(elev_matrix, watercolor = "lightblue", wateralpha = 0.8,
waterlinecolor = "#ffffff", waterlinealpha = 0.5,
waterdepth = waterdepths[i]/zscale)
render_camera(theta=theta[i], phi=phi[i], zoom=zoom[i])
render_snapshot(filename = sprintf("welli%i.png", i),
title_text = "Wellington, New Zealand | Imagery: ESRI_Imagery | DSM: 1m, source: Open Topography",
title_bar_color = "#1f5214", title_color = "white", title_bar_alpha = 1)
}
rgl::rgl.close()
av::av_encode_video(sprintf("welli%d.png",seq(1,1080,by=1)), framerate = 30,
output = "wellington.mp4")
多亏了这个精彩 tutorial 我创建了 3D 地图的 gif 以可视化惠灵顿市中心海平面上升 12 米的范围!
地图截图:
现在我想知道是否可以在使用 "render_movie" 功能创建的视频中保留标签、比例尺和指南针?我一直在寻找许多教程,但到目前为止没有成功!有人可以帮我解决这个问题吗?
#GENERATE MP4:
n_frames <- 1080
waterdepths <- transition_values(from = 0, to = 12.3, steps = n_frames)
# video transition variables
theta <- transition_values(from = -45, to = 180, steps = n_frames, one_way = TRUE, type = "lin")
phi <- transition_values(from = 40, to = 10, steps = n_frames, one_way = TRUE, type = "cos")
zoom <- transition_values(from = 0.8, to = 0.3, steps = n_frames, one_way = TRUE, type = "cos")
library(av)
zscale <- 2
elev_matrix %>%
sphere_shade(sunangle = 270, texture = "imhof1", zscale = zscale) %>%
add_water(detect_water(elev_matrix), color = "imhof4") %>%
add_shadow(ambient_shade(elev_matrix, zscale = zscale), 0.5) %>%
add_shadow(ray_shade(elev_matrix, zscale = zscale, lambert = TRUE), 0.5) %>%
add_overlay(overlay_img, alphalayer = 0.8) %>%
plot_3d(elev_matrix, solid = TRUE, shadow = TRUE, zscale = zscale,
water = TRUE, watercolor = "imhof3", wateralpha = 0.8,
waterlinecolor = "#ffffff", waterlinealpha = 0.5,
waterdepth = waterdepths/zscale, windowsize = c(1500, 1250))
render_label(elev_matrix, x = 700, y = 650, z = 1500,
zscale = 4, text = "Wellington", linecolor="black", freetype=FALSE)
render_label(elev_matrix, x = 1405, y = 1190, z = 800,
zscale = 4, text = "Mount Victoria", textcolor = "black", linecolor="darkred",dashed = TRUE, freetype=FALSE)
render_scalebar(limits=c(0, 5, 10),label_unit = "km",position = "W", y=50,
scale_length = c(0.33,1))
render_compass(position = "E")
render_movie(
filename = "wellington.mp4", type = "custom",
frames = 1080,
phi = phi,
theta = theta,
zoom = zoom
)
不幸的是,我只能用代码的最后一部分在惠灵顿周围拍到漂亮的风景(但没有标签,也没有海平面上升……):(
问题已解决(确保 ffmpeg 路径设置正确):
代码:
#generate mp4
n_frames <- 1080
waterdepths <- transition_values(from = 0.5, to = 12.3, steps = n_frames)
#video transition variables
theta <- transition_values(from = -15, to = 180, steps = n_frames, one_way = FALSE, type = "lin")
phi <- transition_values(from = 40, to = 15, steps = n_frames, one_way = FALSE, type = "cos")
zoom <- transition_values(from = 0.8, to = 0.3, steps = n_frames, one_way = FALSE, type = "cos")
library(av)
zscale <- 2
elev_matrix %>%
sphere_shade(sunangle = 270, texture = "imhof1", zscale = zscale) %>%
add_shadow(ambient_shade(elev_matrix, zscale = zscale), 0.5) %>%
add_shadow(ray_shade(elev_matrix, zscale = zscale, lambert = TRUE), 0.5) %>%
add_overlay(overlay_img, alphalayer = 0.8) %>%
plot_3d(elev_matrix, solid = TRUE, shadow = TRUE, zscale = zscale,
windowsize = c(1200, 1000))
render_label(elev_matrix, x = 700, y = 650, z = 1500,
zscale = 2, text = "Wellington", linecolor="black", freetype=FALSE)
render_label(elev_matrix, x = 1405, y = 1190, z = 800,
zscale = 2, text = "Mount Victoria", textcolor = "black", linecolor="darkred",dashed = TRUE, freetype=FALSE)
for(i in 1:1080) {
render_water(elev_matrix, watercolor = "lightblue", wateralpha = 0.8,
waterlinecolor = "#ffffff", waterlinealpha = 0.5,
waterdepth = waterdepths[i]/zscale)
render_camera(theta=theta[i], phi=phi[i], zoom=zoom[i])
render_snapshot(filename = sprintf("welli%i.png", i),
title_text = "Wellington, New Zealand | Imagery: ESRI_Imagery | DSM: 1m, source: Open Topography",
title_bar_color = "#1f5214", title_color = "white", title_bar_alpha = 1)
}
rgl::rgl.close()
av::av_encode_video(sprintf("welli%d.png",seq(1,1080,by=1)), framerate = 30,
output = "wellington.mp4")