News for hackers. Stuff that matters.
Re:Non-Rectangular Video Cropping with FFMpeg by BubRoss on Sunday December 29, 2019 @09:50AM (#21906126)
I don't know what you mean by predictive instrumentation or why you are running out of memory, but don't forget the original interprocess communication, the file system.
Re:Non-Rectangular Video Cropping with FFMpeg by ArtWomb on Sunday December 29, 2019 @10:43AM (#21906436)
Thanks for the replies the8472 and BubRoss!

I just mean I'd like to "cap" ffmpeg's memory usage to ensure it never crashes.

I'll provide a simple example. Creating an image slideshow from a directory of huge images. I can downscale and compress to jpeg before processing. But even then, besides batching, it always fails. And this is just raw, without any filters or image processing. Have tried all the i/o techniques from the wiki:

https://trac.ffmpeg.org/wiki/Slideshow

All this local laptop based (4GB). I just want to get a better handle before devoting cloud resources (ffmpeg is standard on gcloud serverless) ;)

Re:Non-Rectangular Video Cropping with FFMpeg by shakna on Sunday December 29, 2019 @11:04AM (#21906544)
I think there's something vital missing from this story.

I regularly use a laptop with 4GB RAM to generate videos using the sequential method listed there, with 4-8k sized frames, producing video files of hundreds of GB, without a crash. There can be hundreds of thousands of them as well.

No batching required.

The final command in my pipeline is a simple:

    ffmpeg \
    -threads "$threads" \
    -y \
    -start_number 0 \
    -i 'build_frames'"$unique"'/%09d.png' \
    -c:v libvpx-vp9 \
    -lossless 1 \
    -qscale:v 2 \
    -r "$fps" \
    build_tmp"$unique"/media.webm
But, if you really need to limit ffmpeg's memory consumption, you probably need to look at -max_alloc and -bits_per_raw_sample. It'll be highly specific to your own hardware.
Re:Non-Rectangular Video Cropping with FFMpeg by izacus on Sunday December 29, 2019 @02:22PM (#21907854)
There's also a word of warning here - the fps filter (which gets auto-inserted with -r) has a tendency to buffer the duplicated frames between two input frames.

This can cause large memory spikes if your input has low fps (or is generated from JPEGs with large time difference), since frames between two input frames will be generated and then sent to the output in a single operation, spiking memory usage.

Re:Non-Rectangular Video Cropping with FFMpeg by _Gyan_ on Monday December 30, 2019 @01:22AM (#21911239)
the fps filter (which gets auto-inserted with -r)

Which ffmpeg version are you using? This hasn't been the case since 2012. Both input and output -r are effected through fftools and not libs.

Re:Non-Rectangular Video Cropping with FFMpeg by ArtWomb on Sunday December 29, 2019 @01:29PM (#21907489)
Thnks for the replies all ;)

Switching to vp9 (from x264) worked for me!

Re:Non-Rectangular Video Cropping with FFMpeg by AstralStorm on Sunday December 29, 2019 @11:01AM (#21906526)
Sounds like there's a lack of feature in the CLI tool. You will have to write your own, pick a language and it probably has enough of low level ffmpeg bindings to do this. The library supports streaming reads and writes very well, though you may have to provide a custom reader callback or use the old loop APIs.
Re:Non-Rectangular Video Cropping with FFMpeg by BubRoss on Sunday December 29, 2019 @02:37PM (#21907942)
ffmpeg from the command line is very powerful and people use it for what is being described here all the time. Why do you think it is necessary to have to resort to the library and API?
Re:Non-Rectangular Video Cropping with FFMpeg by BubRoss on Sunday December 29, 2019 @11:37AM (#21906762)
I'm not sure why you would need to use a server when you have your laptop, ffmpeg should be able to chew through this stuff faster than you could upload it.

Something is likely very off with how you are using ffmpeg. If you force more keyframes, use good quality settings etc. it should make short work of it.

Re:Non-Rectangular Video Cropping with FFMpeg by kohanz on Sunday December 29, 2019 @11:04AM (#21906543)
You should be able to, for example, divide the slideshow into smaller segments, create those and then use the concatenate ability to join them back together. Maybe that's what you were already referring to by 'batching'? It's a completely valid approach.