diff --git a/WRF.md b/WRF.md index 3c81498c98e4458935092deef267ad8bab422ffa..8544fdde4d9185d3fa30e698311190dfd8cfec2b 100644 --- a/WRF.md +++ b/WRF.md @@ -681,5 +681,58 @@ For 3D visualization of WRF output, it is recommended to use either [Paraview](h Not tested yet. +##### Creating a video + +Whether done with Paraview or with Mayavi, the visualization will result in a collection of png files, e.g., `InnValley.%04d.png`. There are several tools to convert invidual frames into movies. Among them, `ffmpeg` and `apngasm`. + +The basic method to create an `mp4` movie is: +```sh +ffmpeg -i InnValley.%04d.png -c:v libx264 -r 12 -pix_fmt yuv420p InnValley.mp4 +``` + +The method above might return an error if frames have an odd number of pixels in one dimension: +```sh +[libx264 @ 0x5651e5f02980] height not divisible by 2 (1066x1083) +``` + +The fix is as follows: +```sh +ffmpeg -i InnValley.%04d.png -c:v libx264 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -r 12 -pix_fmt yuv420p InnValley.mp4 +``` + +It is possible to add movie repetitions (similar to a loop). In this case, 3 additional loops are appended after the first one: +```sh +ffmpeg -stream_loop 3 -framerate 12 -i InnValley.%04d.png -c:v libx264 -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" -pix_fmt yuv420p InnValley.mp4 +``` + +It also possible to generate movies in other formats, better suited for the web: + +* webp (most efficient compression for loops): + ```sh + ffmpeg -framerate 12 -i InnValley.%04d.png InnValley.webp + ``` + +* animated png (bigger in size): + ```sh + apngasm InnValley.png InnValley.0*png + ``` + +* gif (much bigger in size): + ```sh + ffmpeg -framerate 12 -i InnValley.%04d.png InnValley.gif + ``` + +* To get a feeling of the file sizes: + ```sh + (mypy39) stefano@stefano-XPS-13-9370:~/Desktop/Paraview_animation/anim$ du -hcs InnValley.0*png + 59M total + + (mypy39) stefano@stefano-XPS-13-9370:~/Desktop/Paraview_animation/anim$ du -hcs InnValley.[pgmw]* + 70M InnValley.gif + 14M InnValley.mp4 + 51M InnValley.png + 4,5M InnValley.webp + ``` + ## Useful tools