Merge commit 'ca489564ae150bc41764f175b88151d883e69ae0'
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>
Sun, 22 Nov 2015 17:41:51 +0000 (17:41 +0000)
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>
Sun, 22 Nov 2015 17:41:51 +0000 (17:41 +0000)
* commit 'ca489564ae150bc41764f175b88151d883e69ae0':
  movenc: add fallback audio track tref support

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
1  2 
libavformat/movenc.c

@@@ -3201,23 -2285,23 +3201,34 @@@ static int mov_write_moov_tag(AVIOConte
              mov->tracks[i].tref_id  = mov->tracks[mov->chapter_track].track_id;
          }
      for (i = 0; i < mov->nb_streams; i++) {
-         if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) {
-             mov->tracks[i].tref_tag = MKTAG('h','i','n','t');
-             mov->tracks[i].tref_id =
-                 mov->tracks[mov->tracks[i].src_track].track_id;
+         MOVTrack *track = &mov->tracks[i];
+         if (track->tag == MKTAG('r','t','p',' ')) {
+             track->tref_tag = MKTAG('h','i','n','t');
+             track->tref_id = mov->tracks[track->src_track].track_id;
+         } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) {
+             int * fallback, size;
+             fallback = (int*)av_stream_get_side_data(track->st,
+                                                      AV_PKT_DATA_FALLBACK_TRACK,
+                                                      &size);
+             if (fallback != NULL && size == sizeof(int)) {
+                 if (*fallback >= 0 && *fallback < mov->nb_streams) {
+                     track->tref_tag = MKTAG('f','a','l','l');
+                     track->tref_id = mov->tracks[*fallback].track_id;
+                 }
+             }
          }
      }
 +    for (i = 0; i < mov->nb_streams; i++) {
 +        if (mov->tracks[i].tag == MKTAG('t','m','c','d')) {
 +            int src_trk = mov->tracks[i].src_track;
 +            mov->tracks[src_trk].tref_tag = mov->tracks[i].tag;
 +            mov->tracks[src_trk].tref_id  = mov->tracks[i].track_id;
 +            //src_trk may have a different timescale than the tmcd track
 +            mov->tracks[i].track_duration = av_rescale(mov->tracks[src_trk].track_duration,
 +                                                       mov->tracks[i].timescale,
 +                                                       mov->tracks[src_trk].timescale);
 +        }
 +    }
  
      mov_write_mvhd_tag(pb, mov);
      if (mov->mode != MODE_MOV && !mov->iods_skip)