php – How to set featured image from external url img

I’m generating a thumb of a video and its going to the public_html folder with this

  $thumbfile = .$key.".png";
  $videothumb = "/var/www/bamboostock/wp-content/uploads/2021/04/".$file_name;
  $command = "/usr/bin/ffmpeg -i " . $videothumb . " -f mjpeg -t 1 -r 1 -y ".$thumbfile;
  system($command);

Now I need this image to set as Featured, but nothing is working