Revision 7a39f142 ffmpeg.c
ffmpeg.c | ||
---|---|---|
1646 | 1646 |
fflush(stdout); |
1647 | 1647 |
} |
1648 | 1648 |
|
1649 |
static int copy_chapters(int infile, int outfile) |
|
1650 |
{ |
|
1651 |
AVFormatContext *is = input_files[infile]; |
|
1652 |
AVFormatContext *os = output_files[outfile]; |
|
1653 |
int i; |
|
1654 |
|
|
1655 |
for (i = 0; i < is->nb_chapters; i++) { |
|
1656 |
AVChapter *in_ch = is->chapters[i], *out_ch; |
|
1657 |
AVMetadataTag *t = NULL; |
|
1658 |
int64_t ts_off = av_rescale_q(start_time - input_files_ts_offset[infile], |
|
1659 |
AV_TIME_BASE_Q, in_ch->time_base); |
|
1660 |
int64_t rt = (recording_time == INT64_MAX) ? INT64_MAX : |
|
1661 |
av_rescale_q(recording_time, AV_TIME_BASE_Q, in_ch->time_base); |
|
1662 |
|
|
1663 |
|
|
1664 |
if (in_ch->end < ts_off) |
|
1665 |
continue; |
|
1666 |
if (rt != INT64_MAX && in_ch->start > rt + ts_off) |
|
1667 |
break; |
|
1668 |
|
|
1669 |
out_ch = av_mallocz(sizeof(AVChapter)); |
|
1670 |
if (!out_ch) |
|
1671 |
return AVERROR(ENOMEM); |
|
1672 |
|
|
1673 |
out_ch->id = in_ch->id; |
|
1674 |
out_ch->time_base = in_ch->time_base; |
|
1675 |
out_ch->start = FFMAX(0, in_ch->start - ts_off); |
|
1676 |
out_ch->end = FFMIN(rt, in_ch->end - ts_off); |
|
1677 |
|
|
1678 |
while ((t = av_metadata_get(in_ch->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) |
|
1679 |
av_metadata_set2(&out_ch->metadata, t->key, t->value, 0); |
|
1680 |
|
|
1681 |
os->nb_chapters++; |
|
1682 |
os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters); |
|
1683 |
if (!os->chapters) |
|
1684 |
return AVERROR(ENOMEM); |
|
1685 |
os->chapters[os->nb_chapters - 1] = out_ch; |
|
1686 |
} |
|
1687 |
return 0; |
|
1688 |
} |
|
1689 |
|
|
1649 | 1690 |
/* |
1650 | 1691 |
* The following code is the main loop of the file converter |
1651 | 1692 |
*/ |
... | ... | |
2134 | 2175 |
in_file->iformat->metadata_conv); |
2135 | 2176 |
} |
2136 | 2177 |
|
2178 |
/* copy chapters from the first input file that has them*/ |
|
2179 |
for (i = 0; i < nb_input_files; i++) { |
|
2180 |
if (!input_files[i]->nb_chapters) |
|
2181 |
continue; |
|
2182 |
|
|
2183 |
for (j = 0; j < nb_output_files; j++) |
|
2184 |
if ((ret = copy_chapters(i, j)) < 0) |
|
2185 |
goto dump_format; |
|
2186 |
} |
|
2187 |
|
|
2137 | 2188 |
/* open files and write file headers */ |
2138 | 2189 |
for(i=0;i<nb_output_files;i++) { |
2139 | 2190 |
os = output_files[i]; |
Also available in: Unified diff