[FFmpeg-user] Combining download of ts stream with geometry modification into mp4?

Bo Berglund bo.berglund at gmail.com
Mon Apr 19 14:46:42 EEST 2021


On Sun, 18 Apr 2021 23:41:59 -0700, Carl Zwanzig <cpz at tuunq.com> wrote:

>On 4/18/2021 11:20 PM, Bo Berglund wrote:
>> Can I combine these two operations into a single ffmpeg command such that there
>> is no intermediate ts file created and the mp4 is available essentially when the
>> download completes?
>
>You can combine them, but* then the "download" will be extended by the time 
>needed to re-code the file _and_ you'll lose the ability to retry the 
>conversion if something goes up the wall. If you can afford the storage, I'd 
>definitely download and convert in separate steps.

I did not mean to first let the ts download complete into the ts file and then
start a conversion.
That can be done inside the script as a second operation following the capture.

What I really asked for is a way to let ffmpeg run the conversion with the
source not from a file but from the stream that it is downloading at the same
time.

Then since the conversion is faster than real time viewing the convert will be
essentially ready when the stream download is stopped on timeout.
Notice that I have a timeout in there to determine for how long the download is
supposed to be done:  "-t <CAPTURETIME>"
The download script is started at a set time via the at command in Linux and
shall end upon reaching the timout (since the stream continues).


>*assuming that the source is producing a ts which is captured as-is

I think that it is, this is the command:
ffmpeg -hide_banner -user_agent \"Mozilla\" -i URL -t 3600 -c
copy output.ts
Where URL is supplied on call as well as timeout 3600 (can be 7200 for 2 hours
etc)

>Also,
>"from 1280x720 to 640x320 px."  !=  "-vf scale=w=-4:h=$360"
>(what does the dollar sign do or is that a typo? complete output is always a 
>good idea.....)
>1280/720=1.77777 while 640/320=2.0, so I assume that should be 360.
I actually wrote 360 in the command example itself, the text above has the
typo...
But with an erroneous $ in front.

I copied the command from my script, which accepts the height as a parameter and
so in the actual command line it is specified as "-vf scale=w=-4:h=${VSIZE}"
When I replaced it I missed to also take out the $ char....
You are right that the parameter is 360, which makes a 1280x720 conversion come
out as exactly 640x320. This should help in the internal processing of pixels.

>Have you looked at the CPU usage for each step?

Yes I have, the download itself is barely noticable whereas the conversion taxes
the CPU a lot. That is why the "-threads 1" is there to not completely lock up
the server.

So how should a command that uses the input *stream* as source to the mp4
conversion look like?


-- 
Bo Berglund
Developer in Sweden



More information about the ffmpeg-user mailing list