History

avformat/segment: fix increment_tc

inner stream avg_frame_rate wasn't populated, so tc formation failed. Also, extended increment_tc to cover individual stream timecode.

Gyan Doshi committed 7 years ago

Commit 2fdbeb01 parent 268ab171 file · +19 −2Browse files

Unified · Split

libavformat/segment.c+19−2
@@ -180,6 +180,7 @@ static int segment_mux_init(AVFormatContext *s) · 179 unmodified lines
180180 }
181181 st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
182182 st->time_base = s->streams[i]->time_base;
183+ st->avg_frame_rate = s->streams[i]->avg_frame_rate;
183184 av_dict_copy(&st->metadata, s->streams[i]->metadata, 0);
184185 }
185186
@@ -421,7 +422,7 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last) · 235 unmodified lines
421422 rate = s->streams[i]->avg_frame_rate;/* Get fps from the video stream */
422423 err = av_timecode_init_from_string(&tc, rate, tcr->value, s);
423424 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");
425426 break;
426427 }
427428 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
431432 }
432433 }
433434 } 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+ }
435452 }
436453 }
437454

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t