| @@ -98,6 +98,9 @@ static const AVOption options[] = { · 97 unmodified lines |
| 98 | 98 | { "encryption_kid", "The media encryption key identifier (hex)", offsetof(MOVMuxContext, encryption_kid), AV_OPT_TYPE_BINARY, .flags = AV_OPT_FLAG_ENCODING_PARAM }, |
| 99 | 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 | 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 | 104 | { NULL }, |
| 102 | 105 | }; |
| 103 | 106 | |
| @@ -4514,6 +4517,49 @@ static int mov_write_sidx_tags(AVIOContext *pb, MOVMuxContext *mov, · 4410 unmodified lines |
| 4514 | 4517 | return 0; |
| 4515 | 4518 | } |
| 4516 | 4519 | |
| 4520 | +static 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 | + |
| 4517 | 4563 | static int mov_write_moof_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks, |
| 4518 | 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 | 4574 | if (mov->flags & FF_MOV_FLAG_DASH && !(mov->flags & FF_MOV_FLAG_GLOBAL_SIDX)) |
| 4529 | 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 | 4580 | if (mov->flags & FF_MOV_FLAG_GLOBAL_SIDX || |
| 4532 | 4581 | !(mov->flags & FF_MOV_FLAG_SKIP_TRAILER) || |
| 4533 | 4582 | mov->ism_lookahead) { |
| @@ -5317,6 +5366,7 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) · 783 unmodified lines |
| 5317 | 5366 | trk->cluster[trk->entry].size = size; |
| 5318 | 5367 | trk->cluster[trk->entry].entries = samples_in_chunk; |
| 5319 | 5368 | trk->cluster[trk->entry].dts = pkt->dts; |
| 5369 | + trk->cluster[trk->entry].pts = pkt->pts; |
| 5320 | 5370 | if (!trk->entry && trk->start_dts != AV_NOPTS_VALUE) { |
| 5321 | 5371 | if (!trk->frag_discont) { |
| 5322 | 5372 | /* First packet of a new fragment. We already wrote the duration |