code: def main(_):
      """The main fonction use skvideo to extract frames as jpg.
  
      It can do it from a part or the totality of the video.
  
      Args:
        Nothing
      """
      print("argument to expand", ARGS.video_in)
      print("argument expanded", glob.glob(ARGS.video_in))
      video_count = 0
      for video_filename in glob.glob(ARGS.video_in):
          print("start parsing", video_filename)
          data = skvideo.io.ffprobe(video_filename)["video"]
          rate_str = six.ensure_str(data["@r_frame_rate"]).split("/")
          rate = float(rate_str[0]) / float(rate_str[1])
          print("detected frame rate:", rate)
  
          print("load frames:")
          video = skvideo.io.vreader(video_filename)
          frame_count = 0
          file_count = 0
          for frame in video:
              if (
                  (frame_count > ARGS.offset)
                  and ((frame_count - ARGS.offset) % ARGS.skip == 0)
                  and (frame_count / rate >= ARGS.from_s)
                  and (
                      frame_count / rate <= ARGS.to_s or ARGS.to_s == -1
                  )
              ):
                  print(
                      frame_count,
                  )
                  img = Image.fromarray(frame)
                  if ARGS.crop:
                      img = crop(img, ARGS.size)
                  # save file
                  file_number = (
                      file_count
                      + video_count * ARGS.multiple
                      + ARGS.start
                  )
                  if ARGS.format_ext.lower() == "jpg":
                      file_out = os.path.join(
                          ARGS.path_out,
                          "f{:07d}.jpg".format(file_number),
                      )
                      img.save(file_out, "JPEG")
                  elif ARGS.format_ext.lower() == "png":
                      file_out = os.path.join(
                          ARGS.path_out,
                          "f{:07d}.png".format(file_number),
                      )
                      img.save(file_out, "PNG")
                  else:
                      print("unrecognize format", ARGS.format_ext)
                      sys.exit()
                  file_count += 1
              frame_count += 1
          video_count += 1
  
file_path: magenta/magenta/video/tools/extract_frames.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import argparse
  import glob
  import os
  import sys
  from PIL import Image
  import six
  import skvideo.io
label_desc: Use image node_id 2 for calling a global function with example usage: main(_) without return types