This series adds a demuxer and a muxer for the Time-Addressable Media Store
(TAMS), an open API specification started by BBC R&D for storing media in
the cloud as immutable, time-addressable segments on a shared nanosecond
TAI timeline:

  https://bbc.github.io/tams/
  https://github.com/bbc/tams

There is an open-source implementation from AWS which this was tested
against:

  https://github.com/aws-samples/time-addressable-media-store

The work was done at Hoot Works Ltd. A longer write-up of the design and
the notes made along the way is at:

  https://hoot.works/news/tams-implementation-in-ffmpeg/

Usage:

  # read a Flow, or all Flows of a Source, optionally a timerange of it
  ffmpeg -headers "Authorization: Bearer $TOKEN" \
    -i "https://<store>/flows?source_id=<id>&timerange=[10:0_20:0)" ...

  # write video+audio to a new multi Flow sharing one container
  ffmpeg -i INPUT -c:v libx264 -c:a aac \
    -flow_map "flow=streams=0,1,multi_flow=0" \
    -headers "Authorization: Bearer $TOKEN" -f tams https://<store>/flows

Patch 1 adds the shared data model:
- Flows, segments, timestamps, timeranges
- JSON parsing/serialisation
- HTTP requests with retry
- Not built until patch 2 is added.

Patch 2 adds the demuxer:
- Flow or Source input
- Timerange restriction
- Seeking
- Shared-container multi Flows via container_mapping
- Following a Flow live while it is being written

Patch 3 adds the muxer:
- One Flow per stream by default or grouped into multi Flows or
  pinned to existing Flows and Sources with -flow_map.
- Each segment is a self-contained object from a nested muxer, uploaded to a
  presigned URL from the store and registered with its timerange, ts_offset
  and last_duration.

Notes for reviewers:

- There is no JSON library dependency as parsing uses a small cursor-based
  parser over AVBPrint covering just the TAMS schemas.
- POST/PUT requests go through ffurl_open_whitelist()/ffurl_read() rather
  than AVIOContext, because a write-flagged AVIOContext never reads the
  response back.
- Targets TAMS API 8.2. Flows using separate init segments (new in 8.2)
  are rejected with an error for now.
- Segment formats are detected by probing the objects, not taken from the
  Flow's container MIME type, so raw video or PCM objects with no
  container are not readable. The muxer wraps those in a container.
- A video or audio Flow whose codec has no TAMS codec MIME mapping is
  skipped by the demuxer with a warning, and rejected by the muxer.
- Audio priming stays before the Flow start. Where it ends part way through
  a packet, the demuxer marks the part before the start as skip samples.
- -ss on Flows stored as raw H.264/HEVC elementary streams is only
  segment-accurate: their packets carry no timestamps, so ffmpeg cannot
  drop the frames between the segment start and the seek point.

Use of AI tools:

This series was developed with the help of Claude (Anthropic) as a coding
assistant, which is credited with an Assisted-by trailer on each patch.
I drove the design and implementation step by step across many sessions:
deciding the architecture and behaviour, directing each change, reviewing
the generated code, and refactoring or rejecting numerous approaches along
the way. It also helped with the end-to-end testing against a TAMS store
described below, which found and fixed several bugs. I have reviewed and
tested the final code and take full responsibility for it, and I'm happy
to explain or rework any part of it in review.

Testing:

- make fate passes; new unit tests fate-tams, fate-tamsdec, fate-tamsenc,
  and sample tests fate-tams-{audio,video,multi,multi-mapped}.
- The fate-tams-* sample tests need a small tams/ directory (Flow and
  segment JSON and their media objects, ~5 MB) adding to the FATE suite.
  The content is available here:
  https://hoot.works/assets/download/tams-fate-samples.tar.gz
  Local Flow JSON is read as complete responses (no query strings),
  so the sample file names are valid on Windows.
- 600 runs of tools/trasher on the sample Flow JSON: no crashes or hangs.
- End-to-end against a hosted AWS TAMS instance (API 8.2):
  - Mux then demux (by Flow and by Source) for
  H.264, HEVC, VP8, VP9, AV1, MPEG-2, raw video, AAC, MP3, MP2, AC-3,
  E-AC-3, PCM (16/24/32-bit integer, 32/64-bit float), SubRip and WebVTT.
  - From encoded input and stream copied from MP4 and MPEG-TS.
  - Raw elementary-stream, MP4, MOV, MPEG-TS and Matroska containers.
  - Shared and independent multi Flows.
  - Appending to existing Flows/Sources/multi Flows.
  - Timerange requests and seeking.
  - A realtime 720p mux read back concurrently by Flow and by Source,
  joining late, and with the writer killed part way through.
  - Timerange requests were also read while a Flow as live:
    - before its start
    - part written
    - open-ended
    - in the future.
  - Edited Flows built on the store re-using whole and partial objects at
    new timeline position.

Nick Ryan (3):
  avformat/tams: add shared Time-Addressable Media Store code
  avformat: add TAMS demuxer
  avformat: add TAMS muxer

 Changelog                        |    1 +
 MAINTAINERS                      |    1 +
 configure                        |    1 +
 doc/demuxers.texi                |   97 ++
 doc/general_contents.texi        |    1 +
 doc/muxers.texi                  |  165 ++
 libavformat/Makefile             |    5 +
 libavformat/allformats.c         |    2 +
 libavformat/tams.c               | 2472 ++++++++++++++++++++++++++++
 libavformat/tams.h               |  490 ++++++
 libavformat/tamsdec.c            | 2419 ++++++++++++++++++++++++++++
 libavformat/tamsenc.c            | 2580 ++++++++++++++++++++++++++++++
 libavformat/tests/.gitignore     |    3 +
 libavformat/tests/tams.c         | 1719 ++++++++++++++++++++
 libavformat/tests/tamsdec.c      | 1184 ++++++++++++++
 libavformat/tests/tamsenc.c      |  634 ++++++++
 libavformat/version.h            |    2 +-
 tests/Makefile                   |    1 +
 tests/fate/libavformat.mak       |   12 +
 tests/fate/tamsdec.mak           |   15 +
 tests/ref/fate/tams              |   43 +
 tests/ref/fate/tams-audio        |  570 +++++++
 tests/ref/fate/tams-multi        |  908 +++++++++++
 tests/ref/fate/tams-multi-mapped |  166 ++
 tests/ref/fate/tams-video        |  338 ++++
 tests/ref/fate/tamsdec           |   34 +
 tests/ref/fate/tamsenc           |   37 +
 27 files changed, 13899 insertions(+), 1 deletion(-)
 create mode 100644 libavformat/tams.c
 create mode 100644 libavformat/tams.h
 create mode 100644 libavformat/tamsdec.c
 create mode 100644 libavformat/tamsenc.c
 create mode 100644 libavformat/tests/tams.c
 create mode 100644 libavformat/tests/tamsdec.c
 create mode 100644 libavformat/tests/tamsenc.c
 create mode 100644 tests/fate/tamsdec.mak
 create mode 100644 tests/ref/fate/tams
 create mode 100644 tests/ref/fate/tams-audio
 create mode 100644 tests/ref/fate/tams-multi
 create mode 100644 tests/ref/fate/tams-multi-mapped
 create mode 100644 tests/ref/fate/tams-video
 create mode 100644 tests/ref/fate/tamsdec
 create mode 100644 tests/ref/fate/tamsenc

-- 
2.43.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to