History

avformat/movenc: creating producer reference time (PRFT) box

The producer reference time box supplies relative wall-clock times at which movie fragments, or files containing movie fragments (such as segments) were produced. The box is mainly useful in live streaming use cases. A media player can parse the box and utilize the time fields to measure and improve the latency during real time playout.

Vishwanath Dixit committed 8 years ago

Commit 5717cd81 parent f09635f3 files · +69 −0Browse files

Unified · Split

3 files
  1. doc/muxers.texi +10 −0
  2. libavformat/movenc.c +50 −0
  3. libavformat/movenc.h +9 −0
doc/muxers.texi+10−0
@@ -1344,6 +1344,16 @@ be negative. This enables the initial sample to have DTS/CTS of zero, and · 1343 unmodified lines
1344reduces the need for edit lists for some cases such as video tracks with1344reduces the need for edit lists for some cases such as video tracks with
1345B-frames. Additionally, eases conformance with the DASH-IF interoperability1345B-frames. Additionally, eases conformance with the DASH-IF interoperability
1346guidelines.1346guidelines.
1347@item -write_prft
1348Write producer time reference box (PRFT) with a specified time source for the
1349NTP field in the PRFT box. Set value as @samp{wallclock} to specify timesource
1350as wallclock time and @samp{pts} to specify timesource as input packets' PTS
1351values.
1352
1353Setting value to @samp{pts} is applicable only for a live encoding use case,
1354where PTS values are set as as wallclock time at the source. For example, an
1355encoding use case with decklink capture source where @option{video_pts} and
1356@option{audio_pts} are set to @samp{abs_wallclock}.
1347@end table1357@end table
1348 1358
1349@subsection Example1359@subsection Example
libavformat/movenc.c+50−0
@@ -98,6 +98,9 @@ static const AVOption options[] = { · 97 unmodified lines
98 { "encryption_kid", "The media encryption key identifier (hex)", offsetof(MOVMuxContext, encryption_kid), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },98 { "encryption_kid", "The media encryption key identifier (hex)", offsetof(MOVMuxContext, encryption_kid), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM },
99 { "use_stream_ids_as_track_ids", "use stream ids as track ids", offsetof(MOVMuxContext, use_stream_ids_as_track_ids), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},99 { "use_stream_ids_as_track_ids", "use stream ids as track ids", offsetof(MOVMuxContext, use_stream_ids_as_track_ids), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
100 { "write_tmcd", "force or disable writing tmcd", offsetof(MOVMuxContext, write_tmcd), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},100 { "write_tmcd", "force or disable writing tmcd", offsetof(MOVMuxContext, write_tmcd), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AV_OPT_FLAG_ENCODING_PARAM},
101 { "write_prft", "Write producer reference time box with specified time source", offsetof(MOVMuxContext, write_prft), AV_OPT_TYPE_INT, {.i64 = MOV_PRFT_NONE}, 0, MOV_PRFT_NB-1, AV_OPT_FLAG_ENCODING_PARAM, "prft"},
102 { "wallclock", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = MOV_PRFT_SRC_WALLCLOCK}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM, "prft"},
103 { "pts", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = MOV_PRFT_SRC_PTS}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM, "prft"},
101 { NULL },104 { NULL },
102};105};
103 106
@@ -4514,6 +4517,49 @@ static int mov_write_sidx_tags(AVIOContext *pb, MOVMuxContext *mov, · 4410 unmodified lines
4514 return 0;4517 return 0;
4515}4518}
4516 4519
4520static int mov_write_prft_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks)
4521{
4522 int64_t pos = avio_tell(pb), pts_us, ntp_ts;
4523 MOVTrack *first_track;
4524
4525 /* PRFT should be associated with at most one track. So, choosing only the
4526 * first track. */
4527 if (tracks > 0)
4528 return 0;
4529 first_track = &(mov->tracks[0]);
4530
4531 if (!first_track->entry) {
4532 av_log(mov->fc, AV_LOG_WARNING, "Unable to write PRFT, no entries in the track\n");
4533 return 0;
4534 }
4535
4536 if (first_track->cluster[0].pts == AV_NOPTS_VALUE) {
4537 av_log(mov->fc, AV_LOG_WARNING, "Unable to write PRFT, first PTS is invalid\n");
4538 return 0;
4539 }
4540
4541 if (mov->write_prft == MOV_PRFT_SRC_WALLCLOCK) {
4542 ntp_ts = ff_get_formatted_ntp_time(ff_ntp_time());
4543 } else if (mov->write_prft == MOV_PRFT_SRC_PTS) {
4544 pts_us = av_rescale_q(first_track->cluster[0].pts,
4545 first_track->st->time_base, AV_TIME_BASE_Q);
4546 ntp_ts = ff_get_formatted_ntp_time(pts_us + NTP_OFFSET_US);
4547 } else {
4548 av_log(mov->fc, AV_LOG_WARNING, "Unsupported PRFT box configuration: %d\n",
4549 mov->write_prft);
4550 return 0;
4551 }
4552
4553 avio_wb32(pb, 0); // Size place holder
4554 ffio_wfourcc(pb, "prft"); // Type
4555 avio_w8(pb, 1); // Version
4556 avio_wb24(pb, 0); // Flags
4557 avio_wb32(pb, first_track->track_id); // reference track ID
4558 avio_wb64(pb, ntp_ts); // NTP time stamp
4559 avio_wb64(pb, first_track->cluster[0].pts); //media time
4560 return update_size(pb, pos);
4561}
4562
4517static int mov_write_moof_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks,4563static int mov_write_moof_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks,
4518 int64_t mdat_size)4564 int64_t mdat_size)
4519{4565{
@@ -4528,6 +4574,9 @@ static int mov_write_moof_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks, · 8 unmodified lines
4528 if (mov->flags & FF_MOV_FLAG_DASH && !(mov->flags & FF_MOV_FLAG_GLOBAL_SIDX))4574 if (mov->flags & FF_MOV_FLAG_DASH && !(mov->flags & FF_MOV_FLAG_GLOBAL_SIDX))
4529 mov_write_sidx_tags(pb, mov, tracks, moof_size + 8 + mdat_size);4575 mov_write_sidx_tags(pb, mov, tracks, moof_size + 8 + mdat_size);
4530 4576
4577 if (mov->write_prft > MOV_PRFT_NONE && mov->write_prft < MOV_PRFT_NB)
4578 mov_write_prft_tag(pb, mov, tracks);
4579
4531 if (mov->flags & FF_MOV_FLAG_GLOBAL_SIDX ||4580 if (mov->flags & FF_MOV_FLAG_GLOBAL_SIDX ||
4532 !(mov->flags & FF_MOV_FLAG_SKIP_TRAILER) ||4581 !(mov->flags & FF_MOV_FLAG_SKIP_TRAILER) ||
4533 mov->ism_lookahead) {4582 mov->ism_lookahead) {
@@ -5317,6 +5366,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 783 unmodified lines
5317 trk->cluster[trk->entry].size = size;5366 trk->cluster[trk->entry].size = size;
5318 trk->cluster[trk->entry].entries = samples_in_chunk;5367 trk->cluster[trk->entry].entries = samples_in_chunk;
5319 trk->cluster[trk->entry].dts = pkt->dts;5368 trk->cluster[trk->entry].dts = pkt->dts;
5369 trk->cluster[trk->entry].pts = pkt->pts;
5320 if (!trk->entry && trk->start_dts != AV_NOPTS_VALUE) {5370 if (!trk->entry && trk->start_dts != AV_NOPTS_VALUE) {
5321 if (!trk->frag_discont) {5371 if (!trk->frag_discont) {
5322 /* First packet of a new fragment. We already wrote the duration5372 /* First packet of a new fragment. We already wrote the duration
libavformat/movenc.h+9−0
@@ -46,6 +46,7 @@ · 45 unmodified lines
46typedef struct MOVIentry {46typedef struct MOVIentry {
47 uint64_t pos;47 uint64_t pos;
48 int64_t dts;48 int64_t dts;
49 int64_t pts;
49 unsigned int size;50 unsigned int size;
50 unsigned int samples_in_chunk;51 unsigned int samples_in_chunk;
51 unsigned int chunkNum; ///< Chunk number if the current entry is a chunk start otherwise 052 unsigned int chunkNum; ///< Chunk number if the current entry is a chunk start otherwise 0
@@ -169,6 +170,13 @@ typedef enum { · 117 unmodified lines
169 MOV_ENC_CENC_AES_CTR,170 MOV_ENC_CENC_AES_CTR,
170} MOVEncryptionScheme;171} MOVEncryptionScheme;
171 172
173typedef enum {
174 MOV_PRFT_NONE = 0,
175 MOV_PRFT_SRC_WALLCLOCK,
176 MOV_PRFT_SRC_PTS,
177 MOV_PRFT_NB
178} MOVPrftBox;
179
172typedef struct MOVMuxContext {180typedef struct MOVMuxContext {
173 const AVClass *av_class;181 const AVClass *av_class;
174 int mode;182 int mode;
@@ -224,6 +232,7 @@ typedef struct MOVMuxContext { · 49 unmodified lines
224 int use_stream_ids_as_track_ids;232 int use_stream_ids_as_track_ids;
225 int track_ids_ok;233 int track_ids_ok;
226 int write_tmcd;234 int write_tmcd;
235 MOVPrftBox write_prft;
227} MOVMuxContext;236} MOVMuxContext;
228 237
229#define FF_MOV_FLAG_RTP_HINT (1 << 0)238#define FF_MOV_FLAG_RTP_HINT (1 << 0)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t