Right now, they are arrays of structs, reallocated when new streams/files are added. This makes storing pointers to those structs harder than necessary.
Unified · Split
| @@ -264,15 +264,15 @@ typedef struct OutputFile { · 263 unmodified lines | |||
| 264 | uint64_t limit_filesize; | 264 | uint64_t limit_filesize; |
| 265 | } OutputFile; | 265 | } OutputFile; |
| 266 | 266 | ||
| 267 | static InputStream *input_streams = NULL; | 267 | static InputStream **input_streams = NULL; |
| 268 | static int nb_input_streams = 0; | 268 | static int nb_input_streams = 0; |
| 269 | static InputFile *input_files = NULL; | 269 | static InputFile **input_files = NULL; |
| 270 | static int nb_input_files = 0; | 270 | static int nb_input_files = 0; |
| 271 | 271 | ||
| 272 | static OutputStream *output_streams = NULL; | 272 | static OutputStream **output_streams = NULL; |
| 273 | static int nb_output_streams = 0; | 273 | static int nb_output_streams = 0; |
| 274 | static OutputFile *output_files = NULL; | 274 | static OutputFile **output_files = NULL; |
| 275 | static int nb_output_files = 0; | 275 | static int nb_output_files = 0; |
| 276 | 276 | ||
| 277 | typedef struct OptionsContext { | 277 | typedef struct OptionsContext { |
| 278 | /* input/output options */ | 278 | /* input/output options */ |
| @@ -663,38 +663,42 @@ void exit_program(int ret) · 384 unmodified lines | |||
| 663 | 663 | ||
| 664 | /* close files */ | 664 | /* close files */ |
| 665 | for (i = 0; i < nb_output_files; i++) { | 665 | for (i = 0; i < nb_output_files; i++) { |
| 666 | AVFormatContext *s = output_files[i].ctx; | 666 | AVFormatContext *s = output_files[i]->ctx; |
| 667 | if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) | 667 | if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb) |
| 668 | avio_close(s->pb); | 668 | avio_close(s->pb); |
| 669 | avformat_free_context(s); | 669 | avformat_free_context(s); |
| 670 | av_dict_free(&output_files[i].opts); | 670 | av_dict_free(&output_files[i]->opts); |
| 671 | av_freep(&output_files[i]); | ||
| 671 | } | 672 | } |
| 672 | for (i = 0; i < nb_output_streams; i++) { | 673 | for (i = 0; i < nb_output_streams; i++) { |
| 673 | AVBitStreamFilterContext *bsfc = output_streams[i].bitstream_filters; | 674 | AVBitStreamFilterContext *bsfc = output_streams[i]->bitstream_filters; |
| 674 | while (bsfc) { | 675 | while (bsfc) { |
| 675 | AVBitStreamFilterContext *next = bsfc->next; | 676 | AVBitStreamFilterContext *next = bsfc->next; |
| 676 | av_bitstream_filter_close(bsfc); | 677 | av_bitstream_filter_close(bsfc); |
| 677 | bsfc = next; | 678 | bsfc = next; |
| 678 | } | 679 | } |
| 679 | output_streams[i].bitstream_filters = NULL; | 680 | output_streams[i]->bitstream_filters = NULL; |
| 680 | 681 | ||
| 681 | if (output_streams[i].output_frame) { | 682 | if (output_streams[i]->output_frame) { |
| 682 | AVFrame *frame = output_streams[i].output_frame; | 683 | AVFrame *frame = output_streams[i]->output_frame; |
| 683 | if (frame->extended_data != frame->data) | 684 | if (frame->extended_data != frame->data) |
| 684 | av_freep(&frame->extended_data); | 685 | av_freep(&frame->extended_data); |
| 685 | av_freep(&frame); | 686 | av_freep(&frame); |
| 686 | } | 687 | } |
| 687 | 688 | ||
| 688 | av_freep(&output_streams[i].avfilter); | 689 | av_freep(&output_streams[i]->avfilter); |
| 690 | av_freep(&output_streams[i]); | ||
| 689 | } | 691 | } |
| 690 | for (i = 0; i < nb_input_files; i++) { | 692 | for (i = 0; i < nb_input_files; i++) { |
| 691 | avformat_close_input(&input_files[i].ctx); | 693 | avformat_close_input(&input_files[i]->ctx); |
| 694 | av_freep(&input_files[i]); | ||
| 692 | } | 695 | } |
| 693 | for (i = 0; i < nb_input_streams; i++) { | 696 | for (i = 0; i < nb_input_streams; i++) { |
| 694 | av_freep(&input_streams[i].decoded_frame); | 697 | av_freep(&input_streams[i]->decoded_frame); |
| 695 | av_freep(&input_streams[i].filtered_frame); | 698 | av_freep(&input_streams[i]->filtered_frame); |
| 696 | av_dict_free(&input_streams[i].opts); | 699 | av_dict_free(&input_streams[i]->opts); |
| 697 | free_buffer_pool(&input_streams[i]); | 700 | free_buffer_pool(input_streams[i]); |
| 701 | av_freep(&input_streams[i]); | ||
| 698 | } | 702 | } |
| 699 | 703 | ||
| 700 | if (vstats_file) | 704 | if (vstats_file) |
| @@ -860,7 +864,7 @@ static void choose_pixel_fmt(AVStream *st, AVCodec *codec) · 159 unmodified lines | |||
| 860 | static double | 864 | static double |
| 861 | get_sync_ipts(const OutputStream *ost, int64_t pts) | 865 | get_sync_ipts(const OutputStream *ost, int64_t pts) |
| 862 | { | 866 | { |
| 863 | OutputFile *of = &output_files[ost->file_index]; | 867 | OutputFile *of = output_files[ost->file_index]; |
| 864 | return (double)(pts - of->start_time) / AV_TIME_BASE; | 868 | return (double)(pts - of->start_time) / AV_TIME_BASE; |
| 865 | } | 869 | } |
| 866 | 870 | ||
| @@ -917,7 +921,7 @@ static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) · 50 unmodified lines | |||
| 917 | 921 | ||
| 918 | static int check_recording_time(OutputStream *ost) | 922 | static int check_recording_time(OutputStream *ost) |
| 919 | { | 923 | { |
| 920 | OutputFile *of = &output_files[ost->file_index]; | 924 | OutputFile *of = output_files[ost->file_index]; |
| 921 | 925 | ||
| 922 | if (of->recording_time != INT64_MAX && | 926 | if (of->recording_time != INT64_MAX && |
| 923 | av_compare_ts(ost->sync_opts - ost->first_pts, ost->st->codec->time_base, of->recording_time, | 927 | av_compare_ts(ost->sync_opts - ost->first_pts, ost->st->codec->time_base, of->recording_time, |
| @@ -1514,7 +1518,7 @@ static void print_report(int is_last_report, int64_t timer_start) · 590 unmodified lines | |||
| 1514 | } | 1518 | } |
| 1515 | 1519 | ||
| 1516 | 1520 | ||
| 1517 | oc = output_files[0].ctx; | 1521 | oc = output_files[0]->ctx; |
| 1518 | 1522 | ||
| 1519 | total_size = avio_size(oc->pb); | 1523 | total_size = avio_size(oc->pb); |
| 1520 | if (total_size < 0) // FIXME improve avio_size() so it works with non seekable output too | 1524 | if (total_size < 0) // FIXME improve avio_size() so it works with non seekable output too |
| @@ -1525,7 +1529,7 @@ static void print_report(int is_last_report, int64_t timer_start) · 4 unmodified lines | |||
| 1525 | vid = 0; | 1529 | vid = 0; |
| 1526 | for (i = 0; i < nb_output_streams; i++) { | 1530 | for (i = 0; i < nb_output_streams; i++) { |
| 1527 | float q = -1; | 1531 | float q = -1; |
| 1528 | ost = &output_streams[i]; | 1532 | ost = output_streams[i]; |
| 1529 | enc = ost->st->codec; | 1533 | enc = ost->st->codec; |
| 1530 | if (!ost->stream_copy && enc->coded_frame) | 1534 | if (!ost->stream_copy && enc->coded_frame) |
| 1531 | q = enc->coded_frame->quality / (float)FF_QP2LAMBDA; | 1535 | q = enc->coded_frame->quality / (float)FF_QP2LAMBDA; |
| @@ -1611,9 +1615,9 @@ static void flush_encoders(void) · 79 unmodified lines | |||
| 1611 | int i, ret; | 1615 | int i, ret; |
| 1612 | 1616 | ||
| 1613 | for (i = 0; i < nb_output_streams; i++) { | 1617 | for (i = 0; i < nb_output_streams; i++) { |
| 1614 | OutputStream *ost = &output_streams[i]; | 1618 | OutputStream *ost = output_streams[i]; |
| 1615 | AVCodecContext *enc = ost->st->codec; | 1619 | AVCodecContext *enc = ost->st->codec; |
| 1616 | AVFormatContext *os = output_files[ost->file_index].ctx; | 1620 | AVFormatContext *os = output_files[ost->file_index]->ctx; |
| 1617 | int stop_encoding = 0; | 1621 | int stop_encoding = 0; |
| 1618 | 1622 | ||
| 1619 | if (!ost->encoding_needed) | 1623 | if (!ost->encoding_needed) |
| @@ -1692,8 +1696,8 @@ static void flush_encoders(void) · 72 unmodified lines | |||
| 1692 | */ | 1696 | */ |
| 1693 | static int check_output_constraints(InputStream *ist, OutputStream *ost) | 1697 | static int check_output_constraints(InputStream *ist, OutputStream *ost) |
| 1694 | { | 1698 | { |
| 1695 | OutputFile *of = &output_files[ost->file_index]; | 1699 | OutputFile *of = output_files[ost->file_index]; |
| 1696 | int ist_index = ist - input_streams; | 1700 | int ist_index = input_files[ist->file_index]->ist_index + ist->st->index; |
| 1697 | 1701 | ||
| 1698 | if (ost->source_index != ist_index) | 1702 | if (ost->source_index != ist_index) |
| 1699 | return 0; | 1703 | return 0; |
| @@ -1706,7 +1710,7 @@ static int check_output_constraints(InputStream *ist, OutputStream *ost) · 6 unmodified lines | |||
| 1706 | 1710 | ||
| 1707 | static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt) | 1711 | static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt) |
| 1708 | { | 1712 | { |
| 1709 | OutputFile *of = &output_files[ost->file_index]; | 1713 | OutputFile *of = output_files[ost->file_index]; |
| 1710 | int64_t ost_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base); | 1714 | int64_t ost_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base); |
| 1711 | AVPacket opkt; | 1715 | AVPacket opkt; |
| 1712 | 1716 | ||
| @@ -1764,7 +1768,7 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p · 51 unmodified lines | |||
| 1764 | 1768 | ||
| 1765 | static void rate_emu_sleep(InputStream *ist) | 1769 | static void rate_emu_sleep(InputStream *ist) |
| 1766 | { | 1770 | { |
| 1767 | if (input_files[ist->file_index].rate_emu) { | 1771 | if (input_files[ist->file_index]->rate_emu) { |
| 1768 | int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE); | 1772 | int64_t pts = av_rescale(ist->last_dts, 1000000, AV_TIME_BASE); |
| 1769 | int64_t now = av_gettime() - ist->start; | 1773 | int64_t now = av_gettime() - ist->start; |
| 1770 | if (pts > now) | 1774 | if (pts > now) |
| @@ -1866,11 +1870,11 @@ static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output) · 95 unmodified lines | |||
| 1866 | rate_emu_sleep(ist); | 1870 | rate_emu_sleep(ist); |
| 1867 | 1871 | ||
| 1868 | for (i = 0; i < nb_output_streams; i++) { | 1872 | for (i = 0; i < nb_output_streams; i++) { |
| 1869 | OutputStream *ost = &output_streams[i]; | 1873 | OutputStream *ost = output_streams[i]; |
| 1870 | 1874 | ||
| 1871 | if (!check_output_constraints(ist, ost) || !ost->encoding_needed) | 1875 | if (!check_output_constraints(ist, ost) || !ost->encoding_needed) |
| 1872 | continue; | 1876 | continue; |
| 1873 | do_audio_out(output_files[ost->file_index].ctx, ost, ist, decoded_frame); | 1877 | do_audio_out(output_files[ost->file_index]->ctx, ost, ist, decoded_frame); |
| 1874 | } | 1878 | } |
| 1875 | 1879 | ||
| 1876 | return ret; | 1880 | return ret; |
| @@ -1914,7 +1918,7 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int · 37 unmodified lines | |||
| 1914 | decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; | 1918 | decoded_frame->sample_aspect_ratio = ist->st->sample_aspect_ratio; |
| 1915 | 1919 | ||
| 1916 | for (i = 0; i < nb_output_streams; i++) { | 1920 | for (i = 0; i < nb_output_streams; i++) { |
| 1917 | OutputStream *ost = &output_streams[i]; | 1921 | OutputStream *ost = output_streams[i]; |
| 1918 | int frame_size, resample_changed; | 1922 | int frame_size, resample_changed; |
| 1919 | 1923 | ||
| 1920 | if (!check_output_constraints(ist, ost) || !ost->encoding_needed) | 1924 | if (!check_output_constraints(ist, ost) || !ost->encoding_needed) |
| @@ -1978,10 +1982,10 @@ static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int · 57 unmodified lines | |||
| 1978 | if (!ost->frame_aspect_ratio) | 1982 | if (!ost->frame_aspect_ratio) |
| 1979 | ost->st->codec->sample_aspect_ratio = picref->video->pixel_aspect; | 1983 | ost->st->codec->sample_aspect_ratio = picref->video->pixel_aspect; |
| 1980 | 1984 | ||
| 1981 | do_video_out(output_files[ost->file_index].ctx, ost, filtered_frame, &frame_size, | 1985 | do_video_out(output_files[ost->file_index]->ctx, ost, filtered_frame, &frame_size, |
| 1982 | same_quant ? quality : ost->st->codec->global_quality); | 1986 | same_quant ? quality : ost->st->codec->global_quality); |
| 1983 | if (vstats_filename && frame_size) | 1987 | if (vstats_filename && frame_size) |
| 1984 | do_video_stats(output_files[ost->file_index].ctx, ost, frame_size); | 1988 | do_video_stats(output_files[ost->file_index]->ctx, ost, frame_size); |
| 1985 | frame_available = ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]); | 1989 | frame_available = ost->output_video_filter && avfilter_poll_frame(ost->output_video_filter->inputs[0]); |
| 1986 | avfilter_unref_buffer(picref); | 1990 | avfilter_unref_buffer(picref); |
| 1987 | } | 1991 | } |
| @@ -2005,12 +2009,12 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) · 17 unmodified lines | |||
| 2005 | rate_emu_sleep(ist); | 2009 | rate_emu_sleep(ist); |
| 2006 | 2010 | ||
| 2007 | for (i = 0; i < nb_output_streams; i++) { | 2011 | for (i = 0; i < nb_output_streams; i++) { |
| 2008 | OutputStream *ost = &output_streams[i]; | 2012 | OutputStream *ost = output_streams[i]; |
| 2009 | 2013 | ||
| 2010 | if (!check_output_constraints(ist, ost) || !ost->encoding_needed) | 2014 | if (!check_output_constraints(ist, ost) || !ost->encoding_needed) |
| 2011 | continue; | 2015 | continue; |
| 2012 | 2016 | ||
| 2013 | do_subtitle_out(output_files[ost->file_index].ctx, ost, ist, &subtitle, pkt->pts); | 2017 | do_subtitle_out(output_files[ost->file_index]->ctx, ost, ist, &subtitle, pkt->pts); |
| 2014 | } | 2018 | } |
| 2015 | 2019 | ||
| 2016 | avsubtitle_free(&subtitle); | 2020 | avsubtitle_free(&subtitle); |
| @@ -2113,7 +2117,7 @@ static int output_packet(InputStream *ist, const AVPacket *pkt) · 96 unmodified lines | |||
| 2113 | } | 2117 | } |
| 2114 | } | 2118 | } |
| 2115 | for (i = 0; pkt && i < nb_output_streams; i++) { | 2119 | for (i = 0; pkt && i < nb_output_streams; i++) { |
| 2116 | OutputStream *ost = &output_streams[i]; | 2120 | OutputStream *ost = output_streams[i]; |
| 2117 | 2121 | ||
| 2118 | if (!check_output_constraints(ist, ost) || ost->encoding_needed) | 2122 | if (!check_output_constraints(ist, ost) || ost->encoding_needed) |
| 2119 | continue; | 2123 | continue; |
| @@ -2133,7 +2137,7 @@ static void print_sdp(void) · 13 unmodified lines | |||
| 2133 | if (!avc) | 2137 | if (!avc) |
| 2134 | exit_program(1); | 2138 | exit_program(1); |
| 2135 | for (i = 0; i < nb_output_files; i++) | 2139 | for (i = 0; i < nb_output_files; i++) |
| 2136 | avc[i] = output_files[i].ctx; | 2140 | avc[i] = output_files[i]->ctx; |
| 2137 | 2141 | ||
| 2138 | av_sdp_create(avc, nb_output_files, sdp, sizeof(sdp)); | 2142 | av_sdp_create(avc, nb_output_files, sdp, sizeof(sdp)); |
| 2139 | printf("SDP:\n%s\n", sdp); | 2143 | printf("SDP:\n%s\n", sdp); |
| @@ -2189,7 +2193,7 @@ static void get_default_channel_layouts(OutputStream *ost, InputStream *ist) · 49 unmodified lines | |||
| 2189 | static int init_input_stream(int ist_index, char *error, int error_len) | 2193 | static int init_input_stream(int ist_index, char *error, int error_len) |
| 2190 | { | 2194 | { |
| 2191 | int i; | 2195 | int i; |
| 2192 | InputStream *ist = &input_streams[ist_index]; | 2196 | InputStream *ist = input_streams[ist_index]; |
| 2193 | if (ist->decoding_needed) { | 2197 | if (ist->decoding_needed) { |
| 2194 | AVCodec *codec = ist->dec; | 2198 | AVCodec *codec = ist->dec; |
| 2195 | if (!codec) { | 2199 | if (!codec) { |
| @@ -2201,7 +2205,7 @@ static int init_input_stream(int ist_index, char *error, int error_len) · 5 unmodified lines | |||
| 2201 | /* update requested sample format for the decoder based on the | 2205 | /* update requested sample format for the decoder based on the |
| 2202 | corresponding encoder sample format */ | 2206 | corresponding encoder sample format */ |
| 2203 | for (i = 0; i < nb_output_streams; i++) { | 2207 | for (i = 0; i < nb_output_streams; i++) { |
| 2204 | OutputStream *ost = &output_streams[i]; | 2208 | OutputStream *ost = output_streams[i]; |
| 2205 | if (ost->source_index == ist_index) { | 2209 | if (ost->source_index == ist_index) { |
| 2206 | update_sample_fmt(ist->st->codec, codec, ost->st->codec); | 2210 | update_sample_fmt(ist->st->codec, codec, ost->st->codec); |
| 2207 | break; | 2211 | break; |
| @@ -2226,7 +2230,7 @@ static int init_input_stream(int ist_index, char *error, int error_len) · 18 unmodified lines | |||
| 2226 | 2230 | ||
| 2227 | if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { | 2231 | if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { |
| 2228 | for (i = 0; i < nb_output_streams; i++) { | 2232 | for (i = 0; i < nb_output_streams; i++) { |
| 2229 | OutputStream *ost = &output_streams[i]; | 2233 | OutputStream *ost = output_streams[i]; |
| 2230 | if (ost->source_index == ist_index) { | 2234 | if (ost->source_index == ist_index) { |
| 2231 | if (!ist->st->codec->channel_layout || !ost->st->codec->channel_layout) | 2235 | if (!ist->st->codec->channel_layout || !ost->st->codec->channel_layout) |
| 2232 | get_default_channel_layouts(ost, ist); | 2236 | get_default_channel_layouts(ost, ist); |
| @@ -2256,15 +2260,15 @@ static int transcode_init(void) · 23 unmodified lines | |||
| 2256 | 2260 | ||
| 2257 | /* init framerate emulation */ | 2261 | /* init framerate emulation */ |
| 2258 | for (i = 0; i < nb_input_files; i++) { | 2262 | for (i = 0; i < nb_input_files; i++) { |
| 2259 | InputFile *ifile = &input_files[i]; | 2263 | InputFile *ifile = input_files[i]; |
| 2260 | if (ifile->rate_emu) | 2264 | if (ifile->rate_emu) |
| 2261 | for (j = 0; j < ifile->nb_streams; j++) | 2265 | for (j = 0; j < ifile->nb_streams; j++) |
| 2262 | input_streams[j + ifile->ist_index].start = av_gettime(); | 2266 | input_streams[j + ifile->ist_index]->start = av_gettime(); |
| 2263 | } | 2267 | } |
| 2264 | 2268 | ||
| 2265 | /* output stream init */ | 2269 | /* output stream init */ |
| 2266 | for (i = 0; i < nb_output_files; i++) { | 2270 | for (i = 0; i < nb_output_files; i++) { |
| 2267 | oc = output_files[i].ctx; | 2271 | oc = output_files[i]->ctx; |
| 2268 | if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { | 2272 | if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { |
| 2269 | av_dump_format(oc, i, oc->filename, 1); | 2273 | av_dump_format(oc, i, oc->filename, 1); |
| 2270 | av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i); | 2274 | av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i); |
| @@ -2274,9 +2278,9 @@ static int transcode_init(void) · 3 unmodified lines | |||
| 2274 | 2278 | ||
| 2275 | /* for each output stream, we compute the right encoding parameters */ | 2279 | /* for each output stream, we compute the right encoding parameters */ |
| 2276 | for (i = 0; i < nb_output_streams; i++) { | 2280 | for (i = 0; i < nb_output_streams; i++) { |
| 2277 | ost = &output_streams[i]; | 2281 | ost = output_streams[i]; |
| 2278 | oc = output_files[ost->file_index].ctx; | 2282 | oc = output_files[ost->file_index]->ctx; |
| 2279 | ist = &input_streams[ost->source_index]; | 2283 | ist = input_streams[ost->source_index]; |
| 2280 | 2284 | ||
| 2281 | if (ost->attachment_filename) | 2285 | if (ost->attachment_filename) |
| 2282 | continue; | 2286 | continue; |
| @@ -2495,10 +2499,10 @@ static int transcode_init(void) · 212 unmodified lines | |||
| 2495 | 2499 | ||
| 2496 | /* open each encoder */ | 2500 | /* open each encoder */ |
| 2497 | for (i = 0; i < nb_output_streams; i++) { | 2501 | for (i = 0; i < nb_output_streams; i++) { |
| 2498 | ost = &output_streams[i]; | 2502 | ost = output_streams[i]; |
| 2499 | if (ost->encoding_needed) { | 2503 | if (ost->encoding_needed) { |
| 2500 | AVCodec *codec = ost->enc; | 2504 | AVCodec *codec = ost->enc; |
| 2501 | AVCodecContext *dec = input_streams[ost->source_index].st->codec; | 2505 | AVCodecContext *dec = input_streams[ost->source_index]->st->codec; |
| 2502 | if (!codec) { | 2506 | if (!codec) { |
| 2503 | snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d:%d", | 2507 | snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d:%d", |
| 2504 | ost->st->codec->codec_id, ost->file_index, ost->index); | 2508 | ost->st->codec->codec_id, ost->file_index, ost->index); |
| @@ -2530,7 +2534,7 @@ static int transcode_init(void) · 25 unmodified lines | |||
| 2530 | extra_size += ost->st->codec->extradata_size; | 2534 | extra_size += ost->st->codec->extradata_size; |
| 2531 | 2535 | ||
| 2532 | if (ost->st->codec->me_threshold) | 2536 | if (ost->st->codec->me_threshold) |
| 2533 | input_streams[ost->source_index].st->codec->debug |= FF_DEBUG_MV; | 2537 | input_streams[ost->source_index]->st->codec->debug |= FF_DEBUG_MV; |
| 2534 | } | 2538 | } |
| 2535 | } | 2539 | } |
| 2536 | 2540 | ||
| @@ -2541,13 +2545,13 @@ static int transcode_init(void) · 4 unmodified lines | |||
| 2541 | 2545 | ||
| 2542 | /* discard unused programs */ | 2546 | /* discard unused programs */ |
| 2543 | for (i = 0; i < nb_input_files; i++) { | 2547 | for (i = 0; i < nb_input_files; i++) { |
| 2544 | InputFile *ifile = &input_files[i]; | 2548 | InputFile *ifile = input_files[i]; |
| 2545 | for (j = 0; j < ifile->ctx->nb_programs; j++) { | 2549 | for (j = 0; j < ifile->ctx->nb_programs; j++) { |
| 2546 | AVProgram *p = ifile->ctx->programs[j]; | 2550 | AVProgram *p = ifile->ctx->programs[j]; |
| 2547 | int discard = AVDISCARD_ALL; | 2551 | int discard = AVDISCARD_ALL; |
| 2548 | 2552 | ||
| 2549 | for (k = 0; k < p->nb_stream_indexes; k++) | 2553 | for (k = 0; k < p->nb_stream_indexes; k++) |
| 2550 | if (!input_streams[ifile->ist_index + p->stream_index[k]].discard) { | 2554 | if (!input_streams[ifile->ist_index + p->stream_index[k]]->discard) { |
| 2551 | discard = AVDISCARD_DEFAULT; | 2555 | discard = AVDISCARD_DEFAULT; |
| 2552 | break; | 2556 | break; |
| 2553 | } | 2557 | } |
| @@ -2557,14 +2561,14 @@ static int transcode_init(void) · 3 unmodified lines | |||
| 2557 | 2561 | ||
| 2558 | /* open files and write file headers */ | 2562 | /* open files and write file headers */ |
| 2559 | for (i = 0; i < nb_output_files; i++) { | 2563 | for (i = 0; i < nb_output_files; i++) { |
| 2560 | oc = output_files[i].ctx; | 2564 | oc = output_files[i]->ctx; |
| 2561 | oc->interrupt_callback = int_cb; | 2565 | oc->interrupt_callback = int_cb; |
| 2562 | if (avformat_write_header(oc, &output_files[i].opts) < 0) { | 2566 | if (avformat_write_header(oc, &output_files[i]->opts) < 0) { |
| 2563 | snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); | 2567 | snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); |
| 2564 | ret = AVERROR(EINVAL); | 2568 | ret = AVERROR(EINVAL); |
| 2565 | goto dump_format; | 2569 | goto dump_format; |
| 2566 | } | 2570 | } |
| 2567 | assert_avoptions(output_files[i].opts); | 2571 | assert_avoptions(output_files[i]->opts); |
| 2568 | if (strcmp(oc->oformat->name, "rtp")) { | 2572 | if (strcmp(oc->oformat->name, "rtp")) { |
| 2569 | want_sdp = 0; | 2573 | want_sdp = 0; |
| 2570 | } | 2574 | } |
| @@ -2574,13 +2578,13 @@ static int transcode_init(void) · 3 unmodified lines | |||
| 2574 | /* dump the file output parameters - cannot be done before in case | 2578 | /* dump the file output parameters - cannot be done before in case |
| 2575 | of stream copy */ | 2579 | of stream copy */ |
| 2576 | for (i = 0; i < nb_output_files; i++) { | 2580 | for (i = 0; i < nb_output_files; i++) { |
| 2577 | av_dump_format(output_files[i].ctx, i, output_files[i].ctx->filename, 1); | 2581 | av_dump_format(output_files[i]->ctx, i, output_files[i]->ctx->filename, 1); |
| 2578 | } | 2582 | } |
| 2579 | 2583 | ||
| 2580 | /* dump the stream mapping */ | 2584 | /* dump the stream mapping */ |
| 2581 | av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); | 2585 | av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); |
| 2582 | for (i = 0; i < nb_output_streams; i++) { | 2586 | for (i = 0; i < nb_output_streams; i++) { |
| 2583 | ost = &output_streams[i]; | 2587 | ost = output_streams[i]; |
| 2584 | 2588 | ||
| 2585 | if (ost->attachment_filename) { | 2589 | if (ost->attachment_filename) { |
| 2586 | /* an attached file */ | 2590 | /* an attached file */ |
| @@ -2589,19 +2593,19 @@ static int transcode_init(void) · 2 unmodified lines | |||
| 2589 | continue; | 2593 | continue; |
| 2590 | } | 2594 | } |
| 2591 | av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d", | 2595 | av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d", |
| 2592 | input_streams[ost->source_index].file_index, | 2596 | input_streams[ost->source_index]->file_index, |
| 2593 | input_streams[ost->source_index].st->index, | 2597 | input_streams[ost->source_index]->st->index, |
| 2594 | ost->file_index, | 2598 | ost->file_index, |
| 2595 | ost->index); | 2599 | ost->index); |
| 2596 | if (ost->sync_ist != &input_streams[ost->source_index]) | 2600 | if (ost->sync_ist != input_streams[ost->source_index]) |
| 2597 | av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]", | 2601 | av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]", |
| 2598 | ost->sync_ist->file_index, | 2602 | ost->sync_ist->file_index, |
| 2599 | ost->sync_ist->st->index); | 2603 | ost->sync_ist->st->index); |
| 2600 | if (ost->stream_copy) | 2604 | if (ost->stream_copy) |
| 2601 | av_log(NULL, AV_LOG_INFO, " (copy)"); | 2605 | av_log(NULL, AV_LOG_INFO, " (copy)"); |
| 2602 | else | 2606 | else |
| 2603 | av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index].dec ? | 2607 | av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index]->dec ? |
| 2604 | input_streams[ost->source_index].dec->name : "?", | 2608 | input_streams[ost->source_index]->dec->name : "?", |
| 2605 | ost->enc ? ost->enc->name : "?"); | 2609 | ost->enc ? ost->enc->name : "?"); |
| 2606 | av_log(NULL, AV_LOG_INFO, "\n"); | 2610 | av_log(NULL, AV_LOG_INFO, "\n"); |
| 2607 | } | 2611 | } |
| @@ -2659,16 +2663,16 @@ static int transcode(void) · 51 unmodified lines | |||
| 2659 | OutputFile *of; | 2663 | OutputFile *of; |
| 2660 | int64_t ipts; | 2664 | int64_t ipts; |
| 2661 | double opts; | 2665 | double opts; |
| 2662 | ost = &output_streams[i]; | 2666 | ost = output_streams[i]; |
| 2663 | of = &output_files[ost->file_index]; | 2667 | of = output_files[ost->file_index]; |
| 2664 | os = output_files[ost->file_index].ctx; | 2668 | os = output_files[ost->file_index]->ctx; |
| 2665 | ist = &input_streams[ost->source_index]; | 2669 | ist = input_streams[ost->source_index]; |
| 2666 | if (ost->is_past_recording_time || no_packet[ist->file_index] || | 2670 | if (ost->is_past_recording_time || no_packet[ist->file_index] || |
| 2667 | (os->pb && avio_tell(os->pb) >= of->limit_filesize)) | 2671 | (os->pb && avio_tell(os->pb) >= of->limit_filesize)) |
| 2668 | continue; | 2672 | continue; |
| 2669 | opts = ost->st->pts.val * av_q2d(ost->st->time_base); | 2673 | opts = ost->st->pts.val * av_q2d(ost->st->time_base); |
| 2670 | ipts = ist->last_dts; | 2674 | ipts = ist->last_dts; |
| 2671 | if (!input_files[ist->file_index].eof_reached) { | 2675 | if (!input_files[ist->file_index]->eof_reached) { |
| 2672 | if (ipts < ipts_min) { | 2676 | if (ipts < ipts_min) { |
| 2673 | ipts_min = ipts; | 2677 | ipts_min = ipts; |
| 2674 | if (input_sync) | 2678 | if (input_sync) |
| @@ -2682,7 +2686,7 @@ static int transcode(void) · 7 unmodified lines | |||
| 2682 | if (ost->frame_number >= ost->max_frames) { | 2686 | if (ost->frame_number >= ost->max_frames) { |
| 2683 | int j; | 2687 | int j; |
| 2684 | for (j = 0; j < of->ctx->nb_streams; j++) | 2688 | for (j = 0; j < of->ctx->nb_streams; j++) |
| 2685 | output_streams[of->ost_index + j].is_past_recording_time = 1; | 2689 | output_streams[of->ost_index + j]->is_past_recording_time = 1; |
| 2686 | continue; | 2690 | continue; |
| 2687 | } | 2691 | } |
| 2688 | } | 2692 | } |
| @@ -2698,7 +2702,7 @@ static int transcode(void) · 9 unmodified lines | |||
| 2698 | } | 2702 | } |
| 2699 | 2703 | ||
| 2700 | /* read a frame from it and output it in the fifo */ | 2704 | /* read a frame from it and output it in the fifo */ |
| 2701 | is = input_files[file_index].ctx; | 2705 | is = input_files[file_index]->ctx; |
| 2702 | ret = av_read_frame(is, &pkt); | 2706 | ret = av_read_frame(is, &pkt); |
| 2703 | if (ret == AVERROR(EAGAIN)) { | 2707 | if (ret == AVERROR(EAGAIN)) { |
| 2704 | no_packet[file_index] = 1; | 2708 | no_packet[file_index] = 1; |
| @@ -2706,7 +2710,7 @@ static int transcode(void) · 1 unmodified line | |||
| 2706 | continue; | 2710 | continue; |
| 2707 | } | 2711 | } |
| 2708 | if (ret < 0) { | 2712 | if (ret < 0) { |
| 2709 | input_files[file_index].eof_reached = 1; | 2713 | input_files[file_index]->eof_reached = 1; |
| 2710 | if (opt_shortest) | 2714 | if (opt_shortest) |
| 2711 | break; | 2715 | break; |
| 2712 | else | 2716 | else |
| @@ -2722,17 +2726,17 @@ static int transcode(void) · 9 unmodified lines | |||
| 2722 | } | 2726 | } |
| 2723 | /* the following test is needed in case new streams appear | 2727 | /* the following test is needed in case new streams appear |
| 2724 | dynamically in stream : we ignore them */ | 2728 | dynamically in stream : we ignore them */ |
| 2725 | if (pkt.stream_index >= input_files[file_index].nb_streams) | 2729 | if (pkt.stream_index >= input_files[file_index]->nb_streams) |
| 2726 | goto discard_packet; | 2730 | goto discard_packet; |
| 2727 | ist_index = input_files[file_index].ist_index + pkt.stream_index; | 2731 | ist_index = input_files[file_index]->ist_index + pkt.stream_index; |
| 2728 | ist = &input_streams[ist_index]; | 2732 | ist = input_streams[ist_index]; |
| 2729 | if (ist->discard) | 2733 | if (ist->discard) |
| 2730 | goto discard_packet; | 2734 | goto discard_packet; |
| 2731 | 2735 | ||
| 2732 | if (pkt.dts != AV_NOPTS_VALUE) | 2736 | if (pkt.dts != AV_NOPTS_VALUE) |
| 2733 | pkt.dts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); | 2737 | pkt.dts += av_rescale_q(input_files[ist->file_index]->ts_offset, AV_TIME_BASE_Q, ist->st->time_base); |
| 2734 | if (pkt.pts != AV_NOPTS_VALUE) | 2738 | if (pkt.pts != AV_NOPTS_VALUE) |
| 2735 | pkt.pts += av_rescale_q(input_files[ist->file_index].ts_offset, AV_TIME_BASE_Q, ist->st->time_base); | 2739 | pkt.pts += av_rescale_q(input_files[ist->file_index]->ts_offset, AV_TIME_BASE_Q, ist->st->time_base); |
| 2736 | 2740 | ||
| 2737 | if (pkt.pts != AV_NOPTS_VALUE) | 2741 | if (pkt.pts != AV_NOPTS_VALUE) |
| 2738 | pkt.pts *= ist->ts_scale; | 2742 | pkt.pts *= ist->ts_scale; |
| @@ -2748,10 +2752,10 @@ static int transcode(void) · 9 unmodified lines | |||
| 2748 | int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); | 2752 | int64_t pkt_dts = av_rescale_q(pkt.dts, ist->st->time_base, AV_TIME_BASE_Q); |
| 2749 | int64_t delta = pkt_dts - ist->next_dts; | 2753 | int64_t delta = pkt_dts - ist->next_dts; |
| 2750 | if ((FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE || pkt_dts + 1 < ist->last_dts) && !copy_ts) { | 2754 | if ((FFABS(delta) > 1LL * dts_delta_threshold * AV_TIME_BASE || pkt_dts + 1 < ist->last_dts) && !copy_ts) { |
| 2751 | input_files[ist->file_index].ts_offset -= delta; | 2755 | input_files[ist->file_index]->ts_offset -= delta; |
| 2752 | av_log(NULL, AV_LOG_DEBUG, | 2756 | av_log(NULL, AV_LOG_DEBUG, |
| 2753 | "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", | 2757 | "timestamp discontinuity %"PRId64", new offset= %"PRId64"\n", |
| 2754 | delta, input_files[ist->file_index].ts_offset); | 2758 | delta, input_files[ist->file_index]->ts_offset); |
| 2755 | pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); | 2759 | pkt.dts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); |
| 2756 | if (pkt.pts != AV_NOPTS_VALUE) | 2760 | if (pkt.pts != AV_NOPTS_VALUE) |
| 2757 | pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); | 2761 | pkt.pts-= av_rescale_q(delta, AV_TIME_BASE_Q, ist->st->time_base); |
| @@ -2778,7 +2782,7 @@ static int transcode(void) · 20 unmodified lines | |||
| 2778 | 2782 | ||
| 2779 | /* at the end of stream, we must flush the decoder buffers */ | 2783 | /* at the end of stream, we must flush the decoder buffers */ |
| 2780 | for (i = 0; i < nb_input_streams; i++) { | 2784 | for (i = 0; i < nb_input_streams; i++) { |
| 2781 | ist = &input_streams[i]; | 2785 | ist = input_streams[i]; |
| 2782 | if (ist->decoding_needed) { | 2786 | if (ist->decoding_needed) { |
| 2783 | output_packet(ist, NULL); | 2787 | output_packet(ist, NULL); |
| 2784 | } | 2788 | } |
| @@ -2789,7 +2793,7 @@ static int transcode(void) · 4 unmodified lines | |||
| 2789 | 2793 | ||
| 2790 | /* write the trailer if needed and close file */ | 2794 | /* write the trailer if needed and close file */ |
| 2791 | for (i = 0; i < nb_output_files; i++) { | 2795 | for (i = 0; i < nb_output_files; i++) { |
| 2792 | os = output_files[i].ctx; | 2796 | os = output_files[i]->ctx; |
| 2793 | av_write_trailer(os); | 2797 | av_write_trailer(os); |
| 2794 | } | 2798 | } |
| 2795 | 2799 | ||
| @@ -2798,7 +2802,7 @@ static int transcode(void) · 2 unmodified lines | |||
| 2798 | 2802 | ||
| 2799 | /* close each encoder */ | 2803 | /* close each encoder */ |
| 2800 | for (i = 0; i < nb_output_streams; i++) { | 2804 | for (i = 0; i < nb_output_streams; i++) { |
| 2801 | ost = &output_streams[i]; | 2805 | ost = output_streams[i]; |
| 2802 | if (ost->encoding_needed) { | 2806 | if (ost->encoding_needed) { |
| 2803 | av_freep(&ost->st->codec->stats_in); | 2807 | av_freep(&ost->st->codec->stats_in); |
| 2804 | avcodec_close(ost->st->codec); | 2808 | avcodec_close(ost->st->codec); |
| @@ -2808,7 +2812,7 @@ static int transcode(void) · 3 unmodified lines | |||
| 2808 | 2812 | ||
| 2809 | /* close each decoder */ | 2813 | /* close each decoder */ |
| 2810 | for (i = 0; i < nb_input_streams; i++) { | 2814 | for (i = 0; i < nb_input_streams; i++) { |
| 2811 | ist = &input_streams[i]; | 2815 | ist = input_streams[i]; |
| 2812 | if (ist->decoding_needed) { | 2816 | if (ist->decoding_needed) { |
| 2813 | avcodec_close(ist->st->codec); | 2817 | avcodec_close(ist->st->codec); |
| 2814 | } | 2818 | } |
| @@ -2822,7 +2826,7 @@ static int transcode(void) · 7 unmodified lines | |||
| 2822 | 2826 | ||
| 2823 | if (output_streams) { | 2827 | if (output_streams) { |
| 2824 | for (i = 0; i < nb_output_streams; i++) { | 2828 | for (i = 0; i < nb_output_streams; i++) { |
| 2825 | ost = &output_streams[i]; | 2829 | ost = output_streams[i]; |
| 2826 | if (ost) { | 2830 | if (ost) { |
| 2827 | if (ost->stream_copy) | 2831 | if (ost->stream_copy) |
| 2828 | av_freep(&ost->st->codec->extradata); | 2832 | av_freep(&ost->st->codec->extradata); |
| @@ -2913,13 +2917,13 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) · 84 unmodified lines | |||
| 2913 | } | 2917 | } |
| 2914 | if (*sync) | 2918 | if (*sync) |
| 2915 | sync++; | 2919 | sync++; |
| 2916 | for (i = 0; i < input_files[sync_file_idx].nb_streams; i++) | 2920 | for (i = 0; i < input_files[sync_file_idx]->nb_streams; i++) |
| 2917 | if (check_stream_specifier(input_files[sync_file_idx].ctx, | 2921 | if (check_stream_specifier(input_files[sync_file_idx]->ctx, |
| 2918 | input_files[sync_file_idx].ctx->streams[i], sync) == 1) { | 2922 | input_files[sync_file_idx]->ctx->streams[i], sync) == 1) { |
| 2919 | sync_stream_idx = i; | 2923 | sync_stream_idx = i; |
| 2920 | break; | 2924 | break; |
| 2921 | } | 2925 | } |
| 2922 | if (i == input_files[sync_file_idx].nb_streams) { | 2926 | if (i == input_files[sync_file_idx]->nb_streams) { |
| 2923 | av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not " | 2927 | av_log(NULL, AV_LOG_FATAL, "Sync stream specification in map %s does not " |
| 2924 | "match any streams.\n", arg); | 2928 | "match any streams.\n", arg); |
| 2925 | exit_program(1); | 2929 | exit_program(1); |
| @@ -2937,14 +2941,14 @@ static int opt_map(OptionsContext *o, const char *opt, const char *arg) · 11 unmodified lines | |||
| 2937 | for (i = 0; i < o->nb_stream_maps; i++) { | 2941 | for (i = 0; i < o->nb_stream_maps; i++) { |
| 2938 | m = &o->stream_maps[i]; | 2942 | m = &o->stream_maps[i]; |
| 2939 | if (file_idx == m->file_index && | 2943 | if (file_idx == m->file_index && |
| 2940 | check_stream_specifier(input_files[m->file_index].ctx, | 2944 | check_stream_specifier(input_files[m->file_index]->ctx, |
| 2941 | input_files[m->file_index].ctx->streams[m->stream_index], | 2945 | input_files[m->file_index]->ctx->streams[m->stream_index], |
| 2942 | *p == ':' ? p + 1 : p) > 0) | 2946 | *p == ':' ? p + 1 : p) > 0) |
| 2943 | m->disabled = 1; | 2947 | m->disabled = 1; |
| 2944 | } | 2948 | } |
| 2945 | else | 2949 | else |
| 2946 | for (i = 0; i < input_files[file_idx].nb_streams; i++) { | 2950 | for (i = 0; i < input_files[file_idx]->nb_streams; i++) { |
| 2947 | if (check_stream_specifier(input_files[file_idx].ctx, input_files[file_idx].ctx->streams[i], | 2951 | if (check_stream_specifier(input_files[file_idx]->ctx, input_files[file_idx]->ctx->streams[i], |
| 2948 | *p == ':' ? p + 1 : p) <= 0) | 2952 | *p == ':' ? p + 1 : p) <= 0) |
| 2949 | continue; | 2953 | continue; |
| 2950 | o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps), | 2954 | o->stream_maps = grow_array(o->stream_maps, sizeof(*o->stream_maps), |
| @@ -3129,10 +3133,14 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) · 178 unmodified lines | |||
| 3129 | for (i = 0; i < ic->nb_streams; i++) { | 3133 | for (i = 0; i < ic->nb_streams; i++) { |
| 3130 | AVStream *st = ic->streams[i]; | 3134 | AVStream *st = ic->streams[i]; |
| 3131 | AVCodecContext *dec = st->codec; | 3135 | AVCodecContext *dec = st->codec; |
| 3132 | InputStream *ist; | 3136 | InputStream *ist = av_mallocz(sizeof(*ist)); |
| 3137 | |||
| 3138 | if (!ist) | ||
| 3139 | exit_program(1); | ||
| 3133 | 3140 | ||
| 3134 | input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1); | 3141 | input_streams = grow_array(input_streams, sizeof(*input_streams), &nb_input_streams, nb_input_streams + 1); |
| 3135 | ist = &input_streams[nb_input_streams - 1]; | 3142 | input_streams[nb_input_streams - 1] = ist; |
| 3143 | |||
| 3136 | ist->st = st; | 3144 | ist->st = st; |
| 3137 | ist->file_index = nb_input_files; | 3145 | ist->file_index = nb_input_files; |
| 3138 | ist->discard = 1; | 3146 | ist->discard = 1; |
| @@ -3314,11 +3322,14 @@ static int opt_input_file(OptionsContext *o, const char *opt, const char *filena · 175 unmodified lines | |||
| 3314 | av_dump_format(ic, nb_input_files, filename, 0); | 3322 | av_dump_format(ic, nb_input_files, filename, 0); |
| 3315 | 3323 | ||
| 3316 | input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1); | 3324 | input_files = grow_array(input_files, sizeof(*input_files), &nb_input_files, nb_input_files + 1); |
| 3317 | input_files[nb_input_files - 1].ctx = ic; | 3325 | if (!(input_files[nb_input_files - 1] = av_mallocz(sizeof(*input_files[0])))) |
| 3318 | input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams; | 3326 | exit_program(1); |
| 3319 | input_files[nb_input_files - 1].ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp); | 3327 | |
| 3320 | input_files[nb_input_files - 1].nb_streams = ic->nb_streams; | 3328 | input_files[nb_input_files - 1]->ctx = ic; |
| 3321 | input_files[nb_input_files - 1].rate_emu = o->rate_emu; | 3329 | input_files[nb_input_files - 1]->ist_index = nb_input_streams - ic->nb_streams; |
| 3330 | input_files[nb_input_files - 1]->ts_offset = o->input_ts_offset - (copy_ts ? 0 : timestamp); | ||
| 3331 | input_files[nb_input_files - 1]->nb_streams = ic->nb_streams; | ||
| 3332 | input_files[nb_input_files - 1]->rate_emu = o->rate_emu; | ||
| 3322 | 3333 | ||
| 3323 | for (i = 0; i < o->nb_dump_attachment; i++) { | 3334 | for (i = 0; i < o->nb_dump_attachment; i++) { |
| 3324 | int j; | 3335 | int j; |
| @@ -3445,7 +3456,10 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e · 120 unmodified lines | |||
| 3445 | 3456 | ||
| 3446 | output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams, | 3457 | output_streams = grow_array(output_streams, sizeof(*output_streams), &nb_output_streams, |
| 3447 | nb_output_streams + 1); | 3458 | nb_output_streams + 1); |
| 3448 | ost = &output_streams[nb_output_streams - 1]; | 3459 | if (!(ost = av_mallocz(sizeof(*ost)))) |
| 3460 | exit_program(1); | ||
| 3461 | output_streams[nb_output_streams - 1] = ost; | ||
| 3462 | |||
| 3449 | ost->file_index = nb_output_files; | 3463 | ost->file_index = nb_output_files; |
| 3450 | ost->index = idx; | 3464 | ost->index = idx; |
| 3451 | ost->st = st; | 3465 | ost->st = st; |
| @@ -3825,16 +3839,16 @@ static void opt_output_file(void *optctx, const char *filename) · 373 unmodified lines | |||
| 3825 | if (index >= 0) {\ | 3839 | if (index >= 0) {\ |
| 3826 | ost = new_ ## type ## _stream(o, oc);\ | 3840 | ost = new_ ## type ## _stream(o, oc);\ |
| 3827 | ost->source_index = index;\ | 3841 | ost->source_index = index;\ |
| 3828 | ost->sync_ist = &input_streams[index];\ | 3842 | ost->sync_ist = input_streams[index];\ |
| 3829 | input_streams[index].discard = 0;\ | 3843 | input_streams[index]->discard = 0;\ |
| 3830 | input_streams[index].st->discard = AVDISCARD_NONE;\ | 3844 | input_streams[index]->st->discard = AVDISCARD_NONE;\ |
| 3831 | } | 3845 | } |
| 3832 | 3846 | ||
| 3833 | /* video: highest resolution */ | 3847 | /* video: highest resolution */ |
| 3834 | if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) { | 3848 | if (!o->video_disable && oc->oformat->video_codec != CODEC_ID_NONE) { |
| 3835 | int area = 0, idx = -1; | 3849 | int area = 0, idx = -1; |
| 3836 | for (i = 0; i < nb_input_streams; i++) { | 3850 | for (i = 0; i < nb_input_streams; i++) { |
| 3837 | ist = &input_streams[i]; | 3851 | ist = input_streams[i]; |
| 3838 | if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && | 3852 | if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && |
| 3839 | ist->st->codec->width * ist->st->codec->height > area) { | 3853 | ist->st->codec->width * ist->st->codec->height > area) { |
| 3840 | area = ist->st->codec->width * ist->st->codec->height; | 3854 | area = ist->st->codec->width * ist->st->codec->height; |
| @@ -3848,7 +3862,7 @@ static void opt_output_file(void *optctx, const char *filename) · 7 unmodified lines | |||
| 3848 | if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) { | 3862 | if (!o->audio_disable && oc->oformat->audio_codec != CODEC_ID_NONE) { |
| 3849 | int channels = 0, idx = -1; | 3863 | int channels = 0, idx = -1; |
| 3850 | for (i = 0; i < nb_input_streams; i++) { | 3864 | for (i = 0; i < nb_input_streams; i++) { |
| 3851 | ist = &input_streams[i]; | 3865 | ist = input_streams[i]; |
| 3852 | if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && | 3866 | if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && |
| 3853 | ist->st->codec->channels > channels) { | 3867 | ist->st->codec->channels > channels) { |
| 3854 | channels = ist->st->codec->channels; | 3868 | channels = ist->st->codec->channels; |
| @@ -3861,7 +3875,7 @@ static void opt_output_file(void *optctx, const char *filename) · 6 unmodified lines | |||
| 3861 | /* subtitles: pick first */ | 3875 | /* subtitles: pick first */ |
| 3862 | if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) { | 3876 | if (!o->subtitle_disable && oc->oformat->subtitle_codec != CODEC_ID_NONE) { |
| 3863 | for (i = 0; i < nb_input_streams; i++) | 3877 | for (i = 0; i < nb_input_streams; i++) |
| 3864 | if (input_streams[i].st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { | 3878 | if (input_streams[i]->st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { |
| 3865 | NEW_STREAM(subtitle, i); | 3879 | NEW_STREAM(subtitle, i); |
| 3866 | break; | 3880 | break; |
| 3867 | } | 3881 | } |
| @@ -3874,7 +3888,7 @@ static void opt_output_file(void *optctx, const char *filename) · 6 unmodified lines | |||
| 3874 | if (map->disabled) | 3888 | if (map->disabled) |
| 3875 | continue; | 3889 | continue; |
| 3876 | 3890 | ||
| 3877 | ist = &input_streams[input_files[map->file_index].ist_index + map->stream_index]; | 3891 | ist = input_streams[input_files[map->file_index]->ist_index + map->stream_index]; |
| 3878 | switch (ist->st->codec->codec_type) { | 3892 | switch (ist->st->codec->codec_type) { |
| 3879 | case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break; | 3893 | case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break; |
| 3880 | case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break; | 3894 | case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break; |
| @@ -3887,8 +3901,8 @@ static void opt_output_file(void *optctx, const char *filename) · 6 unmodified lines | |||
| 3887 | exit_program(1); | 3901 | exit_program(1); |
| 3888 | } | 3902 | } |
| 3889 | 3903 | ||
| 3890 | ost->source_index = input_files[map->file_index].ist_index + map->stream_index; | 3904 | ost->source_index = input_files[map->file_index]->ist_index + map->stream_index; |
| 3891 | ost->sync_ist = &input_streams[input_files[map->sync_file_index].ist_index + | 3905 | ost->sync_ist = input_streams[input_files[map->sync_file_index]->ist_index + |
| 3892 | map->sync_stream_index]; | 3906 | map->sync_stream_index]; |
| 3893 | ist->discard = 0; | 3907 | ist->discard = 0; |
| 3894 | ist->st->discard = AVDISCARD_NONE; | 3908 | ist->st->discard = AVDISCARD_NONE; |
| @@ -3932,14 +3946,17 @@ static void opt_output_file(void *optctx, const char *filename) · 37 unmodified lines | |||
| 3932 | } | 3946 | } |
| 3933 | 3947 | ||
| 3934 | output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1); | 3948 | output_files = grow_array(output_files, sizeof(*output_files), &nb_output_files, nb_output_files + 1); |
| 3935 | output_files[nb_output_files - 1].ctx = oc; | 3949 | if (!(output_files[nb_output_files - 1] = av_mallocz(sizeof(*output_files[0])))) |
| 3936 | output_files[nb_output_files - 1].ost_index = nb_output_streams - oc->nb_streams; | 3950 | exit_program(1); |
| 3937 | output_files[nb_output_files - 1].recording_time = o->recording_time; | 3951 | |
| 3952 | output_files[nb_output_files - 1]->ctx = oc; | ||
| 3953 | output_files[nb_output_files - 1]->ost_index = nb_output_streams - oc->nb_streams; | ||
| 3954 | output_files[nb_output_files - 1]->recording_time = o->recording_time; | ||
| 3938 | if (o->recording_time != INT64_MAX) | 3955 | if (o->recording_time != INT64_MAX) |
| 3939 | oc->duration = o->recording_time; | 3956 | oc->duration = o->recording_time; |
| 3940 | output_files[nb_output_files - 1].start_time = o->start_time; | 3957 | output_files[nb_output_files - 1]->start_time = o->start_time; |
| 3941 | output_files[nb_output_files - 1].limit_filesize = o->limit_filesize; | 3958 | output_files[nb_output_files - 1]->limit_filesize = o->limit_filesize; |
| 3942 | av_dict_copy(&output_files[nb_output_files - 1].opts, format_opts, 0); | 3959 | av_dict_copy(&output_files[nb_output_files - 1]->opts, format_opts, 0); |
| 3943 | 3960 | ||
| 3944 | /* check filename in case of an image number is expected */ | 3961 | /* check filename in case of an image number is expected */ |
| 3945 | if (oc->oformat->flags & AVFMT_NEEDNUMBER) { | 3962 | if (oc->oformat->flags & AVFMT_NEEDNUMBER) { |
| @@ -3956,7 +3973,7 @@ static void opt_output_file(void *optctx, const char *filename) · 10 unmodified lines | |||
| 3956 | /* open the file */ | 3973 | /* open the file */ |
| 3957 | if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE, | 3974 | if ((err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE, |
| 3958 | &oc->interrupt_callback, | 3975 | &oc->interrupt_callback, |
| 3959 | &output_files[nb_output_files - 1].opts)) < 0) { | 3976 | &output_files[nb_output_files - 1]->opts)) < 0) { |
| 3960 | print_error(filename, err); | 3977 | print_error(filename, err); |
| 3961 | exit_program(1); | 3978 | exit_program(1); |
| 3962 | } | 3979 | } |
| @@ -3965,7 +3982,7 @@ static void opt_output_file(void *optctx, const char *filename) · 2 unmodified lines | |||
| 3965 | if (o->mux_preload) { | 3982 | if (o->mux_preload) { |
| 3966 | uint8_t buf[64]; | 3983 | uint8_t buf[64]; |
| 3967 | snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE)); | 3984 | snprintf(buf, sizeof(buf), "%d", (int)(o->mux_preload*AV_TIME_BASE)); |
| 3968 | av_dict_set(&output_files[nb_output_files - 1].opts, "preload", buf, 0); | 3985 | av_dict_set(&output_files[nb_output_files - 1]->opts, "preload", buf, 0); |
| 3969 | } | 3986 | } |
| 3970 | oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE); | 3987 | oc->max_delay = (int)(o->mux_max_delay * AV_TIME_BASE); |
| 3971 | oc->flags |= AVFMT_FLAG_NONBLOCK; | 3988 | oc->flags |= AVFMT_FLAG_NONBLOCK; |
| @@ -3981,7 +3998,7 @@ static void opt_output_file(void *optctx, const char *filename) · 9 unmodified lines | |||
| 3981 | av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index); | 3998 | av_log(NULL, AV_LOG_FATAL, "Invalid input file index %d while processing metadata maps\n", in_file_index); |
| 3982 | exit_program(1); | 3999 | exit_program(1); |
| 3983 | } | 4000 | } |
| 3984 | copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, input_files[in_file_index].ctx, o); | 4001 | copy_metadata(o->metadata_map[i].specifier, *p ? p + 1 : p, oc, input_files[in_file_index]->ctx, o); |
| 3985 | } | 4002 | } |
| 3986 | 4003 | ||
| 3987 | /* copy chapters */ | 4004 | /* copy chapters */ |
| @@ -3990,7 +4007,7 @@ static void opt_output_file(void *optctx, const char *filename) · 2 unmodified lines | |||
| 3990 | /* copy chapters from the first input file that has them*/ | 4007 | /* copy chapters from the first input file that has them*/ |
| 3991 | o->chapters_input_file = -1; | 4008 | o->chapters_input_file = -1; |
| 3992 | for (i = 0; i < nb_input_files; i++) | 4009 | for (i = 0; i < nb_input_files; i++) |
| 3993 | if (input_files[i].ctx->nb_chapters) { | 4010 | if (input_files[i]->ctx->nb_chapters) { |
| 3994 | o->chapters_input_file = i; | 4011 | o->chapters_input_file = i; |
| 3995 | break; | 4012 | break; |
| 3996 | } | 4013 | } |
| @@ -4001,20 +4018,20 @@ static void opt_output_file(void *optctx, const char *filename) · 4 unmodified lines | |||
| 4001 | } | 4018 | } |
| 4002 | } | 4019 | } |
| 4003 | if (o->chapters_input_file >= 0) | 4020 | if (o->chapters_input_file >= 0) |
| 4004 | copy_chapters(&input_files[o->chapters_input_file], &output_files[nb_output_files - 1], | 4021 | copy_chapters(input_files[o->chapters_input_file], output_files[nb_output_files - 1], |
| 4005 | !o->metadata_chapters_manual); | 4022 | !o->metadata_chapters_manual); |
| 4006 | 4023 | ||
| 4007 | /* copy global metadata by default */ | 4024 | /* copy global metadata by default */ |
| 4008 | if (!o->metadata_global_manual && nb_input_files) | 4025 | if (!o->metadata_global_manual && nb_input_files) |
| 4009 | av_dict_copy(&oc->metadata, input_files[0].ctx->metadata, | 4026 | av_dict_copy(&oc->metadata, input_files[0]->ctx->metadata, |
| 4010 | AV_DICT_DONT_OVERWRITE); | 4027 | AV_DICT_DONT_OVERWRITE); |
| 4011 | if (!o->metadata_streams_manual) | 4028 | if (!o->metadata_streams_manual) |
| 4012 | for (i = output_files[nb_output_files - 1].ost_index; i < nb_output_streams; i++) { | 4029 | for (i = output_files[nb_output_files - 1]->ost_index; i < nb_output_streams; i++) { |
| 4013 | InputStream *ist; | 4030 | InputStream *ist; |
| 4014 | if (output_streams[i].source_index < 0) /* this is true e.g. for attached files */ | 4031 | if (output_streams[i]->source_index < 0) /* this is true e.g. for attached files */ |
| 4015 | continue; | 4032 | continue; |
| 4016 | ist = &input_streams[output_streams[i].source_index]; | 4033 | ist = input_streams[output_streams[i]->source_index]; |
| 4017 | av_dict_copy(&output_streams[i].st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); | 4034 | av_dict_copy(&output_streams[i]->st->metadata, ist->st->metadata, AV_DICT_DONT_OVERWRITE); |
| 4018 | } | 4035 | } |
| 4019 | 4036 | ||
| 4020 | /* process manually set metadata */ | 4037 | /* process manually set metadata */ |
| @@ -4173,8 +4190,8 @@ static int opt_target(OptionsContext *o, const char *opt, const char *arg) · 152 unmodified lines | |||
| 4173 | if (nb_input_files) { | 4190 | if (nb_input_files) { |
| 4174 | int i, j, fr; | 4191 | int i, j, fr; |
| 4175 | for (j = 0; j < nb_input_files; j++) { | 4192 | for (j = 0; j < nb_input_files; j++) { |
| 4176 | for (i = 0; i < input_files[j].nb_streams; i++) { | 4193 | for (i = 0; i < input_files[j]->nb_streams; i++) { |
| 4177 | AVCodecContext *c = input_files[j].ctx->streams[i]->codec; | 4194 | AVCodecContext *c = input_files[j]->ctx->streams[i]->codec; |
| 4178 | if (c->codec_type != AVMEDIA_TYPE_VIDEO) | 4195 | if (c->codec_type != AVMEDIA_TYPE_VIDEO) |
| 4179 | continue; | 4196 | continue; |
| 4180 | fr = c->time_base.den * 1000 / c->time_base.num; | 4197 | fr = c->time_base.den * 1000 / c->time_base.num; |