| 93 | } |
| 94 | |
| 95 | int avformat_alloc_output_context2(AVFormatContext **avctx, const AVOutputFormat *oformat, |
| 96 | const char *format, const char *filename) |
| 97 | { |
| 98 | AVFormatContext *s = avformat_alloc_context(); |
| 99 | int ret = 0; |
| 100 | |
| 101 | *avctx = NULL; |
| 102 | if (!s) |
| 103 | goto nomem; |
| 104 | |
| 105 | if (!oformat) { |
| 106 | if (format) { |
| 107 | oformat = av_guess_format(format, NULL, NULL); |
| 108 | if (!oformat) { |
| 109 | av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not known.\n", format); |
| 110 | ret = AVERROR(EINVAL); |
| 111 | goto error; |
| 112 | } |
| 113 | } else { |
| 114 | oformat = av_guess_format(NULL, filename, NULL); |
| 115 | if (!oformat) { |
| 116 | ret = AVERROR(EINVAL); |
| 117 | av_log(s, AV_LOG_ERROR, |
| 118 | "Unable to choose an output format for '%s'; " |
| 119 | "use a standard extension for the filename or specify " |
| 120 | "the format manually.\n", filename); |
| 121 | goto error; |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | s->oformat = oformat; |
| 127 | if (ffofmt(s->oformat)->priv_data_size > 0) { |
| 128 | s->priv_data = av_mallocz(ffofmt(s->oformat)->priv_data_size); |
| 129 | if (!s->priv_data) |
| 130 | goto nomem; |
| 131 | if (s->oformat->priv_class) { |
| 132 | *(const AVClass**)s->priv_data= s->oformat->priv_class; |
| 133 | av_opt_set_defaults(s->priv_data); |
| 134 | } |
| 135 | } else |
| 136 | s->priv_data = NULL; |
| 137 | |
| 138 | if (filename) { |
| 139 | if (!(s->url = av_strdup(filename))) |
| 140 | goto nomem; |
| 141 | |
| 142 | } |
| 143 | *avctx = s; |
| 144 | return 0; |
| 145 | nomem: |
| 146 | av_log(s, AV_LOG_ERROR, "Out of memory\n"); |
| 147 | ret = AVERROR(ENOMEM); |
| 148 | error: |
| 149 | avformat_free_context(s); |
| 150 | return ret; |
| 151 | } |
| 152 | |