如何从视频中提取帧并将其保存到内存中?

时间:2022-09-11 21:23:28

I tried extract frame and save it as output.jpg On server side:

我尝试提取帧并将其保存为output.jpg在服务器端:

f = "ffmpeg -vframes 1 -y -ss "+time+" -i ./media/somemov.mp4 ./media/output.jpg"
subprocess.call(f, shell=True)

And on client side used:

在客户端使用:

getImage(noOfFrame);  //send the request for call the ffmpeg function from views.py

document.getElementById("main").style.backgroundImage="url(http://localhost:8000/media/output.jpg#"+ new Date().getTime();+")";

But its too slow. DIV displays always the old image becose creates image takes a long time. for example i want image no 3 and DIV has no 2, i want image no 4, and div has no 3.

但它太慢了。 DIV始终显示旧图像,因为创建图像需要很长时间。例如,我想要图像没有3而DIV没有2,我希望图像没有4,而div没有3。

Is there any way how to extract frame from video (by ffmpeg) and send it into Python without creation the output.jpg file?

有没有办法如何从视频中提取帧(通过ffmpeg)并将其发送到Python而不创建output.jpg文件?

I want get the image data and send it from server (django) to webpage and set it as background-image of any DIV.

我想获取图像数据并将其从服务器(django)发送到网页,并将其设置为任何DIV的背景图像。

Is the "pure data sending" solution better then mine?

“纯数据发送”解决方案比我的更好吗?

Thanks for help.

感谢帮助。

1 个解决方案

#1


1  

short answer: no.

简短的回答:没有。

There is a better way to do this though.

有一种更好的方法来做到这一点。

  1. video is flagged for thumbnail/screengrab creation with a certain timestamp
  2. 视频被标记为具有特定时间戳的缩略图/ screengrab创建

  3. django deletes old thumbnail if it exists
  4. django删除旧缩略图(如果存在)

  5. django queues an event using http://pypi.python.org/pypi/django-celery (the event is the actual thumnail creation event)
  6. django使用http://pypi.python.org/pypi/django-celery对事件进行排队(该事件是实际的thumnail创建事件)

  7. while the event is in the queue, the user is shown a placeholder image b/c the thumbnail doesn't exist
  8. 当事件在队列中时,向用户显示占位符图像b / c缩略图不存在

  9. javascript/ajax on the DIV polling the event queue for the thumbnail to be finished.
  10. DIV上的javascript / ajax轮询事件队列以完成缩略图。

  11. the event finished, the javascript fetches the newly created thumbnail in realtime and changes the CSS property of the DIV
  12. 事件结束后,javascript实时获取新创建的缩略图并更改DIV的CSS属性

#1


1  

short answer: no.

简短的回答:没有。

There is a better way to do this though.

有一种更好的方法来做到这一点。

  1. video is flagged for thumbnail/screengrab creation with a certain timestamp
  2. 视频被标记为具有特定时间戳的缩略图/ screengrab创建

  3. django deletes old thumbnail if it exists
  4. django删除旧缩略图(如果存在)

  5. django queues an event using http://pypi.python.org/pypi/django-celery (the event is the actual thumnail creation event)
  6. django使用http://pypi.python.org/pypi/django-celery对事件进行排队(该事件是实际的thumnail创建事件)

  7. while the event is in the queue, the user is shown a placeholder image b/c the thumbnail doesn't exist
  8. 当事件在队列中时,向用户显示占位符图像b / c缩略图不存在

  9. javascript/ajax on the DIV polling the event queue for the thumbnail to be finished.
  10. DIV上的javascript / ajax轮询事件队列以完成缩略图。

  11. the event finished, the javascript fetches the newly created thumbnail in realtime and changes the CSS property of the DIV
  12. 事件结束后,javascript实时获取新创建的缩略图并更改DIV的CSS属性