How to tell Kodi that a video file is being written to?

I have tried to use Kodi to play files which are in the process of being downloaded so that I don’t have to wait until the stream is done, but it only partially works…

On my Ubuntu server I download various internet video streams to mp4 files for later viewing via OSMC on a number of RaspberryPi devices and that has worked fine for years.
But there has been the problem that I cannot view them until the download finishes and the mp4 file is properly closed. And that is because the mp4 file format has some kind of marker (called moov) that is only written by ffmpeg at the finish of a file download.

So I tried to change the download target from mp4 to the ts type instead and Kodi initially seems happy to play these files. But only for a while…

After some testing I have found that in the following situation playback is erratic:

  • Start downloading the stream to a ts type video file
  • Wait say 5 minutes and then navigate to the file in Kodi and play it
  • After 5 minutes the playback still works but behaves erratically when using pause, jump back and jump forward commands.
  • Stop the playback and re-open the file again
  • Now playback seems to be OK until you jump or play forward to the time corresponding to file length at the time you re-started playing it, then the problems re-appear.

It seems like the problem is that Kodi does not check the current length of the file when playing it, it looks like it uses the length at the time playback started as the immutable video length even though the file grows.

Is there some setting that can tell Kodi to update the video length while playing a file that is of type ts (or other file formats that can be written and played at the same time)?

No. You would want a different approach for something like this.

OK, thanks.
I have to start searching then.

What you’re doing is named progressive download and even for the mp4 files it is possible to move the critical moov atom to the beginning of the file, see the linked article.

With TVHeadend I use the mkv container format to record news broadcasts from DVB-C and which then in most cases I watch some minutes later after start of the recording (some kind of time-shifting which prevents the stress to sit on front of the TV at exact 7 or 8 pm to get the news).
This works great and I even can jump around in the video in case I want to skip the advertising block between the news and the wheather report.

TVheadend can also use MPEG-TS container format. I’ll configure that in TVheadend and will test whether this makes any difference.

Yes, there is a difference using the standard video player of kodi started in the file mgr and the start of a running recording from the TV menu item:

  • Started from TV menu: You see in the OSD (OSMC skin assumed) on the left bottom side the current and the end time stamp and both change with the time while the recording is still running.
  • Started from the file mgr menu: The OSD shows a fix end time stamp which presents the time stamp when the playback was started.

So, at least in theory it is possible but I don’t know what the TVheadend HTSP client addon is doing to achieve this. Perhaps, this is part of the HTSP protocol between the TVheadend HTSP client and tvheadend server. The client is not accessing the file directly. Better, you ask in the kodi forum for ideas.