Revision 002c95d7 ffmpeg.c

View differences:

ffmpeg.c
1545 1545
                     int nb_input_files,
1546 1546
                     AVStreamMap *stream_maps, int nb_stream_maps)
1547 1547
{
1548
    int ret, i, j, k, n, nb_istreams = 0, nb_ostreams = 0;
1548
    int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0;
1549 1549
    AVFormatContext *is, *os;
1550 1550
    AVCodecContext *codec, *icodec;
1551 1551
    AVOutputStream *ost, **ost_table = NULL;
1552 1552
    AVInputStream *ist, **ist_table = NULL;
1553 1553
    AVInputFile *file_table;
1554
    char error[1024];
1554 1555
    int key;
1555 1556
    int want_sdp = 1;
1556 1557
    uint8_t no_packet[MAX_FILES]={0};
......
1899 1900

  
1900 1901
    if (!bit_buffer)
1901 1902
        bit_buffer = av_malloc(bit_buffer_size);
1902
    if (!bit_buffer)
1903
    if (!bit_buffer) {
1904
        ret = AVERROR(ENOMEM);
1903 1905
        goto fail;
1904

  
1905
    /* dump the file output parameters - cannot be done before in case
1906
       of stream copy */
1907
    for(i=0;i<nb_output_files;i++) {
1908
        dump_format(output_files[i], i, output_files[i]->filename, 1);
1909
    }
1910

  
1911
    /* dump the stream mapping */
1912
    if (verbose >= 0) {
1913
        fprintf(stderr, "Stream mapping:\n");
1914
        for(i=0;i<nb_ostreams;i++) {
1915
            ost = ost_table[i];
1916
            fprintf(stderr, "  Stream #%d.%d -> #%d.%d",
1917
                    ist_table[ost->source_index]->file_index,
1918
                    ist_table[ost->source_index]->index,
1919
                    ost->file_index,
1920
                    ost->index);
1921
            if (ost->sync_ist != ist_table[ost->source_index])
1922
                fprintf(stderr, " [sync #%d.%d]",
1923
                        ost->sync_ist->file_index,
1924
                        ost->sync_ist->index);
1925
            fprintf(stderr, "\n");
1926
        }
1927 1906
    }
1928 1907

  
1929 1908
    /* open each encoder */
......
1934 1913
            if (!codec)
1935 1914
                codec = avcodec_find_encoder(ost->st->codec->codec_id);
1936 1915
            if (!codec) {
1937
                fprintf(stderr, "Unsupported codec for output stream #%d.%d\n",
1916
                snprintf(error, sizeof(error), "Unsupported codec for output stream #%d.%d",
1938 1917
                        ost->file_index, ost->index);
1939
                av_exit(1);
1918
                ret = AVERROR(EINVAL);
1919
                goto dump_format;
1940 1920
            }
1941 1921
            if (avcodec_open(ost->st->codec, codec) < 0) {
1942
                fprintf(stderr, "Error while opening codec for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height\n",
1922
                snprintf(error, sizeof(error), "Error while opening codec for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height",
1943 1923
                        ost->file_index, ost->index);
1944
                av_exit(1);
1924
                ret = AVERROR(EINVAL);
1925
                goto dump_format;
1945 1926
            }
1946 1927
            extra_size += ost->st->codec->extradata_size;
1947 1928
        }
......
1955 1936
            if (!codec)
1956 1937
                codec = avcodec_find_decoder(ist->st->codec->codec_id);
1957 1938
            if (!codec) {
1958
                fprintf(stderr, "Unsupported codec (id=%d) for input stream #%d.%d\n",
1939
                snprintf(error, sizeof(error), "Unsupported codec (id=%d) for input stream #%d.%d",
1959 1940
                        ist->st->codec->codec_id, ist->file_index, ist->index);
1960
                av_exit(1);
1941
                ret = AVERROR(EINVAL);
1942
                goto dump_format;
1961 1943
            }
1962 1944
            if (avcodec_open(ist->st->codec, codec) < 0) {
1963
                fprintf(stderr, "Error while opening codec for input stream #%d.%d\n",
1945
                snprintf(error, sizeof(error), "Error while opening codec for input stream #%d.%d",
1964 1946
                        ist->file_index, ist->index);
1965
                av_exit(1);
1947
                ret = AVERROR(EINVAL);
1948
                goto dump_format;
1966 1949
            }
1967 1950
            //if (ist->st->codec->codec_type == CODEC_TYPE_VIDEO)
1968 1951
            //    ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD;
......
1987 1970
        int out_file_index = meta_data_maps[i].out_file;
1988 1971
        int in_file_index = meta_data_maps[i].in_file;
1989 1972
        if (out_file_index < 0 || out_file_index >= nb_output_files) {
1990
            fprintf(stderr, "Invalid output file index %d map_meta_data(%d,%d)\n", out_file_index, out_file_index, in_file_index);
1973
            snprintf(error, sizeof(error), "Invalid output file index %d map_meta_data(%d,%d)",
1974
                     out_file_index, out_file_index, in_file_index);
1991 1975
            ret = AVERROR(EINVAL);
1992
            goto fail;
1976
            goto dump_format;
1993 1977
        }
1994 1978
        if (in_file_index < 0 || in_file_index >= nb_input_files) {
1995
            fprintf(stderr, "Invalid input file index %d map_meta_data(%d,%d)\n", in_file_index, out_file_index, in_file_index);
1979
            snprintf(error, sizeof(error), "Invalid input file index %d map_meta_data(%d,%d)",
1980
                     in_file_index, out_file_index, in_file_index);
1996 1981
            ret = AVERROR(EINVAL);
1997
            goto fail;
1982
            goto dump_format;
1998 1983
        }
1999 1984

  
2000 1985
        out_file = output_files[out_file_index];
......
2012 1997
    for(i=0;i<nb_output_files;i++) {
2013 1998
        os = output_files[i];
2014 1999
        if (av_write_header(os) < 0) {
2015
            fprintf(stderr, "Could not write header for output file #%d (incorrect codec parameters ?)\n", i);
2000
            snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i);
2016 2001
            ret = AVERROR(EINVAL);
2017
            goto fail;
2002
            goto dump_format;
2018 2003
        }
2019 2004
        if (strcmp(output_files[i]->oformat->name, "rtp")) {
2020 2005
            want_sdp = 0;
2021 2006
        }
2022 2007
    }
2008

  
2009
 dump_format:
2010
    /* dump the file output parameters - cannot be done before in case
2011
       of stream copy */
2012
    for(i=0;i<nb_output_files;i++) {
2013
        dump_format(output_files[i], i, output_files[i]->filename, 1);
2014
    }
2015

  
2016
    /* dump the stream mapping */
2017
    if (verbose >= 0) {
2018
        fprintf(stderr, "Stream mapping:\n");
2019
        for(i=0;i<nb_ostreams;i++) {
2020
            ost = ost_table[i];
2021
            fprintf(stderr, "  Stream #%d.%d -> #%d.%d",
2022
                    ist_table[ost->source_index]->file_index,
2023
                    ist_table[ost->source_index]->index,
2024
                    ost->file_index,
2025
                    ost->index);
2026
            if (ost->sync_ist != ist_table[ost->source_index])
2027
                fprintf(stderr, " [sync #%d.%d]",
2028
                        ost->sync_ist->file_index,
2029
                        ost->sync_ist->index);
2030
            fprintf(stderr, "\n");
2031
        }
2032
    }
2033

  
2034
    if (ret) {
2035
        fprintf(stderr, "%s\n", error);
2036
        goto fail;
2037
    }
2038

  
2023 2039
    if (want_sdp) {
2024 2040
        print_sdp(output_files, nb_output_files);
2025 2041
    }
......
2216 2232

  
2217 2233
    /* finished ! */
2218 2234

  
2219
    ret = 0;
2220
 fail1:
2235
 fail:
2221 2236
    av_freep(&bit_buffer);
2222 2237
    av_free(file_table);
2223 2238

  
......
2251 2266
        av_free(ost_table);
2252 2267
    }
2253 2268
    return ret;
2254
 fail:
2255
    ret = AVERROR(ENOMEM);
2256
    goto fail1;
2257 2269
}
2258 2270

  
2259 2271
#if 0

Also available in: Unified diff