I am using the av::av_encode_video()
function to produce a .mp4 video from png files, as in this answer. I pay special attention for the png files to be perfectly crisp, i.e. I plot matrices to png with exactly the same dimensions, so that every matrix cell maps to one cell in the png. Here is code to illustrate what I mean:
library(av)
n.times <- 24*10
n.row <- 50
n.col <- 26
out.dir <- "/Users/Abdirizak/Documents/some/directory/"
for (i in 1:n.times) {
current.mat <- matrix(data = rnorm(n.row*n.col), nrow = n.row, ncol = n.col)
setwd(out.dir)
png(filename = paste0(i, ".png"), width = n.row, height = n.col)
par(mar = rep(0,4))
image(current.mat)
dev.off()
}
setwd(out.dir)
png.files <- paste0(out.dir, list.files(pattern = ".png$"))
av::av_encode_video(input = png.files, output = "000.mp4", framerate = 24)
Now, even though my input .png files are perfectly crisp, the output .mp4 video is blurry. How can I prevent that from happening? I.e. how can I get a perfectly crisp video? (I am aware that this will likely inflate the file size of the .mp4 file)
I already digged a bit into the vfilter
argument of av_encode_video()
and the underlying ffmpeg filter graphs on here, but could not yet really get the hang on it.
I am looking at the .mp4 file through QuickTime Player on MacOS Ventura 13.0.1, and using R version 4.2.2 through RStudio 2022.12.0.353
Edit 9.1.2023:
To further clarify, here is an example screenshot of a png image (not the original png file because that one appears too small here):
As I said, a perfectly crisp image.
On the other hand, a screenshot of the .mp4 movie looks like this:
Somewhat unsatisfactory. Any suggestions are welcome.