Make a movie with Google Earth Engine

Create awesome time-lapse movies with the GEE.

note! Danielle in the comments fixed the code using the new landsat image collections

Step 1: import the Landsat 4, 5 7 and 8 Image Collections

Step 2: draw a geometry of your area of interest.

Tip! The larger your polygon the longer it takes to process.

Step 3: Copy the bandnames as specified below into your script.

var l4names = ee.List(["B1","B2","B3","B4","B5","B6","B7","fmask"])
var l5names = ee.List(["B1","B2","B3","B4","B5","B6","B7","fmask"])
var l7names = ee.List(["B1","B2","B3","B4","B5","B6_VCID_1","B6_VCID_2","B7","B8","fmask"])
var l8names = ee.List(["B1","B2","B3","B4","B5","B6","B7","B8","B9","B10","B11","BQA"])

// bands
var l4Bands = ee.List(['blue','green','red','nir','swir1','tir','swir2','fmask'])
var l5Bands = ee.List(['blue','green','red','nir','swir1','tir','swir2','fmask'])
var l7Bands = ee.List(['blue','green','red','nir','swir1','tir1','tir2', 'swir2','pan','fmask'])
var l8Bands = ee.List(['b1','blue','green','red','nir','swir1','swir2','cir','tir1','tir2','pan','BQA'])

Step 4: Filter based on location

// Filter based on location
var l4images  = l4.filterBounds(geometry)
var l5images  = l5.filterBounds(geometry)
var l7images  = l7.filterBounds(geometry)
var l8images  = l8.filterBounds(geometry)

Step 5: Remove the clouds from the images

// set cloud threshold
var cloud_thresh = 40;

// Functions
var cloudfunction = function(image){
  //use add the cloud likelihood band to the image
  var CloudScore = ee.Algorithms.Landsat.simpleCloudScore(image);
  //isolate the cloud likelihood band
  var quality = CloudScore.select('cloud');
  //get pixels above the threshold
  var cloud01 = quality.gt(cloud_thresh);
  //create a mask from high likelihood pixels
  var cloudmask = image.mask().and(cloud01.not());
  //mask those pixels from the image
  return image.updateMask(cloudmask);
};

// mask all clouds in the image collection
l4images = l4images.map(cloudfunction);
l5images = l5images.map(cloudfunction);
l7images = l7images.map(cloudfunction);
l8images = l8images.map(cloudfunction);

Step 5: Rename the bands

l4images = l4images.select(l4names,l4Bands);
l5images = l5images.select(l5names,l5Bands);
l7images = l7images.select(l7names,l7Bands);
l8images = l8images.select(l8names,l8Bands);

Step 6: Combine all images into a single collection.

// Combine all data in single collection
var myCollection = ee.ImageCollection((l4images.merge(l5images)).merge(l7images).merge(l8images));

Step 7: Select the Red, Green and blue bands

// select rgb
var myCollection = myCollection.select(['red','green','blue'])

Step 8: Create one map for each year.

var yearlymap = ee.ImageCollection(years.map(function (y) {
      var image = myCollection.filter(ee.Filter.calendarRange(y, y, 'year'))
                              .median();
      return image.set('year', 2000)
                  .set('date', ee.Date.fromYMD(y,1,1))
                  .set('system:time_start',ee.Date.fromYMD(y,1,1));
}));

Step 9: Make it a 8 bit format.

var coll4Video = yearlymap
  .map(function(image) {
    return image.multiply(512).uint8();   // need to make it 8-bit
  });

Step 10: Export the video to your drive

Export.video.toDrive({
    collection: coll4Video,
    description: "myvideo" ,
    scale: 30,
    framesPerSecond: 2,
    region: geometry
});

see an example here.

9 comments

  1. Thank you for the tutorial. It is awesome.
    However I didnt get good results for this. The final video i got was all black and white.
    I dont know what went wrong. I checked my script many times already and it looks good to me.
    can u help

    Like

  2. Thanks for the tutorial…
    I had an amazing result…
    Do you know how can I put the date ( the year) in the video? It would help me so, so much!
    Also, the images selected to do the time frame are the result of a collection of good images without clouds or are a specific one? If they are each one a single image, is it possible to know the date of the image as well?
    thanks!!!

    Liked by 1 person

  3. Hello,
    thank you for your tutorial. If you have the time to explain step 9 (converting to 8-bit image), particularly the line: return image.multiply(512).uint8(); // need to make it 8-bit
    I would appreciate it very much. I have seen this also in Google Documentation but I cannot understand what it means, and what it actually does. I also have ImageCollection of Landsat 5, 7 and 8 Images and need to make video out of it but I am stuck at converting to 8-bit.

    Greetings,
    Popovic Tamara

    Like

  4. Thanks for lots of excellent content! I am using some of your tutorials for lectures and they are a great addition!

    GEE has performed a major change in nomenclature regarding Landsat datasets. As a result, the import functions in this script and the “fmask” band are not recognized anymore by the system. Feel free to update your code with this tested update I did: https://code.earthengine.google.com/bab6b878e5002554ab4ba25e5327135d

    Best regards
    Daniele

    Like

    1. Thank you for your update. I woul like to ask if you know how to put a time (year) stamp on each image of the video?
      Best regards,

      Julio

      Like

  5. how do I add different places. while trying the same shows : ” Geometry coordinates do not have the same geodesic state. Specify an explicit geodesic state to reproject inputs”

    Like

Leave a Reply