static const AVOption options[] = {
{ "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
{ "rtphint", "Add RTP hint tracks", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" },
+ { "moov_size", "maximum moov size so it can be placed at the begin", offsetof(MOVMuxContext, reserved_moov_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
+ { "frag_size", "maximum fragment size", offsetof(MOVMuxContext, max_fragment_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
+ { "frag_duration", "maximum fragment duration", offsetof(MOVMuxContext, max_fragment_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 },
FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags),
+ { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM},
+ { "iods_audio_profile", "iods audio profile atom.", offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM},
+ { "iods_video_profile", "iods video profile atom.", offsetof(MOVMuxContext, iods_video_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM},
{ NULL },
};
return updateSize(pb, pos);
}
- #if 0
- /* TODO: Not sorted out, but not necessary either */
+static int mov_write_tfhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
+{
+ int64_t pos = avio_tell(pb);
+ int flags=1;
+
+ avio_wb32(pb, 0);
+ ffio_wfourcc(pb, "tfhd");
+ avio_w8(pb, 0);
+ avio_wb24(pb, flags);
+ avio_wb32(pb, track->trackID);
+
+ track->base_data_offset_pos= avio_tell(pb);
+ if (flags & 0x01) avio_wb64(pb, 0);
+
+ return updateSize(pb, pos);
+}
+
+static int mov_write_trun_tag(AVIOContext *pb, MOVTrack *track)
+{
+ int64_t pos = avio_tell(pb);
+ int sample_count= track->entry - track->cluster_write_index;
+ int tr_flags=0;
+ int i;
+
+ for(i=track->cluster_write_index; i<track->entry; i++){
+ int64_t duration = i + 1 == track->entry ?
+ track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */
+ track->cluster[i+1].dts - track->cluster[i].dts;
+ if(duration != 1) tr_flags |= 0x100;
+ if(track->trex_size != track->cluster[i].size) tr_flags |= 0x200;
+ if(track->trex_flags != ((track->cluster[i].flags&MOV_SYNC_SAMPLE) ? 0x02000000 : 0x01010000))
+ tr_flags |= 0x400;
+ if(track->cluster[i].cts) tr_flags |= 0x800;
+ }
+
+ avio_wb32(pb, 0);
+ ffio_wfourcc(pb, "trun");
+ avio_w8(pb, 0);
+ avio_wb24(pb, tr_flags);
+ avio_wb32(pb, sample_count);
+ if(tr_flags&1) avio_wb32(pb, 0);
+
+ for(i=track->cluster_write_index; i<track->entry; i++){
+ int64_t duration = i + 1 == track->entry ?
+ track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */
+ track->cluster[i+1].dts - track->cluster[i].dts;
+
+ if(tr_flags&0x100) avio_wb32(pb, duration);
+ if(tr_flags&0x200) avio_wb32(pb, track->cluster[i].size);
+ if(tr_flags&0x400) avio_wb32(pb, (track->cluster[i].flags&MOV_SYNC_SAMPLE) ? 0x02000000 : 0x01010000);
+ if(tr_flags&0x800) avio_wb32(pb, track->cluster[i].cts);
+ }
+
+ return updateSize(pb, pos);
+}
+
+static int mov_write_traf_tag(AVIOContext *pb, MOVTrack *track, AVStream *st)
+{
+ int64_t pos = avio_tell(pb);
+ avio_wb32(pb, 0); /* size */
+ ffio_wfourcc(pb, "traf");
+ mov_write_tfhd_tag(pb, track, st);
+ mov_write_trun_tag(pb, track);
+ return updateSize(pb, pos);
+}
+
static int mov_write_iods_tag(AVIOContext *pb, MOVMuxContext *mov)
{
- avio_wb32(pb, 0x15); /* size */
+ int i, has_audio = 0, has_video = 0;
+ int64_t pos = avio_tell(pb);
+ int audio_profile = mov->iods_audio_profile;
+ int video_profile = mov->iods_video_profile;
+ for (i = 0; i < mov->nb_streams; i++) {
+ if(mov->tracks[i].entry > 0) {
+ has_audio |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_AUDIO;
+ has_video |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_VIDEO;
+ }
+ }
+ if (audio_profile < 0)
+ audio_profile = 0xFF - has_audio;
+ if (video_profile < 0)
+ video_profile = 0xFF - has_video;
+ avio_wb32(pb, 0x0); /* size */
ffio_wfourcc(pb, "iods");
avio_wb32(pb, 0); /* version & flags */
- avio_wb16(pb, 0x1007);
- avio_w8(pb, 0);
- avio_wb16(pb, 0x4fff);
- avio_wb16(pb, 0xfffe);
- avio_wb16(pb, 0x01ff);
- return 0x15;
+ putDescr(pb, 0x10, 7);
+ avio_wb16(pb, 0x004f);
+ avio_w8(pb, 0xff);
+ avio_w8(pb, 0xff);
+ avio_w8(pb, audio_profile);
+ avio_w8(pb, video_profile);
+ avio_w8(pb, 0xff);
+ return updateSize(pb, pos);
}
- #endif
static int mov_write_mvhd_tag(AVIOContext *pb, MOVMuxContext *mov)
{
}
mov_write_mvhd_tag(pb, mov);
- //mov_write_iods_tag(pb, mov);
+ if (mov->mode != MODE_MOV && !mov->iods_skip)
+ mov_write_iods_tag(pb, mov);
for (i=0; i<mov->nb_streams; i++) {
if(mov->tracks[i].entry > 0) {
- mov_write_trak_tag(pb, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
+ mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL);
}
}