inner stream avg_frame_rate wasn't populated, so tc formation failed. Also, extended increment_tc to cover individual stream timecode.
Unified · Split
| @@ -180,6 +180,7 @@ static int segment_mux_init(AVFormatContext *s) · 179 unmodified lines | ||
| 180 | 180 | } |
| 181 | 181 | st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; |
| 182 | 182 | st->time_base = s->streams[i]->time_base; |
| 183 | + st->avg_frame_rate = s->streams[i]->avg_frame_rate; | |
| 183 | 184 | av_dict_copy(&st->metadata, s->streams[i]->metadata, 0); |
| 184 | 185 | } |
| 185 | 186 | |
| @@ -421,7 +422,7 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last) · 235 unmodified lines | ||
| 421 | 422 | rate = s->streams[i]->avg_frame_rate;/* Get fps from the video stream */ |
| 422 | 423 | err = av_timecode_init_from_string(&tc, rate, tcr->value, s); |
| 423 | 424 | if (err < 0) { |
| 424 | − av_log(s, AV_LOG_WARNING, "Could not increment timecode, error occurred during timecode creation."); | |
| 425 | + av_log(s, AV_LOG_WARNING, "Could not increment global timecode, error occurred during timecode creation.\n"); | |
| 425 | 426 | break; |
| 426 | 427 | } |
| 427 | 428 | tc.start += (int)((seg->cur_entry.end_time - seg->cur_entry.start_time) * av_q2d(rate));/* increment timecode */ |
| @@ -431,7 +432,23 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last) · 3 unmodified lines | ||
| 431 | 432 | } |
| 432 | 433 | } |
| 433 | 434 | } else { |
| 434 | − av_log(s, AV_LOG_WARNING, "Could not increment timecode, no timecode metadata found"); | |
| 435 | + av_log(s, AV_LOG_WARNING, "Could not increment global timecode, no global timecode metadata found.\n"); | |
| 436 | + } | |
| 437 | + for (i = 0; i < s->nb_streams; i++) { | |
| 438 | + if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { | |
| 439 | + char st_buf[AV_TIMECODE_STR_SIZE]; | |
| 440 | + AVTimecode st_tc; | |
| 441 | + AVRational st_rate = s->streams[i]->avg_frame_rate; | |
| 442 | + AVDictionaryEntry *st_tcr = av_dict_get(s->streams[i]->metadata, "timecode", NULL, 0); | |
| 443 | + if (st_tcr) { | |
| 444 | + if ((av_timecode_init_from_string(&st_tc, st_rate, st_tcr->value, s) < 0)) { | |
| 445 | + av_log(s, AV_LOG_WARNING, "Could not increment stream %d timecode, error occurred during timecode creation.\n", i); | |
| 446 | + continue; | |
| 447 | + } | |
| 448 | + st_tc.start += (int)((seg->cur_entry.end_time - seg->cur_entry.start_time) * av_q2d(st_rate)); // increment timecode | |
| 449 | + av_dict_set(&s->streams[i]->metadata, "timecode", av_timecode_make_string(&st_tc, st_buf, 0), 0); | |
| 450 | + } | |
| 451 | + } | |
| 435 | 452 | } |
| 436 | 453 | } |
| 437 | 454 | |