Re-writing hot .ts file that rotates every 24 hours in realtime

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Re-writing hot .ts file that rotates every 24 hours in realtime

serge2school
Hello,

we have a file that is written in realtime into .ts (MPEG-2). The file is written for 24 hours and then a new file starts.

Can we use ffmpeg to:
a. copy the file in realtime ? So, ffmpeg would be rewriting file1.ts into file2.ts as file1.ts is constantly being written into.
b. tell ffmpeg to read the file with a constant 3 second delay from the most updated frame?
c. if a new file appears, detect it and switch to it?

Thank you!



Sent from Outlook<http://aka.ms/weboutlook>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Re-writing hot .ts file that rotates every 24 hours in realtime

Michael Glenn Williams
Hi Korn,

We need additional info to help you. What O/S are you working with?
This is relevant to the buffered input and output when reading from stdin
and writing to stdout.
What language are you writing your script/program in?
This is relevant to what capabilities your tool will have access to.

Thank you for your question!
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Re-writing hot .ts file that rotates every 24 hours in realtime

serge2school

Hi,

thank you for your reply:

What I am trying to do:

a. copy the file in realtime ? So, ffmpeg would be rewriting file1.ts into file2.ts as file1.ts is constantly being written into.
b. tell ffmpeg to read the file with a constant 3 second delay from the most updated frame?
c. if a new file appears, detect it and switch to it?

My existing solution of using -re and -sseof has several disadvantages:

  1.  if use -sseof and -re together, I am missing the beginning of the file
  2.  if use only -re, then I need to launch ffmpeg few seconds after the new file is created otherwise I would be constantly hours behind.
  3.  I am sure there are a lot of other issues that I am not seeing

What is OS?
TS files are written on Windows 10 64 bit

What language the program is written in?
The program is written in GNU C++ (GCC) , but we can either use the library of if there is a way to do it from MSDOS shell - even better!

Thank you!


Sent from Outlook<http://aka.ms/weboutlook>

________________________________
From: ffmpeg-user <[hidden email]> on behalf of Michael Glenn Williams <[hidden email]>
Sent: Friday, February 12, 2021 7:18 PM
To: FFmpeg user questions <[hidden email]>
Subject: Re: [FFmpeg-user] Re-writing hot .ts file that rotates every 24 hours in realtime

Hi Korn,

We need additional info to help you. What O/S are you working with?
This is relevant to the buffered input and output when reading from stdin
and writing to stdout.
What language are you writing your script/program in?
This is relevant to what capabilities your tool will have access to.

Thank you for your question!
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Re-writing hot .ts file that rotates every 24 hours in realtime

Carl Zwanzig
On 2/15/2021 11:33 PM, Korn Moffle wrote:
> What I am trying to do:
> a. copy the file in realtime ? So, ffmpeg would be rewriting file1.ts into file2.ts as file1.ts is constantly being written into.

What's the goal of that?

> b. tell ffmpeg to read the file with a constant 3 second delay from the most updated frame?

...to add a 3 second delay?

If it's a real mpeg-ts stream, you could simply skip ffmpeg and as
bytes/blocks are written to one file*, read/buffer for 3 seconds/write out
to other file. You'll, of course, need a long enough circular buffer to hold
that much stream.

*watch that with select(), poll(), or the windoze equivalent


> c. if a new file appears, detect it and switch to it?

Also, do this with your program. Be careful of the boundary conditions when
starting and when switching files; if nothing else, you're probably not
guaranteed that the new file will start on a new frame; depends on the
writer. Fortunately, transport streams are designed to be somewhat resilient
to interruptions.

Later,

z!
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Re-writing hot .ts file that rotates every 24 hours in realtime

Moritz Barsnick
On Wed, Feb 17, 2021 at 22:18:00 -0800, Carl Zwanzig wrote:
> On 2/15/2021 11:33 PM, Korn Moffle wrote:
> > What I am trying to do:
> > a. copy the file in realtime ? So, ffmpeg would be rewriting file1.ts into file2.ts as file1.ts is constantly being written into.
>
> What's the goal of that?

I think he may be trying to tell us he wants to process the data
created by the first ffmpeg in realtime?
>
> > b. tell ffmpeg to read the file with a constant 3 second delay from the most updated frame?
>
> ...to add a 3 second delay?

Perhaps to avoid reading beyond the end of the file?

It sound to me as the first process is constantly recording a stream
straight to disk, and shall turn around to the next file after a
certain time. The second process reads these files while they are being
created, and does something else.

This sound a lot live HLS live streaming. The first process creates a
dynamic .m3u8 with segments, the second process knows how to read
these in real time. It even uses MPEG-TS underneath by default.

Have a look at the "hls" muxer (and demuxer).

Cheers,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Re-writing hot .ts file that rotates every 24 hours in realtime

Michael Glenn Williams
In reply to this post by serge2school
Hi Korn,


> What I am trying to do:
>
> a. copy the file in realtime ? So, ffmpeg would be rewriting file1.ts into
> file2.ts as file1.ts is constantly being written into.
>
OK, so we need to create a connection between ffmpeg and file 1 that will
not return EOF, and will block if there is no data. Something like using
stdin instead of reading the file directly. I'm not a windows programmer
but this seems to do what you need:
https://docs.microsoft.com/en-us/windows/win32/procthread/creating-a-child-process-with-redirected-input-and-output


> b. tell ffmpeg to read the file with a constant 3 second delay from the
> most updated frame?
>
Read works by how much you request to read. You can certainly create a
timer loop that requests an amount of data after 3 seconds, then waits to
read for another 3 secs.


> c. if a new file appears, detect it and switch to it?
>
When we say a new file appears, do we mean that file1.ts gets overwritten
with a new file1.ts ?

>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".