Skip to content

Guides

Watch an analysis

Play a finished analysis in the app or a native player.

The app plays a finished analysis next to its scenes. Through the API, getVodAnalysisStream returns playlistUrl; give it to a player unchanged.

Set MEDIASEER_API_URL, MEDIASEER_API_KEY and ANALYSIS_ID as described in the quickstart.

Playback URLs and playlists are credentials. Keep them out of logs. The examples pass URLs through curl configuration files and ignore your curl configuration.

stream.sh
#!/usr/bin/env bash
#
# Gets a playback ticket for the analysis ANALYSIS_ID and loads its playlist, as a native player would.
set -euo pipefail
base="${MEDIASEER_API_URL:?the API origin, without /api/v1}"
base="${base%/}/api/v1"
: "${MEDIASEER_API_KEY:?your API key}"
id="${ANALYSIS_ID:?the id of a finished analysis}"
api() { curl -q -sS -H @- "$@" <<<"X-Api-Key: $MEDIASEER_API_KEY"; }
player() { curl -q -s --globoff -K "$tmp/playlist-url" "$@"; }
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
status="$(api -o "$tmp/stream.json" -w '%{http_code}' "$base/vod-analysis/$id/stream")" || {
echo "stream got no answer: curl exit $?" >&2
exit 1
}
if [[ "$status" != 200 ]]; then
echo "stream answered $status $(jq -r '.code // empty' "$tmp/stream.json" 2>/dev/null || true)" >&2
exit 1
fi
# The ticket in playlistUrl is a credential, and the playlists list signed URLs: neither goes to the output.
# The URL goes into curl's config file and nowhere else.
jq -r '"url = \(.playlistUrl | tojson)"' "$tmp/stream.json" >"$tmp/playlist-url"
# The player's request: no API key, the ticket in the URL is enough.
status="$(player -o "$tmp/master.m3u8" -w '%{http_code}')" || {
echo "loading the playlist failed: curl exit $?" >&2
exit 1
}
first="$(head -n 1 "$tmp/master.m3u8" | tr -d '\r')"
if [[ "$status" != 200 || "$first" != "#EXTM3U" ]]; then
echo "the playlist answered $status, or is no HLS playlist" >&2
exit 1
fi
expires="$(jq -r .expiresAt "$tmp/stream.json")"
echo "playlist: #EXTM3U"
echo "ticket expires at $expires"

Request a new playback URL when it expires; see link lifetimes.

A player on your own web page is blocked; use a native player or your server. This example uses ffplay from FFmpeg. ffplay and ffprobe expose the playback URL in the process list, so run them only on a machine you trust.

play.sh
#!/usr/bin/env bash
#
# Plays the analysis ANALYSIS_ID in ffplay (FFmpeg's player): a native player, which the API's CORS rules
# don't apply to. Needs FFmpeg's ffprobe and ffplay, and a display.
set -euo pipefail
base="${MEDIASEER_API_URL:?the API origin, without /api/v1}"
base="${base%/}/api/v1"
: "${MEDIASEER_API_KEY:?your API key}"
id="${ANALYSIS_ID:?the id of a finished analysis}"
api() { curl -q -sS -H @- "$@" <<<"X-Api-Key: $MEDIASEER_API_KEY"; }
if ! command -v ffprobe >/dev/null || ! command -v ffplay >/dev/null; then
echo "play.sh needs ffprobe and ffplay, which come with FFmpeg" >&2
exit 1
fi
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
status="$(api -o "$tmp/stream.json" -w '%{http_code}' "$base/vod-analysis/$id/stream")" || {
echo "stream got no answer: curl exit $?" >&2
exit 1
}
if [[ "$status" != 200 ]]; then
echo "stream answered $status $(jq -r '.code // empty' "$tmp/stream.json" 2>/dev/null || true)" >&2
exit 1
fi
playlist="$(jq -r .playlistUrl "$tmp/stream.json")"
# ffprobe and ffplay take the playlist URL only on their command line: while they run, other users of this
# machine can see it, the ticket included, in the process list. Play on a machine only you use.
# They also name their input in their log lines, and ffplay in its window title. So their output is off, and
# the window gets a title of its own.
# ffplay exits with 0 also when it can't open the stream, so ffprobe reads it first: it fails if the
# playlists or the segments can't be loaded.
probed=0
ffprobe -v quiet "$playlist" </dev/null >/dev/null 2>&1 || probed=$?
if [[ "$probed" != 0 ]]; then
echo "playback failed: ffprobe can't read the stream, exit $probed" >&2
exit 1
fi
played=0
ffplay -hide_banner -loglevel quiet -autoexit -window_title Mediaseer "$playlist" </dev/null >/dev/null 2>&1 ||
played=$?
if [[ "$played" != 0 ]]; then
echo "playback failed: ffplay exited with $played" >&2
exit 1
fi