PR #26206 opened by clementperon
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26206
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/26206.patch
# Summary of changes
With `-write_prft wallclock`, the MP4 muxer takes the time of the `prft` box
from the `AV_PKT_DATA_PRFT` side data of the first packet of the fragment, and
cuts it to whole milliseconds before writing it.
This writes the value as it is:
- The side data is in microseconds (the RTP demuxer sets it from the RTCP
sender reports), and the box holds a 64-bit NTP timestamp, so the digits fit.
- `-write_prft pts`, in the same function, already writes its time without
rounding.
## Where the rounding comes from
It is the rounding of `ff_ntp_time()`, which the RTP muxer uses for its sender
reports (d597e1b76c, 2008). The `prft` writer picked it up when it started to
use the side data (4e4ac20340 and 7abc0979e6, 2019), and ab9627223e moved it
inline. I found no reason given for it on the `prft` side.
## Reproduction
An RTSP loopback at 30 fps, so that frame times do not fall on whole
milliseconds:
```
ffmpeg -listen_timeout 30 -rtsp_transport tcp -i rtsp://127.0.0.1:8561/test -c
copy \
-movflags +frag_every_frame+empty_moov+default_base_moof -write_prft
wallclock out.mp4 &
ffmpeg -re -f lavfi -i testsrc=size=320x240:rate=30 -t 10 -c:v mpeg4 -q:v 5 \
-f rtsp -rtsp_transport tcp rtsp://127.0.0.1:8561/test
```
Times read from the 300 `prft` boxes of `out.mp4`:
| | Boxes on a whole millisecond | Interval between two boxes |
|---|---|---|
| Before | 300 | 33000 µs (199 times), 34000 µs (100 times) |
| After | 100 | 33333 µs (199 times), 33334 µs (100 times) |
## Notes
- The fallback on the current time, used when a packet has no side data, still
goes through `ff_ntp_time()` and is unchanged.
- No FATE test here: the demuxer does not read `prft` boxes yet (#26182 adds
that), and the option needs packets that carry the side data.
- With the reader of #26182, a file whose boxes hold microsecond times and that
is remuxed with `-c copy -write_prft wallclock` keeps them exactly (200 of 200
boxes; none before this change, with an error of up to 968 µs).
- Independent of #26182 and #26183. #26183 changes another line of the same
function.
## Tests
`make fate` with the sample suite passes (macOS arm64); no existing reference
changes.
AI disclosure: the patch, the tests and this description were prepared with
Claude Code.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
From c5c71f1d28e91453e75ed81040cd374ff77a6b2a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20P=C3=A9ron?= <[email protected]>
Date: Thu, 19 Nov 2026 16:54:57 +0100
Subject: [PATCH] avformat/movenc: write the prft wallclock with its full
precision
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
With -write_prft wallclock, the time taken from the AV_PKT_DATA_PRFT
side data of the packet was cut to whole milliseconds before it was
written. The side data is in microseconds and the box holds a 64-bit
NTP timestamp, so these digits can be stored as they are. The pts time
source in the same function already writes them.
The rounding came with ff_ntp_time(), which the RTP muxer uses for its
sender reports and which was reused here when the side data support was
added in 7abc0979e6.
The fallback on the current time, used when a packet has no side data,
is unchanged.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: Clément Péron <[email protected]>
---
libavformat/movenc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index da1a44d757d..89583356088 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -6206,8 +6206,7 @@ static int mov_write_prft_tag(AVIOContext *pb,
MOVMuxContext *mov, int tracks)
if (mov->write_prft == MOV_PRFT_SRC_WALLCLOCK) {
if (first_track->cluster[0].prft.wallclock) {
- /* Round the NTP time to whole milliseconds. */
- ntp_ts =
ff_get_formatted_ntp_time((first_track->cluster[0].prft.wallclock / 1000) *
1000 +
+ ntp_ts =
ff_get_formatted_ntp_time(first_track->cluster[0].prft.wallclock +
NTP_OFFSET_US);
flags = first_track->cluster[0].prft.flags;
} else
--
2.54.1
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]