FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rawenc.c
Go to the documentation of this file.
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 
27 {
28  avio_write(s->pb, pkt->data, pkt->size);
29  return 0;
30 }
31 
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  AVCodecParameters *par = s->streams[0]->codecpar;
64 
65  if (pb->seekable) {
66  int64_t file_size = avio_tell(pb);
67  uint64_t sample_count = (file_size - 36) / par->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_GSM_MUXER
197 AVOutputFormat ff_gsm_muxer = {
198  .name = "gsm",
199  .long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
200  .mime_type = "audio/x-gsm",
201  .extensions = "gsm",
202  .audio_codec = AV_CODEC_ID_GSM,
203  .video_codec = AV_CODEC_ID_NONE,
204  .write_header = force_one_stream,
205  .write_packet = ff_raw_write_packet,
206  .flags = AVFMT_NOTIMESTAMPS,
207 };
208 #endif
209 
210 #if CONFIG_H261_MUXER
211 AVOutputFormat ff_h261_muxer = {
212  .name = "h261",
213  .long_name = NULL_IF_CONFIG_SMALL("raw H.261"),
214  .mime_type = "video/x-h261",
215  .extensions = "h261",
216  .audio_codec = AV_CODEC_ID_NONE,
217  .video_codec = AV_CODEC_ID_H261,
218  .write_header = force_one_stream,
219  .write_packet = ff_raw_write_packet,
220  .flags = AVFMT_NOTIMESTAMPS,
221 };
222 #endif
223 
224 #if CONFIG_H263_MUXER
225 AVOutputFormat ff_h263_muxer = {
226  .name = "h263",
227  .long_name = NULL_IF_CONFIG_SMALL("raw H.263"),
228  .mime_type = "video/x-h263",
229  .extensions = "h263",
230  .audio_codec = AV_CODEC_ID_NONE,
231  .video_codec = AV_CODEC_ID_H263,
232  .write_header = force_one_stream,
233  .write_packet = ff_raw_write_packet,
234  .flags = AVFMT_NOTIMESTAMPS,
235 };
236 #endif
237 
238 #if CONFIG_H264_MUXER
239 AVOutputFormat ff_h264_muxer = {
240  .name = "h264",
241  .long_name = NULL_IF_CONFIG_SMALL("raw H.264 video"),
242  .extensions = "h264,264",
243  .audio_codec = AV_CODEC_ID_NONE,
244  .video_codec = AV_CODEC_ID_H264,
245  .write_header = force_one_stream,
246  .write_packet = ff_raw_write_packet,
247  .flags = AVFMT_NOTIMESTAMPS,
248 };
249 #endif
250 
251 #if CONFIG_HEVC_MUXER
252 AVOutputFormat ff_hevc_muxer = {
253  .name = "hevc",
254  .long_name = NULL_IF_CONFIG_SMALL("raw HEVC video"),
255  .extensions = "hevc,h265,265",
256  .audio_codec = AV_CODEC_ID_NONE,
257  .video_codec = AV_CODEC_ID_HEVC,
258  .write_header = force_one_stream,
259  .write_packet = ff_raw_write_packet,
260  .flags = AVFMT_NOTIMESTAMPS,
261 };
262 #endif
263 
264 #if CONFIG_M4V_MUXER
265 AVOutputFormat ff_m4v_muxer = {
266  .name = "m4v",
267  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-4 video"),
268  .extensions = "m4v",
269  .audio_codec = AV_CODEC_ID_NONE,
270  .video_codec = AV_CODEC_ID_MPEG4,
271  .write_header = force_one_stream,
272  .write_packet = ff_raw_write_packet,
273  .flags = AVFMT_NOTIMESTAMPS,
274 };
275 #endif
276 
277 #if CONFIG_MJPEG_MUXER
278 AVOutputFormat ff_mjpeg_muxer = {
279  .name = "mjpeg",
280  .long_name = NULL_IF_CONFIG_SMALL("raw MJPEG video"),
281  .mime_type = "video/x-mjpeg",
282  .extensions = "mjpg,mjpeg",
283  .audio_codec = AV_CODEC_ID_NONE,
284  .video_codec = AV_CODEC_ID_MJPEG,
285  .write_header = force_one_stream,
286  .write_packet = ff_raw_write_packet,
287  .flags = AVFMT_NOTIMESTAMPS,
288 };
289 #endif
290 
291 #if CONFIG_SINGLEJPEG_MUXER
292 AVOutputFormat ff_singlejpeg_muxer = {
293  .name = "singlejpeg",
294  .long_name = NULL_IF_CONFIG_SMALL("JPEG single image"),
295  .mime_type = "image/jpeg",
296  .audio_codec = AV_CODEC_ID_NONE,
297  .video_codec = AV_CODEC_ID_MJPEG,
298  .write_packet = ff_raw_write_packet,
299  .flags = AVFMT_NOTIMESTAMPS,
300  .write_header = force_one_stream,
301 };
302 #endif
303 
304 #if CONFIG_MLP_MUXER
305 AVOutputFormat ff_mlp_muxer = {
306  .name = "mlp",
307  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
308  .extensions = "mlp",
309  .audio_codec = AV_CODEC_ID_MLP,
310  .video_codec = AV_CODEC_ID_NONE,
311  .write_header = force_one_stream,
312  .write_packet = ff_raw_write_packet,
313  .flags = AVFMT_NOTIMESTAMPS,
314 };
315 #endif
316 
317 #if CONFIG_MPEG1VIDEO_MUXER
318 AVOutputFormat ff_mpeg1video_muxer = {
319  .name = "mpeg1video",
320  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
321  .mime_type = "video/mpeg",
322  .extensions = "mpg,mpeg,m1v",
323  .audio_codec = AV_CODEC_ID_NONE,
324  .video_codec = AV_CODEC_ID_MPEG1VIDEO,
325  .write_header = force_one_stream,
326  .write_packet = ff_raw_write_packet,
327  .flags = AVFMT_NOTIMESTAMPS,
328 };
329 #endif
330 
331 #if CONFIG_MPEG2VIDEO_MUXER
332 AVOutputFormat ff_mpeg2video_muxer = {
333  .name = "mpeg2video",
334  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
335  .extensions = "m2v",
336  .audio_codec = AV_CODEC_ID_NONE,
337  .video_codec = AV_CODEC_ID_MPEG2VIDEO,
338  .write_header = force_one_stream,
339  .write_packet = ff_raw_write_packet,
340  .flags = AVFMT_NOTIMESTAMPS,
341 };
342 #endif
343 
344 #if CONFIG_RAWVIDEO_MUXER
345 AVOutputFormat ff_rawvideo_muxer = {
346  .name = "rawvideo",
347  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
348  .extensions = "yuv,rgb",
349  .audio_codec = AV_CODEC_ID_NONE,
350  .video_codec = AV_CODEC_ID_RAWVIDEO,
351  .write_packet = ff_raw_write_packet,
352  .flags = AVFMT_NOTIMESTAMPS,
353 };
354 #endif
355 
356 #if CONFIG_TRUEHD_MUXER
357 AVOutputFormat ff_truehd_muxer = {
358  .name = "truehd",
359  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
360  .extensions = "thd",
361  .audio_codec = AV_CODEC_ID_TRUEHD,
362  .video_codec = AV_CODEC_ID_NONE,
363  .write_header = force_one_stream,
364  .write_packet = ff_raw_write_packet,
365  .flags = AVFMT_NOTIMESTAMPS,
366 };
367 #endif
368 
369 #if CONFIG_VC1_MUXER
370 AVOutputFormat ff_vc1_muxer = {
371  .name = "vc1",
372  .long_name = NULL_IF_CONFIG_SMALL("raw VC-1 video"),
373  .extensions = "vc1",
374  .audio_codec = AV_CODEC_ID_NONE,
375  .video_codec = AV_CODEC_ID_VC1,
376  .write_header = force_one_stream,
377  .write_packet = ff_raw_write_packet,
378  .flags = AVFMT_NOTIMESTAMPS,
379 };
380 #endif
const char * s
Definition: avisynth_c.h:631
Bytestream IO Context.
Definition: avio.h:111
static int force_one_stream(AVFormatContext *s)
Definition: rawenc.c:32
int size
Definition: avcodec.h:1578
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:213
static AVPacket pkt
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3907
Format I/O context.
Definition: avformat.h:1319
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1387
uint8_t * data
Definition: avcodec.h:1577
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:447
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:187
#define av_log(a,...)
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1338
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1375
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:207
const char * name
Definition: avformat.h:522
int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawenc.c:26
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:194
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:484
AVIOContext * pb
I/O context.
Definition: avformat.h:1361
Main libavformat public API header.
if(ret< 0)
Definition: vf_mcdeint.c:282
as in Berlin toast format
Definition: avcodec.h:529
int channels
Audio only.
Definition: avcodec.h:4021
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:337
AVCodecParameters * codecpar
Definition: avformat.h:1006
This structure stores compressed data.
Definition: avcodec.h:1554