OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Python API referencev12.0

SessionPlayer

class optris_sdk.session.SessionPlayer

A session being replayed, several cameras on one clock.

::

with optris_sdk.SessionPlayer.open('plant.mkv') as session:
  for i in range(session.source_count):
    print(session.source_info(i))
  session.on_frame(lambda source, frame: draw(source, frame))
  session.play()

Also opens an ordinary single-camera recording, as a session of one source, so an application that has moved to this API needs only one code path and every file the single-camera recorder ever wrote stays readable. is_session says which you got.

One seek_to moves every source. That is what makes a session a session.

SessionPlayer — properties

source_count

How many sources the file holds.

Read once, at the open: a file's source count cannot change while it is open.

is_session

Whether the file carries a session document.

False for a single-camera recording opened through this API, which still plays -- the names and identities are then whatever the ordinary file metadata carries, or empty.

is_at_end

Whether every source has delivered everything it holds.

This is the question, not position_s >= duration_s. The position is the last delivered frame's session time and the duration counts that frame's own length as well, so the two stand one frame period apart on a correct file and never meet.

Goes false again after play, stop and seek_to, so a transport that has run out can be restarted or dragged back. A looping session never reports an end, because it does not have one.

duration_s

How long the session is, in seconds.

The end of whichever source ran longest -- the end of its last frame, not the position of it, so this is the length of the recording rather than the timestamp of its last picture. A source that ended early does not shorten it: north running ten seconds beside a south that stopped at three is a ten-second session with a source that ended.

Deliberately not the container's own duration, which counts the telemetry tracks a session also has.

position_s

Where playback has got to, in seconds of session time.

The last delivered frame's session time. See is_at_end for why this never reaches duration_s.

started_at

When the session was recorded, as an aware UTC datetime.datetime, or None for a file that did not record one.

sources

Every source's SessionSourceInfo, in order.

statistics

The session's SessionPlaybackStats.

Session-wide, not per source -- unlike RecordingSession.statistics.

SessionPlayer — methods

open(cls, path)

Open a session, or a single-camera recording, for replay.

The file is scanned once here, which is what fills in the per-source frame counts, spans, gaps and outages -- so all of those are readable before a single frame is decoded.

Raises optris_sdk.errors.IoError when the file cannot be read or carries no video track.

source_info(source)

One source's SessionSourceInfo.

outage_count(source)

How many recorded outages one source has.

Zero for a source that was never away and for a file written before outages were recorded -- those two are not distinguishable through this API.

outages(source)

One source's SessionOutage spans, earliest first.

Available the moment the file is open, before anything is played, so an application can draw the holes onto its transport bar rather than discovering them by playing through.

presentation_at(source, at_s)

What a viewer should show for source at at_s.

One of the SESSION_PRESENTATION_* constants. Consistent with what on_presentation reports while playing, because both read the same recorded spans -- so a transport bar drawn from this cannot disagree with the picture.

A time past the end of the session is not an error.

on_frame(handler)

Be handed each thermal frame as the session plays.

handler takes (source, frame). None stops delivery.

Frames arrive in session order across sources, so a consumer that redraws a canvas on each one gets the dashboard as it was. Re-queueing them per camera throws that away.

The handler runs on the playback thread, and the frame is borrowed: it is valid until the handler returns and this package invalidates it afterwards, so using it later raises rather than reading freed memory. Keep pixels by copying them, or the frame with optris_sdk.camera.Frame.clone. Do not close the player from the handler.

on_color_frame(handler)

Be handed each visual picture as the session plays.

handler takes (source, rgb, width, height, timestamp_s), where rgb is bytes of packed RGB24. None stops delivery.

Separate from on_frame because the two carry different things and only one of them is a measurement. The bytes are copied out before your handler runs, so they outlive the call.

on_presentation(handler)

Be told what to show for a source, and from when.

handler takes a SessionPresentationChange. None stops delivery.

Fires on change, not per frame: once as playback enters a disconnection, once as it leaves, once when a track ends, and once per source at the start of playback and after every seek -- so a consumer that joined mid-file, or that has just dragged the transport bar, is never left guessing.

This is the one to use rather than holding a source's last frame across a hole. A held last frame is a still picture of a scene nobody is watching, with nothing on it to say so.

play()

Start playback on a background thread.

Returns before anything is delivered. Does not rewind: a session sitting at the end reads as being at the end and says so again. seek_to zero to play it through a second time.

pause()

Stop advancing and hold the position.

Joins the playback thread, so when this returns no handler is in flight.

stop()

Stop and rewind to the start of the session.

seek_to(position_s)

Move every source to position_s seconds of session time.

One call, all sources: that is what makes a session a session. Each source resumes at its first frame at or after position_s, so a source that was mid-gap at that moment delivers nothing until its next real frame rather than back-filling one -- and on_presentation re-fires per source so you are told why.

set_speed(speed)

Set the replay speed. 1.0 is real time, 0.5 half, 2.0 double.

A method rather than a property, deliberately: the ABI has no getter for it, and a property that can be written and not read is worse in Python than a verb that says what it does. The .NET binding spells it as a set-only property, which is a C#-ism.

Raises ValueError for zero, a negative or a NaN -- stop the playback rather than setting its speed to zero.

set_looping(looping)

Whether to restart from the beginning at the end.

A method for the same reason as set_speed. A looping session never reports is_at_end, because it does not have an end.

close()

Release the file. Closing twice is a no-op.

__enter__()

__exit__(*exc)

__del__()

__repr__()