| 1591 | } |
| 1592 | |
| 1593 | static int read_interval_packets(AVTextFormatContext *tfc, InputFile *ifile, |
| 1594 | const ReadInterval *interval, int64_t *cur_ts) |
| 1595 | { |
| 1596 | AVFormatContext *fmt_ctx = ifile->fmt_ctx; |
| 1597 | AVPacket *pkt = NULL; |
| 1598 | AVFrame *frame = NULL; |
| 1599 | int ret = 0, i = 0, frame_count = 0; |
| 1600 | int64_t start = -INT64_MAX, end = interval->end; |
| 1601 | int has_start = 0, has_end = interval->has_end && !interval->end_is_offset; |
| 1602 | |
| 1603 | av_log(NULL, AV_LOG_VERBOSE, "Processing read interval "); |
| 1604 | log_read_interval(interval, NULL, AV_LOG_VERBOSE); |
| 1605 | |
| 1606 | if (interval->has_start) { |
| 1607 | int64_t target; |
| 1608 | if (interval->start_is_offset) { |
| 1609 | if (*cur_ts == AV_NOPTS_VALUE) { |
| 1610 | av_log(NULL, AV_LOG_ERROR, |
| 1611 | "Could not seek to relative position since current " |
| 1612 | "timestamp is not defined\n"); |
| 1613 | ret = AVERROR(EINVAL); |
| 1614 | goto end; |
| 1615 | } |
| 1616 | target = *cur_ts + interval->start; |
| 1617 | } else { |
| 1618 | target = interval->start; |
| 1619 | } |
| 1620 | |
| 1621 | av_log(NULL, AV_LOG_VERBOSE, "Seeking to read interval start point %s\n", |
| 1622 | av_ts2timestr(target, &AV_TIME_BASE_Q)); |
| 1623 | if ((ret = avformat_seek_file(fmt_ctx, -1, -INT64_MAX, target, INT64_MAX, 0)) < 0) { |
| 1624 | av_log(NULL, AV_LOG_ERROR, "Could not seek to position %"PRId64": %s\n", |
| 1625 | interval->start, av_err2str(ret)); |
| 1626 | goto end; |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | frame = av_frame_alloc(); |
| 1631 | if (!frame) { |
| 1632 | ret = AVERROR(ENOMEM); |
| 1633 | goto end; |
| 1634 | } |
| 1635 | pkt = av_packet_alloc(); |
| 1636 | if (!pkt) { |
| 1637 | ret = AVERROR(ENOMEM); |
| 1638 | goto end; |
| 1639 | } |
| 1640 | while (!av_read_frame(fmt_ctx, pkt)) { |
| 1641 | if (fmt_ctx->nb_streams > nb_streams) { |
| 1642 | REALLOCZ_ARRAY_STREAM(nb_streams_frames, nb_streams, fmt_ctx->nb_streams); |
| 1643 | REALLOCZ_ARRAY_STREAM(nb_streams_packets, nb_streams, fmt_ctx->nb_streams); |
| 1644 | REALLOCZ_ARRAY_STREAM(selected_streams, nb_streams, fmt_ctx->nb_streams); |
| 1645 | REALLOCZ_ARRAY_STREAM(streams_with_closed_captions, nb_streams, fmt_ctx->nb_streams); |
| 1646 | REALLOCZ_ARRAY_STREAM(streams_with_film_grain, nb_streams, fmt_ctx->nb_streams); |
| 1647 | nb_streams = fmt_ctx->nb_streams; |
| 1648 | } |
| 1649 | if (selected_streams[pkt->stream_index]) { |
| 1650 | AVRational tb = ifile->streams[pkt->stream_index].st->time_base; |
no test coverage detected