2

Good afternoon, I use FFMPEG to merge and transfer videos from a remote (mount folder) to a local folder. If the video is very large, the whole network stream gets clogged and the system goes down for a while. This is unacceptable for me. Is there any way to limit the speed of reading from the remote drive?

My command

/usr/bin/ffmpeg -safe 0 -protocol_whitelist pipe,file -y -f concat -i - -c copy /tmp/record3115801675360365846.mp4
WBLord
  • 874
  • 6
  • 29
  • Depending on codec used, you can try to [limit thread count](https://superuser.com/questions/155305/how-many-threads-does-ffmpeg-use-by-default), but that won't give you much control over read speed. For that you can try to start ffpmeg process and read file yourself - while feeding InputStream into child ffmpeg process in controlled manner. Relevant [javadocs](https://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.Redirect.html#PIPE) – rkosegi Jan 10 '22 at 08:27
  • @rkosegi I thought about doing it this way, but I don't have the knowledge to build it. Can you make an example? – WBLord Jan 10 '22 at 08:52
  • try [this](https://stackoverflow.com/questions/18903549/writing-to-inputstream-of-a-java-process) as a starting point. Note that you will need dedicated thread that will pump data into ffmpeg process. Guava's [RateLimiter](https://guava.dev/releases/19.0/api/docs/index.html?com/google/common/util/concurrent/RateLimiter.html) can help you achieve fine-grain rate limiting – rkosegi Jan 10 '22 at 09:20

1 Answers1

0

FFmpeg has an option readrate for this.

ffmpeg -readrate 5.0 -i INPUT ...

This will ingest 5 seconds of media data in one second.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • This option is only available in the latest (not yet stable) version and does not allow for flexible bandwidth settings such as 10KB/sec. – WBLord Jan 14 '22 at 07:47
  • git master builds are as stable as the releases, usually more. The unit is media duration because ffmpeg deals with packetized media data not a raw bytesteam. – Gyan Jan 14 '22 at 08:29