MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / copy_chapters

Function copy_chapters

ffmpeg.c:1705–1744  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1703}
1704
1705static int copy_chapters(int infile, int outfile)
1706{
1707 AVFormatContext *is = input_files[infile];
1708 AVFormatContext *os = output_files[outfile];
1709 int i;
1710
1711 for (i = 0; i < is->nb_chapters; i++) {
1712 AVChapter *in_ch = is->chapters[i], *out_ch;
1713 AVMetadataTag *t = NULL;
1714 int64_t ts_off = av_rescale_q(start_time - input_files_ts_offset[infile],
1715 AV_TIME_BASE_Q, in_ch->time_base);
1716 int64_t rt = (recording_time == INT64_MAX) ? INT64_MAX :
1717 av_rescale_q(recording_time, AV_TIME_BASE_Q, in_ch->time_base);
1718
1719
1720 if (in_ch->end < ts_off)
1721 continue;
1722 if (rt != INT64_MAX && in_ch->start > rt + ts_off)
1723 break;
1724
1725 out_ch = av_mallocz(sizeof(AVChapter));
1726 if (!out_ch)
1727 return AVERROR(ENOMEM);
1728
1729 out_ch->id = in_ch->id;
1730 out_ch->time_base = in_ch->time_base;
1731 out_ch->start = FFMAX(0, in_ch->start - ts_off);
1732 out_ch->end = FFMIN(rt, in_ch->end - ts_off);
1733
1734 while ((t = av_metadata_get(in_ch->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
1735 av_metadata_set2(&out_ch->metadata, t->key, t->value, 0);
1736
1737 os->nb_chapters++;
1738 os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters);
1739 if (!os->chapters)
1740 return AVERROR(ENOMEM);
1741 os->chapters[os->nb_chapters - 1] = out_ch;
1742 }
1743 return 0;
1744}
1745
1746/*
1747 * The following code is the main loop of the file converter

Callers 1

av_transcodeFunction · 0.85

Calls 5

av_rescale_qFunction · 0.85
av_malloczFunction · 0.85
av_metadata_getFunction · 0.85
av_metadata_set2Function · 0.85
av_reallocFunction · 0.85

Tested by

no test coverage detected