Instead of using GDAL directly, look into using gippy to process raster data because it can better handle memory management for processing large images and chaining of image processing tasks.