1

I have a img tag in my html

<img width="600px" height ="400px" id='the_img_1' src='http://127.0.0.1:5000/video_feed'>

Img element is displaying the video from a local url.

I want to get a frame(or image in jpg form) of video from this img tag in javascript. Is this possible?

Obiii
  • 698
  • 1
  • 6
  • 26

2 Answers2

1

I hope this will help you this is exactly what you want this is not the best way but it is as per your requirement:

var imgTags = document.getElementsByTagName('img');
for(i=0; i<imgTags.length; i++){
  var iframurl = imgTags[i].getAttribute("src");
  var iframe = document.createElement('iframe');
  iframe.src = 'data:text/html;charset=utf-8,' + encodeURI(iframurl);
  document.body.appendChild(iframe);
}
<img width="600px" height ="400px" id='the_img_1' src='http://127.0.0.1:5000/video_feed'>
ADreNaLiNe-DJ
  • 4,787
  • 3
  • 26
  • 35
brijrajsinh
  • 453
  • 3
  • 11
0

Use canvas. 1. Draw img tag contents on canvas 2. get DataUri from canvas (encoded base64 string)

var img = document.getElementById("the_img_1");
var canvas = document.getElementById('myCanvas') // reference to canvas element
var ctx = canvas.getContext('2d'); // get the canvas context;
ctx.drawImage(img, 0, 0, 640,480); //draw image into canvas;
encodedImg = canvas.toDataURL("image/png");
ADreNaLiNe-DJ
  • 4,787
  • 3
  • 26
  • 35
Obiii
  • 698
  • 1
  • 6
  • 26