diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 30b594fd97..3aab302c27 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -390,7 +390,7 @@ OutputStream *ost_iter(OutputStream *prev)
 
 InputStream *ist_iter(InputStream *prev)
 {
-    int if_idx  = prev ? prev->file_index : 0;
+    int if_idx  = prev ? prev->file->index : 0;
     int ist_idx = prev ? prev->index + 1  : 0;
 
     for (; if_idx < nb_input_files; if_idx++) {
@@ -752,7 +752,7 @@ static void print_stream_maps(void)
         for (int j = 0; j < ist->nb_filters; j++) {
             if (!filtergraph_is_simple(ist->filters[j]->graph)) {
                 av_log(NULL, AV_LOG_INFO, "  Stream #%d:%d (%s) -> %s",
-                       ist->file_index, ist->index, ist->dec ? ist->dec->name : "?",
+                       ist->file->index, ist->index, ist->dec ? ist->dec->name : "?",
                        ist->filters[j]->name);
                 if (nb_filtergraphs > 1)
                     av_log(NULL, AV_LOG_INFO, " (graph %d)", ist->filters[j]->graph->index);
@@ -781,7 +781,7 @@ static void print_stream_maps(void)
         }
 
         av_log(NULL, AV_LOG_INFO, "  Stream #%d:%d -> #%d:%d",
-               ost->ist->file_index,
+               ost->ist->file->index,
                ost->ist->index,
                ost->file_index,
                ost->index);
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 69bd23f576..d7b6e689fc 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -333,7 +333,9 @@ typedef struct Decoder Decoder;
 typedef struct InputStream {
     const AVClass *class;
 
-    int file_index;
+    /* parent source */
+    struct InputFile *file;
+
     int index;
 
     AVStream *st;
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index 5dde82a276..219bcf39e4 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -193,7 +193,7 @@ static void audio_ts_process(void *logctx, Decoder *d, AVFrame *frame)
 static int64_t video_duration_estimate(const InputStream *ist, const AVFrame *frame)
 {
     const Decoder         *d = ist->decoder;
-    const InputFile   *ifile = input_files[ist->file_index];
+    const InputFile   *ifile = ist->file;
     int64_t codec_duration = 0;
 
     // XXX lavf currently makes up frame durations when they are not provided by
@@ -455,7 +455,7 @@ static int transcode_subtitles(InputStream *ist, const AVPacket *pkt,
 
 static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
 {
-    const InputFile *ifile = input_files[ist->file_index];
+    const InputFile *ifile = ist->file;
     Decoder *d = ist->decoder;
     AVCodecContext *dec = ist->dec_ctx;
     const char *type_desc = av_get_media_type_string(dec->codec_type);
@@ -504,7 +504,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
         update_benchmark(NULL);
         ret = avcodec_receive_frame(dec, frame);
         update_benchmark("decode_%s %d.%d", type_desc,
-                         ist->file_index, ist->index);
+                         ifile->index, ist->index);
 
         if (ret == AVERROR(EAGAIN)) {
             av_assert0(pkt); // should never happen during flushing
@@ -550,7 +550,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
             ret = video_frame_process(ist, frame);
             if (ret < 0) {
                 av_log(NULL, AV_LOG_FATAL, "Error while processing the decoded "
-                       "data for stream #%d:%d\n", ist->file_index, ist->index);
+                       "data for stream #%d:%d\n", ifile->index, ist->index);
                 return ret;
             }
         }
@@ -568,7 +568,7 @@ static int packet_decode(InputStream *ist, AVPacket *pkt, AVFrame *frame)
 static void dec_thread_set_name(const InputStream *ist)
 {
     char name[16];
-    snprintf(name, sizeof(name), "dec%d:%d:%s", ist->file_index, ist->index,
+    snprintf(name, sizeof(name), "dec%d:%d:%s", ist->file->index, ist->index,
              ist->dec_ctx->codec->name);
     ff_thread_setname(name);
 }
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 91cd7a1125..61fb856106 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -463,8 +463,7 @@ static int input_packet_process(Demuxer *d, AVPacket *pkt, unsigned *send_flags)
                av_ts2str(pkt->pts), av_ts2timestr(pkt->pts, &pkt->time_base),
                av_ts2str(pkt->dts), av_ts2timestr(pkt->dts, &pkt->time_base),
                av_ts2str(pkt->duration), av_ts2timestr(pkt->duration, &pkt->time_base),
-               av_ts2str(input_files[ist->file_index]->ts_offset),
-               av_ts2timestr(input_files[ist->file_index]->ts_offset, &AV_TIME_BASE_Q));
+               av_ts2str(f->ts_offset),  av_ts2timestr(f->ts_offset, &AV_TIME_BASE_Q));
     }
 
     pkt->stream_index = ds->sch_idx_stream;
@@ -761,7 +760,7 @@ void ifile_close(InputFile **pf)
 
 static int ist_use(InputStream *ist, int decoding_needed)
 {
-    Demuxer      *d = demuxer_from_ifile(input_files[ist->file_index]);
+    Demuxer      *d = demuxer_from_ifile(ist->file);
     DemuxStream *ds = ds_from_ist(ist);
     int ret;
 
@@ -830,7 +829,7 @@ int ist_output_add(InputStream *ist, OutputStream *ost)
 
 int ist_filter_add(InputStream *ist, InputFilter *ifilter, int is_simple)
 {
-    Demuxer      *d = demuxer_from_ifile(input_files[ist->file_index]);
+    Demuxer      *d = demuxer_from_ifile(ist->file);
     DemuxStream *ds = ds_from_ist(ist);
     int ret;
 
@@ -994,7 +993,7 @@ static DemuxStream *demux_stream_alloc(Demuxer *d, AVStream *st)
     ds->sch_idx_dec    = -1;
 
     ds->ist.st         = st;
-    ds->ist.file_index = f->index;
+    ds->ist.file       = f;
     ds->ist.index      = st->index;
     ds->ist.class      = &input_stream_class;
 
diff --git a/fftools/ffmpeg_filter.c b/fftools/ffmpeg_filter.c
index 3b0d457cc2..40608d9e44 100644
--- a/fftools/ffmpeg_filter.c
+++ b/fftools/ffmpeg_filter.c
@@ -1456,7 +1456,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
     const AVFilter *buffer_filt = avfilter_get_by_name("buffer");
     const AVPixFmtDescriptor *desc;
     InputStream *ist = ifp->ist;
-    InputFile     *f = input_files[ist->file_index];
+    InputFile     *f = ist->file;
     AVRational fr = ist->framerate;
     AVRational sar;
     AVBPrint args;
@@ -1497,7 +1497,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
     if (fr.num && fr.den)
         av_bprintf(&args, ":frame_rate=%d/%d", fr.num, fr.den);
     snprintf(name, sizeof(name), "graph %d input from stream %d:%d", fg->index,
-             ist->file_index, ist->index);
+             f->index, ist->index);
 
 
     if ((ret = avfilter_graph_create_filter(&ifp->filter, buffer_filt, name,
@@ -1556,7 +1556,7 @@ static int configure_input_video_filter(FilterGraph *fg, AVFilterGraph *graph,
     }
 
     snprintf(name, sizeof(name), "trim_in_%d_%d",
-             ist->file_index, ist->index);
+             f->index, ist->index);
     if (copy_ts) {
         tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
         if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
@@ -1584,7 +1584,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
     AVFilterContext *last_filter;
     const AVFilter *abuffer_filt = avfilter_get_by_name("abuffer");
     InputStream *ist = ifp->ist;
-    InputFile     *f = input_files[ist->file_index];
+    InputFile     *f = ist->file;
     AVBPrint args;
     char name[255];
     int ret, pad_idx = 0;
@@ -1609,7 +1609,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
     } else
         av_bprintf(&args, ":channels=%d", ifp->ch_layout.nb_channels);
     snprintf(name, sizeof(name), "graph_%d_in_%d_%d", fg->index,
-             ist->file_index, ist->index);
+             f->index, ist->index);
 
     if ((ret = avfilter_graph_create_filter(&ifp->filter, abuffer_filt,
                                             name, args.str, NULL,
@@ -1618,7 +1618,7 @@ static int configure_input_audio_filter(FilterGraph *fg, AVFilterGraph *graph,
     last_filter = ifp->filter;
 
     snprintf(name, sizeof(name), "trim for input stream %d:%d",
-             ist->file_index, ist->index);
+             f->index, ist->index);
     if (copy_ts) {
         tsoffset = f->start_time == AV_NOPTS_VALUE ? 0 : f->start_time;
         if (!start_at_zero && f->ctx->start_time != AV_NOPTS_VALUE)
@@ -2569,7 +2569,7 @@ static int send_eof(FilterGraphThread *fgt, InputFilter *ifilter,
         if (ifp->format < 0) {
             av_log(NULL, AV_LOG_ERROR,
                    "Cannot determine format of input stream %d:%d after EOF\n",
-                   ifp->ist->file_index, ifp->ist->index);
+                   ifp->ist->file->index, ifp->ist->index);
             return AVERROR_INVALIDDATA;
         }
     }
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 6459296ab0..64c173e006 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -819,7 +819,7 @@ static int new_stream_video(Muxer *mux, const OptionsContext *o,
             }
 
             if (ost->ist && ost->vsync_method == VSYNC_CFR) {
-                const InputFile *ifile = input_files[ost->ist->file_index];
+                const InputFile *ifile = ost->ist->file;
 
                 if (ifile->nb_streams == 1 && ifile->input_ts_offset == 0)
                     ost->vsync_method = VSYNC_VSCFR;
@@ -907,7 +907,7 @@ static int new_stream_audio(Muxer *mux, const OptionsContext *o,
                     ist = ost->ist;
                 }
 
-                if (!ist || (ist->file_index == map->file_idx && ist->index == map->stream_idx)) {
+                if (!ist || (ist->file->index == map->file_idx && ist->index == map->stream_idx)) {
                     ret = av_reallocp_array(&ost->audio_channels_map,
                                             ost->audio_channels_mapped + 1,
                                             sizeof(*ost->audio_channels_map));
@@ -970,7 +970,7 @@ static int streamcopy_init(const Muxer *mux, OutputStream *ost)
     MuxStream           *ms         = ms_from_ost(ost);
 
     const InputStream   *ist        = ost->ist;
-    const InputFile     *ifile      = input_files[ist->file_index];
+    const InputFile     *ifile      = ist->file;
 
     AVCodecParameters   *par        = ost->par_in;
     uint32_t             codec_tag  = par->codec_tag;
@@ -1208,7 +1208,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
            av_get_media_type_string(type));
     if (ist)
         av_log(ost, AV_LOG_VERBOSE, "input stream %d:%d",
-               ist->file_index, ist->index);
+               ist->file->index, ist->index);
     else if (ofilter)
         av_log(ost, AV_LOG_VERBOSE, "complex filtergraph %d:[%s]\n",
                ofilter->graph->index, ofilter->name);
@@ -1480,7 +1480,7 @@ static int ost_add(Muxer *mux, const OptionsContext *o, enum AVMediaType type,
             if (ret < 0)
                 return ret;
         } else {
-            ret = sch_connect(mux->sch, SCH_DSTREAM(ost->ist->file_index, sched_idx),
+            ret = sch_connect(mux->sch, SCH_DSTREAM(ost->ist->file->index, sched_idx),
                                         SCH_MSTREAM(ost->file_index, ms->sch_idx));
             if (ret < 0)
                 return ret;
