code: def downsample_scenes(
      main_data, resolution, codec, crf, keyint, quiet
  ):
      desc = [resolution, "scenes"]
      if not codec:
          codec = default_codec
      else:
          desc += [codec]
      assert codec in [
          "h264",
          "hevc",
      ], "--codec must be one of h264 or hevc"
  
      if not crf:
          crf = default_crf
      else:
          desc += ["crf" + crf]
  
      if not keyint:
          keyint = default_keyint
      else:
          desc += ["keyint" + keyint]
  
      main_out_path = os.path.join(main_data, *desc)
  
      print("Writing output files to:", main_out_path)
  
      for subset in ["train", "val"]:
          if not os.path.isdir(os.path.join(main_out_path, subset)):
              os.makedirs(os.path.join(main_out_path, subset))
  
      res_args = []
      if resolution == "4K":
          pass
      else:
          if resolution == "1080p":
              res_str = "1920:1080"
          elif resolution == "720p":
              res_str = "1280:720"
          elif resolution == "540p":
              res_str = "960:540"
          else:
              raise ValueError("Unknown resolution")
          res_args = [
              "-vf",
              "scale=%s" % res_str,
              "-sws_flags",
              "bilinear",
          ]
  
      codec_args = ["-preset", "slow"]
      if codec == "h264":
          codec_args = [
              "-c:v",
              "libx264",
              "-g",
              keyint,
              "-profile:v",
              "high",
          ]
      elif codec == "hevc" or codec == "h265":
          codec_args = [
              "-c:v",
              "libx265",
              "-x265-params",
              "keyint=%s:no-open-gop=1" % (keyint),
          ]
      else:
          raise ValueError("Unknown codec")
  
      if quiet:
          cmdout = subprocess.DEVNULL
      else:
          cmdout = None
  
      def transcode(in_path, out_path):
          cmd = ["ffmpeg", "-y", "-i", in_path]
          cmd += res_args
          cmd += codec_args
          cmd += ["-crf", crf, "-an", out_path]
          print("Running:", " ".join(cmd))
          subprocess.run(cmd, stdout=cmdout, stderr=cmdout)
  
      for subset in ["train", "val"]:
          for in_file in os.listdir(
              os.path.join(main_data, "orig", "scenes", subset)
          ):
              if in_file.endswith(".mp4"):
                  in_path = os.path.join(
                      main_data, "orig", "scenes", subset, in_file
                  )
                  out_path = os.path.join(
                      main_out_path, subset, in_file
                  )
                  transcode(in_path, out_path)
  
label_desc: Use image node_id 1 for calling a global function with example usage: downsample_scenes(main_data, resolution, codec, crf, keyint, quiet) without return types