Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
static void enable_tracks(AVFormatContext *s)
{
MOVMuxContext *mov = s->priv_data;
int i;
int enabled[AVMEDIA_TYPE_NB];
int first[AVMEDIA_TYPE_NB];
for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
enabled[i] = 0;
first[i] = -1;
}
for (i = 0; i < s->nb_streams; i++) {
AVStream *st = s->streams[i];
if (st->codecpar->codec_type <= AVMEDIA_TYPE_UNKNOWN ||
st->codecpar->codec_type >= AVMEDIA_TYPE_NB)
continue;
// note the first stream number for each type
if (first[st->codecpar->codec_type] < 0)
first[st->codecpar->codec_type] = i;
// note whether each media type has any enabled streams
if (st->disposition & AV_DISPOSITION_DEFAULT)
enabled[st->codecpar->codec_type] = 1;
// clear the enables for each stream and track
st->disposition &= ~AV_DISPOSITION_DEFAULT;
mov->tracks[i].flags &= ~MOV_TRACK_ENABLED;
}
// for each media type, if no stream was explicitly enabled
// then enable the first one found for that type
for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
switch (i) {
case AVMEDIA_TYPE_VIDEO:
case AVMEDIA_TYPE_AUDIO:
case AVMEDIA_TYPE_SUBTITLE:
if (!enabled[i] && first[i] >= 0)
enabled[i] = 1;
break;
}
}
// translate the first enabled stream of each media type
// into its stream being default and its output track being enabled
for (i = 0; i < AVMEDIA_TYPE_NB; i++) {
switch (i) {
case AVMEDIA_TYPE_VIDEO:
case AVMEDIA_TYPE_AUDIO:
case AVMEDIA_TYPE_SUBTITLE:
if (enabled[i]) {
s->streams[first[i]]->disposition |= AV_DISPOSITION_DEFAULT;
mov->tracks[first[i]].flags |= MOV_TRACK_ENABLED;
}
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.