Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] PR showing the divergence from official release branch #1

Open
wants to merge 2 commits into
base: release/7.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fftools/ffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ typedef struct OptionsContext {
SpecifierOptList hwaccel_output_formats;
SpecifierOptList autorotate;
SpecifierOptList apply_cropping;
SpecifierOptList force_cfr;

/* output options */
StreamMap *stream_maps;
Expand Down Expand Up @@ -276,6 +277,9 @@ typedef struct InputFilterOptions {
* accurate */
AVRational framerate;

/* convert input stream to CFR at this framerate before inserting additional filters */
AVRational force_cfr;

unsigned crop_top;
unsigned crop_bottom;
unsigned crop_left;
Expand Down Expand Up @@ -451,6 +455,9 @@ typedef struct InputStream {

/* framerate forced with -r */
AVRational framerate;

/* convert input stream to CFR at this framerate before inserting additional filters */
AVRational force_cfr;
#if FFMPEG_OPT_TOP
int top_field_first;
#endif
Expand Down
15 changes: 14 additions & 1 deletion fftools/ffmpeg_demux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,10 @@ int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple,
(opts->crop_top | opts->crop_bottom | opts->crop_left | opts->crop_right))
opts->flags |= IFILTER_FLAG_CROP;
}
if (ist->force_cfr.num > 0 && ist->force_cfr.den > 0) {
opts->force_cfr = ist->force_cfr;
opts->flags |= IFILTER_FLAG_CFR;
}
} else if (ist->par->codec_type == AVMEDIA_TYPE_SUBTITLE) {
/* Compute the size of the canvas for the subtitles stream.
If the subtitles codecpar has set a size, use it. Otherwise use the
Expand Down Expand Up @@ -1241,7 +1245,7 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
AVCodecParameters *par = st->codecpar;
DemuxStream *ds;
InputStream *ist;
const char *framerate = NULL, *hwaccel_device = NULL;
const char *framerate = NULL, *hwaccel_device = NULL, *forcecfr = NULL;
const char *hwaccel = NULL;
const char *apply_cropping = NULL;
const char *hwaccel_output_format = NULL;
Expand Down Expand Up @@ -1437,6 +1441,15 @@ static int ist_add(const OptionsContext *o, Demuxer *d, AVStream *st, AVDictiona
}
}

opt_match_per_stream_str(ist, &o->force_cfr, ic, st, &forcecfr);
if (forcecfr) {
ret = av_parse_video_rate(&ist->force_cfr, forcecfr);
if (ret < 0) {
av_log(ist, AV_LOG_ERROR, "Error parsing framerate %s.\n", forcecfr);
return ret;
}
}

#if FFMPEG_OPT_TOP
ist->top_field_first = -1;
opt_match_per_stream_int(ist, &o->top_field_first, ic, st, &ist->top_field_first);
Expand Down
9 changes: 9 additions & 0 deletions fftools/ffmpeg_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,15 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
ifp->displaymatrix_applied = 1;
}

if (ifp->opts.force_cfr.num > 0 && ifp->opts.force_cfr.den > 0) {
char force_cfr_buf[64];
snprintf(force_cfr_buf, sizeof(force_cfr_buf), "%d/%d",
ifp->opts.force_cfr.num, ifp->opts.force_cfr.den);
ret = insert_filter(&last_filter, &pad_idx, "fps", force_cfr_buf);
if (ret < 0)
return ret;
}

snprintf(name, sizeof(name), "trim_in_%s", ifp->opts.name);
ret = insert_trim(ifp->opts.trim_start_us, ifp->opts.trim_end_us,
&last_filter, &pad_idx, name);
Expand Down
4 changes: 4 additions & 0 deletions fftools/ffmpeg_opt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2033,5 +2033,9 @@ const OptionDef options[] = {
"set video sync method globally; deprecated, use -fps_mode", "" },
#endif

{ "force_cfr", OPT_TYPE_STRING, OPT_VIDEO | OPT_EXPERT | OPT_PERSTREAM | OPT_INPUT,
{ .off = OFFSET(force_cfr) },
"set frame rate (Hz value, fraction or abbreviation)", "force_cfr" },

{ NULL, },
};
26 changes: 26 additions & 0 deletions libavformat/mov.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef struct MOVParseTableEntry {
static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
static int mov_read_mfra(MOVContext *c, AVIOContext *f);
static void mov_free_stream_context(AVFormatContext *s, AVStream *st);
static int mov_switch_root(AVFormatContext *s, int64_t target, int index);
static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size,
int count, int duration);

Expand Down Expand Up @@ -1653,6 +1654,31 @@ static int64_t get_frag_time(AVFormatContext *s, AVStream *dst_st,
return frag_stream_info->sidx_pts;
}


// Check if the requested stream is present in the fragment
int exists = 0;
for (i = 0; i < frag_index->item[index].nb_stream_info; i++) {
if (dst_st->id != frag_index->item[index].stream_info[i].id) {
continue;
}

if ( get_stream_info_time(&frag_index->item[index].stream_info[i]) != AV_NOPTS_VALUE) {
exists = 1;
break;
}
if ( mov_switch_root(s,-1,index) < 0)
return AV_NOPTS_VALUE;

if ( get_stream_info_time(&frag_index->item[index].stream_info[i]) != AV_NOPTS_VALUE) {
exists = 1;
break;
}
}

if (!exists)
return AV_NOPTS_VALUE;


for (i = 0; i < frag_index->item[index].nb_stream_info; i++) {
AVStream *frag_stream = NULL;
frag_stream_info = &frag_index->item[index].stream_info[i];
Expand Down