[FFmpeg-user] How to download and transcode video stream to mp4 and save the TS stream to file at the same time?

Ferdi Scholten ferdi at sttc-nlp.nl
Mon Sep 30 09:40:49 EEST 2024



On 30-09-2024 07:55, Bo Berglund wrote:
> On Mon, 30 Sep 2024 09:49:34 +0530, Gyan Doshi <ffmpeg at gyani.pro> wrote:
>
>>
>> On 2024-09-30 01:29 am, Bo Berglund wrote:
>>> I have created a script that downloads Internet video streams (basically news
>>> programs) and transcodes to mp4 format with a fixed windows size.
>>> As soon as the video stream recording ends the mp4 file can be played.
>>>
>>> I wonder if there is a way to let ffmpeg do two things at the same time:
>>> - download as now but save the stream to a TS formatted file and:
>>> - transcode to the mp4 format into a different output file
>>>
>>> This would make it possible to start viewing the downloaded file in TS format
>>> while the real output file remains unplayable until the download finishes and
>>> the moov atom gets written.
>> Three months ago, ffmpeg's mov/mp4 muxer added a movflags called
>> `hybrid_fragmented`
>>
>>  From the doc description,
>>
>> "
>> For recoverability - write the output file as a fragmented file. This
>> allows the intermediate file to be read while being written (in
>> particular, if the writing process is aborted uncleanly). When writing
>> is finished, the file is converted to a regular, non-fragmented file,
>> which is more compatible and allows easier and quicker seeking.
>>
>> If writing is aborted, the intermediate file can manually be remuxed to
>> get a regular, non-fragmented file of what had been written into the
>> unfinished file.
>> "
> Sounds like what I have been looking for all along!
> Could you provide the ffmpeg version where this is available?
>
> Unfortunately, this is what I get when checking versions on my main Ubuntu
> 20.04.6 LTS server box where the downloads happen:
>
> $ apt policy ffmpeg
> ffmpeg:
>    Installed: 7:4.3.2-0york0~18.04
>    Candidate: 7:4.3.2-0york0~18.04
>
> I guess version 7:4.3.2 is not good enough, so how can I upgrade on my Ubuntu
> 20.04.6 LTS box?
>
> On another Linux laptop running Ubuntu 22.04.5 LTS I get this:
>
> $ apt policy ffmpeg
> ffmpeg:
>    Installed: 7:4.4.2-0ubuntu0.22.04.1+esm5
>    Candidate: 7:4.4.2-0ubuntu0.22.04.1+esm5
>
> And on a Linux-Mint desktop I have an even older vcersion:
>
> $ apt policy ffmpeg
> ffmpeg:
>    Installed: 7:4.2.7-0ubuntu0.1
>    Candidate: 7:4.2.7-0ubuntu0.1
>
> Lastly on a Raspberry-Pi5 box I have:
>
> $ apt policy ffmpeg
> ffmpeg:
>    Installed: 8:5.1.5-0+rpt1+deb12u1
>    Candidate: 8:5.1.6-0+deb12u1+rpt1
>
> Here I see the main version stepped up to 8!
> Does this version contain the wanted feature?
>
> However, download on this box is a bit iffy in general, probably because of the
> RPi5 being a less capable device...
>
> The other  servers are on Lenovo or HP hardware...
>
> Basic install question on Linux:
>
> If one wants to get to the latest version of ffmpeg and it is not provided by
> the Linux distribution used, how can one upgrade to it?
>
>
Either build it from git/snapshot with the options you need/use or 
download and install the provided static builds from the master tree. 
Both are available via the Download page on ffmpeg.org
It looks like the static build has not been updated for a couple of 
months, so the best option is to compile ffmpeg yourself. There is a 
guide available for compilation of ffmpeg on Ubuntu on the ffmpeg wiki: 
https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu

It's not hard to build it, but it takes some time depending on the speed 
of your system.


More information about the ffmpeg-user mailing list