code: def mp4_loader(filepath, nsample, seglen, mode):
      cap = cv2.VideoCapture(filepath)
      videolen = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
      sampledFrames = []
      for i in range(videolen):
          ret, frame = cap.read()
          # maybe first frame is empty
          if ret == False:
              continue
          img = frame[:, :, ::-1]
          sampledFrames.append(img)
      average_dur = int(len(sampledFrames) / nsample)
      imgs = []
      for i in range(nsample):
          idx = 0
          if average_dur >= seglen:
              idx = (average_dur - 1) // 2
              idx += i * average_dur
          elif average_dur >= 1:
              idx += i * average_dur
          else:
              idx = i
  
          for jj in range(idx, idx + seglen):
              imgbuf = sampledFrames[int(jj % len(sampledFrames))]
              img = Image.fromarray(imgbuf, mode="RGB")
              imgs.append(img)
      return imgs
  
file_path: PaddleHub/modules/video/classification/videotag_tsn_lstm/resource/reader/kinetics_reader.py
imports: import sys
  import random
  import functools
  import logging
  import paddle
  import cv2
  import numpy
  from PIL import Image
  from .reader_utils import DataReader
label_desc: Use image node_id 4 for calling a global function with example usage: mp4_loader(filepath, nsample, seglen, mode) and returns: imgs