avformat/concatdec: set safe mode to enabled instead of auto
[ffmpeg.git] / libavformat / rawenc.c
1 /*
2  * RAW muxers
3  * Copyright (c) 2001 Fabrice Bellard
4  * Copyright (c) 2005 Alex Beregszaszi
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #include "avformat.h"
24 #include "rawenc.h"
25
26 int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
27 {
28     avio_write(s->pb, pkt->data, pkt->size);
29     return 0;
30 }
31
32 static int force_one_stream(AVFormatContext *s)
33 {
34     if (s->nb_streams != 1) {
35         av_log(s, AV_LOG_ERROR, "%s files have exactly one stream\n",
36                s->oformat->name);
37         return AVERROR(EINVAL);
38     }
39     return 0;
40 }
41
42 /* Note: Do not forget to add new entries to the Makefile as well. */
43
44 #if CONFIG_AC3_MUXER
45 AVOutputFormat ff_ac3_muxer = {
46     .name              = "ac3",
47     .long_name         = NULL_IF_CONFIG_SMALL("raw AC-3"),
48     .mime_type         = "audio/x-ac3",
49     .extensions        = "ac3",
50     .audio_codec       = AV_CODEC_ID_AC3,
51     .video_codec       = AV_CODEC_ID_NONE,
52     .write_header      = force_one_stream,
53     .write_packet      = ff_raw_write_packet,
54     .flags             = AVFMT_NOTIMESTAMPS,
55 };
56 #endif
57
58 #if CONFIG_ADX_MUXER
59
60 static int adx_write_trailer(AVFormatContext *s)
61 {
62     AVIOContext *pb = s->pb;
63     AVCodecContext *avctx = s->streams[0]->codec;
64
65     if (pb->seekable) {
66         int64_t file_size = avio_tell(pb);
67         uint64_t sample_count = (file_size - 36) / avctx->channels / 18 * 32;
68         if (sample_count <= UINT32_MAX) {
69             avio_seek(pb, 12, SEEK_SET);
70             avio_wb32(pb, sample_count);
71             avio_seek(pb, file_size, SEEK_SET);
72         }
73     }
74
75     return 0;
76 }
77
78 AVOutputFormat ff_adx_muxer = {
79     .name              = "adx",
80     .long_name         = NULL_IF_CONFIG_SMALL("CRI ADX"),
81     .extensions        = "adx",
82     .audio_codec       = AV_CODEC_ID_ADPCM_ADX,
83     .video_codec       = AV_CODEC_ID_NONE,
84     .write_header      = force_one_stream,
85     .write_packet      = ff_raw_write_packet,
86     .write_trailer     = adx_write_trailer,
87     .flags             = AVFMT_NOTIMESTAMPS,
88 };
89 #endif
90
91 #if CONFIG_CAVSVIDEO_MUXER
92 AVOutputFormat ff_cavsvideo_muxer = {
93     .name              = "cavsvideo",
94     .long_name         = NULL_IF_CONFIG_SMALL("raw Chinese AVS (Audio Video Standard) video"),
95     .extensions        = "cavs",
96     .audio_codec       = AV_CODEC_ID_NONE,
97     .video_codec       = AV_CODEC_ID_CAVS,
98     .write_header      = force_one_stream,
99     .write_packet      = ff_raw_write_packet,
100     .flags             = AVFMT_NOTIMESTAMPS,
101 };
102 #endif
103
104 #if CONFIG_DATA_MUXER
105 AVOutputFormat ff_data_muxer = {
106     .name              = "data",
107     .long_name         = NULL_IF_CONFIG_SMALL("raw data"),
108     .write_header      = force_one_stream,
109     .write_packet      = ff_raw_write_packet,
110     .flags             = AVFMT_NOTIMESTAMPS,
111 };
112 #endif
113
114 #if CONFIG_DIRAC_MUXER
115 AVOutputFormat ff_dirac_muxer = {
116     .name              = "dirac",
117     .long_name         = NULL_IF_CONFIG_SMALL("raw Dirac"),
118     .extensions        = "drc,vc2",
119     .audio_codec       = AV_CODEC_ID_NONE,
120     .video_codec       = AV_CODEC_ID_DIRAC,
121     .write_header      = force_one_stream,
122     .write_packet      = ff_raw_write_packet,
123     .flags             = AVFMT_NOTIMESTAMPS,
124 };
125 #endif
126
127 #if CONFIG_DNXHD_MUXER
128 AVOutputFormat ff_dnxhd_muxer = {
129     .name              = "dnxhd",
130     .long_name         = NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
131     .extensions        = "dnxhd",
132     .audio_codec       = AV_CODEC_ID_NONE,
133     .video_codec       = AV_CODEC_ID_DNXHD,
134     .write_header      = force_one_stream,
135     .write_packet      = ff_raw_write_packet,
136     .flags             = AVFMT_NOTIMESTAMPS,
137 };
138 #endif
139
140 #if CONFIG_DTS_MUXER
141 AVOutputFormat ff_dts_muxer = {
142     .name              = "dts",
143     .long_name         = NULL_IF_CONFIG_SMALL("raw DTS"),
144     .mime_type         = "audio/x-dca",
145     .extensions        = "dts",
146     .audio_codec       = AV_CODEC_ID_DTS,
147     .video_codec       = AV_CODEC_ID_NONE,
148     .write_header      = force_one_stream,
149     .write_packet      = ff_raw_write_packet,
150     .flags             = AVFMT_NOTIMESTAMPS,
151 };
152 #endif
153
154 #if CONFIG_EAC3_MUXER
155 AVOutputFormat ff_eac3_muxer = {
156     .name              = "eac3",
157     .long_name         = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
158     .mime_type         = "audio/x-eac3",
159     .extensions        = "eac3",
160     .audio_codec       = AV_CODEC_ID_EAC3,
161     .video_codec       = AV_CODEC_ID_NONE,
162     .write_header      = force_one_stream,
163     .write_packet      = ff_raw_write_packet,
164     .flags             = AVFMT_NOTIMESTAMPS,
165 };
166 #endif
167
168 #if CONFIG_G722_MUXER
169 AVOutputFormat ff_g722_muxer = {
170     .name              = "g722",
171     .long_name         = NULL_IF_CONFIG_SMALL("raw G.722"),
172     .mime_type         = "audio/G722",
173     .extensions        = "g722",
174     .audio_codec       = AV_CODEC_ID_ADPCM_G722,
175     .video_codec       = AV_CODEC_ID_NONE,
176     .write_header      = force_one_stream,
177     .write_packet      = ff_raw_write_packet,
178     .flags             = AVFMT_NOTIMESTAMPS,
179 };
180 #endif
181
182 #if CONFIG_G723_1_MUXER
183 AVOutputFormat ff_g723_1_muxer = {
184     .name              = "g723_1",
185     .long_name         = NULL_IF_CONFIG_SMALL("raw G.723.1"),
186     .mime_type         = "audio/g723",
187     .extensions        = "tco,rco",
188     .audio_codec       = AV_CODEC_ID_G723_1,
189     .video_codec       = AV_CODEC_ID_NONE,
190     .write_header      = force_one_stream,
191     .write_packet      = ff_raw_write_packet,
192     .flags             = AVFMT_NOTIMESTAMPS,
193 };
194 #endif
195
196 #if CONFIG_H261_MUXER
197 AVOutputFormat ff_h261_muxer = {
198     .name              = "h261",
199     .long_name         = NULL_IF_CONFIG_SMALL("raw H.261"),
200     .mime_type         = "video/x-h261",
201     .extensions        = "h261",
202     .audio_codec       = AV_CODEC_ID_NONE,
203     .video_codec       = AV_CODEC_ID_H261,
204     .write_header      = force_one_stream,
205     .write_packet      = ff_raw_write_packet,
206     .flags             = AVFMT_NOTIMESTAMPS,
207 };
208 #endif
209
210 #if CONFIG_H263_MUXER
211 AVOutputFormat ff_h263_muxer = {
212     .name              = "h263",
213     .long_name         = NULL_IF_CONFIG_SMALL("raw H.263"),
214     .mime_type         = "video/x-h263",
215     .extensions        = "h263",
216     .audio_codec       = AV_CODEC_ID_NONE,
217     .video_codec       = AV_CODEC_ID_H263,
218     .write_header      = force_one_stream,
219     .write_packet      = ff_raw_write_packet,
220     .flags             = AVFMT_NOTIMESTAMPS,
221 };
222 #endif
223
224 #if CONFIG_H264_MUXER
225 AVOutputFormat ff_h264_muxer = {
226     .name              = "h264",
227     .long_name         = NULL_IF_CONFIG_SMALL("raw H.264 video"),
228     .extensions        = "h264,264",
229     .audio_codec       = AV_CODEC_ID_NONE,
230     .video_codec       = AV_CODEC_ID_H264,
231     .write_header      = force_one_stream,
232     .write_packet      = ff_raw_write_packet,
233     .flags             = AVFMT_NOTIMESTAMPS,
234 };
235 #endif
236
237 #if CONFIG_HEVC_MUXER
238 AVOutputFormat ff_hevc_muxer = {
239     .name              = "hevc",
240     .long_name         = NULL_IF_CONFIG_SMALL("raw HEVC video"),
241     .extensions        = "hevc,h265,265",
242     .audio_codec       = AV_CODEC_ID_NONE,
243     .video_codec       = AV_CODEC_ID_HEVC,
244     .write_header      = force_one_stream,
245     .write_packet      = ff_raw_write_packet,
246     .flags             = AVFMT_NOTIMESTAMPS,
247 };
248 #endif
249
250 #if CONFIG_M4V_MUXER
251 AVOutputFormat ff_m4v_muxer = {
252     .name              = "m4v",
253     .long_name         = NULL_IF_CONFIG_SMALL("raw MPEG-4 video"),
254     .extensions        = "m4v",
255     .audio_codec       = AV_CODEC_ID_NONE,
256     .video_codec       = AV_CODEC_ID_MPEG4,
257     .write_header      = force_one_stream,
258     .write_packet      = ff_raw_write_packet,
259     .flags             = AVFMT_NOTIMESTAMPS,
260 };
261 #endif
262
263 #if CONFIG_MJPEG_MUXER
264 AVOutputFormat ff_mjpeg_muxer = {
265     .name              = "mjpeg",
266     .long_name         = NULL_IF_CONFIG_SMALL("raw MJPEG video"),
267     .mime_type         = "video/x-mjpeg",
268     .extensions        = "mjpg,mjpeg",
269     .audio_codec       = AV_CODEC_ID_NONE,
270     .video_codec       = AV_CODEC_ID_MJPEG,
271     .write_header      = force_one_stream,
272     .write_packet      = ff_raw_write_packet,
273     .flags             = AVFMT_NOTIMESTAMPS,
274 };
275 #endif
276
277 #if CONFIG_SINGLEJPEG_MUXER
278 AVOutputFormat ff_singlejpeg_muxer = {
279     .name              = "singlejpeg",
280     .long_name         = NULL_IF_CONFIG_SMALL("JPEG single image"),
281     .mime_type         = "image/jpeg",
282     .audio_codec       = AV_CODEC_ID_NONE,
283     .video_codec       = AV_CODEC_ID_MJPEG,
284     .write_packet      = ff_raw_write_packet,
285     .flags             = AVFMT_NOTIMESTAMPS,
286     .write_header      = force_one_stream,
287 };
288 #endif
289
290 #if CONFIG_MLP_MUXER
291 AVOutputFormat ff_mlp_muxer = {
292     .name              = "mlp",
293     .long_name         = NULL_IF_CONFIG_SMALL("raw MLP"),
294     .extensions        = "mlp",
295     .audio_codec       = AV_CODEC_ID_MLP,
296     .video_codec       = AV_CODEC_ID_NONE,
297     .write_header      = force_one_stream,
298     .write_packet      = ff_raw_write_packet,
299     .flags             = AVFMT_NOTIMESTAMPS,
300 };
301 #endif
302
303 #if CONFIG_MPEG1VIDEO_MUXER
304 AVOutputFormat ff_mpeg1video_muxer = {
305     .name              = "mpeg1video",
306     .long_name         = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
307     .mime_type         = "video/mpeg",
308     .extensions        = "mpg,mpeg,m1v",
309     .audio_codec       = AV_CODEC_ID_NONE,
310     .video_codec       = AV_CODEC_ID_MPEG1VIDEO,
311     .write_header      = force_one_stream,
312     .write_packet      = ff_raw_write_packet,
313     .flags             = AVFMT_NOTIMESTAMPS,
314 };
315 #endif
316
317 #if CONFIG_MPEG2VIDEO_MUXER
318 AVOutputFormat ff_mpeg2video_muxer = {
319     .name              = "mpeg2video",
320     .long_name         = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
321     .extensions        = "m2v",
322     .audio_codec       = AV_CODEC_ID_NONE,
323     .video_codec       = AV_CODEC_ID_MPEG2VIDEO,
324     .write_header      = force_one_stream,
325     .write_packet      = ff_raw_write_packet,
326     .flags             = AVFMT_NOTIMESTAMPS,
327 };
328 #endif
329
330 #if CONFIG_RAWVIDEO_MUXER
331 AVOutputFormat ff_rawvideo_muxer = {
332     .name              = "rawvideo",
333     .long_name         = NULL_IF_CONFIG_SMALL("raw video"),
334     .extensions        = "yuv,rgb",
335     .audio_codec       = AV_CODEC_ID_NONE,
336     .video_codec       = AV_CODEC_ID_RAWVIDEO,
337     .write_packet      = ff_raw_write_packet,
338     .flags             = AVFMT_NOTIMESTAMPS,
339 };
340 #endif
341
342 #if CONFIG_TRUEHD_MUXER
343 AVOutputFormat ff_truehd_muxer = {
344     .name              = "truehd",
345     .long_name         = NULL_IF_CONFIG_SMALL("raw TrueHD"),
346     .extensions        = "thd",
347     .audio_codec       = AV_CODEC_ID_TRUEHD,
348     .video_codec       = AV_CODEC_ID_NONE,
349     .write_header      = force_one_stream,
350     .write_packet      = ff_raw_write_packet,
351     .flags             = AVFMT_NOTIMESTAMPS,
352 };
353 #endif
354
355 #if CONFIG_VC1_MUXER
356 AVOutputFormat ff_vc1_muxer = {
357     .name              = "vc1",
358     .long_name         = NULL_IF_CONFIG_SMALL("raw VC-1 video"),
359     .extensions        = "vc1",
360     .audio_codec       = AV_CODEC_ID_NONE,
361     .video_codec       = AV_CODEC_ID_VC1,
362     .write_header      = force_one_stream,
363     .write_packet      = ff_raw_write_packet,
364     .flags             = AVFMT_NOTIMESTAMPS,
365 };
366 #endif