L
L
Lexx Xell2021-09-17 15:06:36
Django
Lexx Xell, 2021-09-17 15:06:36

How to send the output of ffmpeg to memory instead of a file and then store the result in a Django FileField?

In the project I'm currently working on, I need to manipulate the uploaded files using FFMPEG.

There are 4 FileField fields in the model (in reality it is different, but this example can also be explained):

file1 = models.FileField(...)
file2= models.FileField(...)
file3 = models.FileField(...)
out_file = models.FileField(...)

When a model object is created, the first 3 files are loaded, and when it is saved, a selery task is called, in which a bash script is called where, using ffmpeg, these three files are glued into one.
In the current version, the result is saved as a file in /tmp/, and then loaded into the model, deleting from /tmp/

It seems to me that this is irrational due to the load on the HDD / SSD, and if you send the ffmpeg output to memory, it will work faster.

Final question
Does it make sense to redirect ffmpeg output into memory and then store it in the model's FileField?
If yes, how to do it?

Ps
Separately, I know how to load BytesIO from memory into FileField, and I can imagine how to send ffmpeg output to memory. But I can't put it all together.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2021-09-17
@LexxXell

if you have tmp on ssd, then everything is fine, there is no point in bothering.
If you want to experiment, make a ramdrive:
from root

# mkdir /mnt/ramdisk
# mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk
# cd /ramdisk
# df -h .
Filesystem      Size  Used Avail Use% Mounted on
tmpfs           512M     0  512M   0% /ramdisk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question