Fixes Ticket5414
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
... | ... |
@@ -4939,21 +4939,25 @@ static int mov_create_chapter_track(AVFormatContext *s, int tracknum) |
4939 | 4939 |
return 0; |
4940 | 4940 |
} |
4941 | 4941 |
|
4942 |
-static int mov_create_timecode_track(AVFormatContext *s, int index, int src_index, const char *tcstr) |
|
4942 |
+ |
|
4943 |
+static int mov_check_timecode_track(AVFormatContext *s, AVTimecode *tc, int src_index, const char *tcstr) |
|
4944 |
+{ |
|
4945 |
+ int ret; |
|
4946 |
+ |
|
4947 |
+ /* compute the frame number */ |
|
4948 |
+ ret = av_timecode_init_from_string(tc, find_fps(s, s->streams[src_index]), tcstr, s); |
|
4949 |
+ return ret; |
|
4950 |
+} |
|
4951 |
+ |
|
4952 |
+static int mov_create_timecode_track(AVFormatContext *s, int index, int src_index, AVTimecode tc) |
|
4943 | 4953 |
{ |
4944 | 4954 |
int ret; |
4945 | 4955 |
MOVMuxContext *mov = s->priv_data; |
4946 | 4956 |
MOVTrack *track = &mov->tracks[index]; |
4947 | 4957 |
AVStream *src_st = s->streams[src_index]; |
4948 |
- AVTimecode tc; |
|
4949 | 4958 |
AVPacket pkt = {.stream_index = index, .flags = AV_PKT_FLAG_KEY, .size = 4}; |
4950 | 4959 |
AVRational rate = find_fps(s, src_st); |
4951 | 4960 |
|
4952 |
- /* compute the frame number */ |
|
4953 |
- ret = av_timecode_init_from_string(&tc, rate, tcstr, s); |
|
4954 |
- if (ret < 0) |
|
4955 |
- return ret; |
|
4956 |
- |
|
4957 | 4961 |
/* tmcd track based on video stream */ |
4958 | 4962 |
track->mode = mov->mode; |
4959 | 4963 |
track->tag = MKTAG('t','m','c','d'); |
... | ... |
@@ -5242,9 +5246,14 @@ static int mov_write_header(AVFormatContext *s) |
5242 | 5242 |
/* +1 tmcd track for each video stream with a timecode */ |
5243 | 5243 |
for (i = 0; i < s->nb_streams; i++) { |
5244 | 5244 |
AVStream *st = s->streams[i]; |
5245 |
+ t = global_tcr; |
|
5245 | 5246 |
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && |
5246 |
- (global_tcr || av_dict_get(st->metadata, "timecode", NULL, 0))) |
|
5247 |
- mov->nb_meta_tmcd++; |
|
5247 |
+ (t || (t=av_dict_get(st->metadata, "timecode", NULL, 0)))) { |
|
5248 |
+ AVTimecode tc; |
|
5249 |
+ ret = mov_check_timecode_track(s, &tc, i, t->value); |
|
5250 |
+ if (ret >= 0) |
|
5251 |
+ mov->nb_meta_tmcd++; |
|
5252 |
+ } |
|
5248 | 5253 |
} |
5249 | 5254 |
|
5250 | 5255 |
/* check if there is already a tmcd track to remux */ |
... | ... |
@@ -5509,11 +5518,14 @@ static int mov_write_header(AVFormatContext *s) |
5509 | 5509 |
t = global_tcr; |
5510 | 5510 |
|
5511 | 5511 |
if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { |
5512 |
+ AVTimecode tc; |
|
5512 | 5513 |
if (!t) |
5513 | 5514 |
t = av_dict_get(st->metadata, "timecode", NULL, 0); |
5514 | 5515 |
if (!t) |
5515 | 5516 |
continue; |
5516 |
- if ((ret = mov_create_timecode_track(s, tmcd_track, i, t->value)) < 0) |
|
5517 |
+ if (mov_check_timecode_track(s, &tc, i, t->value) < 0) |
|
5518 |
+ continue; |
|
5519 |
+ if ((ret = mov_create_timecode_track(s, tmcd_track, i, tc)) < 0) |
|
5517 | 5520 |
goto error; |
5518 | 5521 |
tmcd_track++; |
5519 | 5522 |
} |