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  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",
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",
242  .audio_codec = AV_CODEC_ID_NONE,
243  .video_codec = AV_CODEC_ID_HEVC,
244  .write_packet = ff_raw_write_packet,
245  .flags = AVFMT_NOTIMESTAMPS,
246 };
247 #endif
248 
249 #if CONFIG_M4V_MUXER
250 AVOutputFormat ff_m4v_muxer = {
251  .name = "m4v",
252  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-4 video"),
253  .extensions = "m4v",
254  .audio_codec = AV_CODEC_ID_NONE,
255  .video_codec = AV_CODEC_ID_MPEG4,
256  .write_packet = ff_raw_write_packet,
257  .flags = AVFMT_NOTIMESTAMPS,
258 };
259 #endif
260 
261 #if CONFIG_MJPEG_MUXER
262 AVOutputFormat ff_mjpeg_muxer = {
263  .name = "mjpeg",
264  .long_name = NULL_IF_CONFIG_SMALL("raw MJPEG video"),
265  .mime_type = "video/x-mjpeg",
266  .extensions = "mjpg,mjpeg",
267  .audio_codec = AV_CODEC_ID_NONE,
268  .video_codec = AV_CODEC_ID_MJPEG,
269  .write_header = force_one_stream,
270  .write_packet = ff_raw_write_packet,
271  .flags = AVFMT_NOTIMESTAMPS,
272 };
273 #endif
274 
275 #if CONFIG_SINGLEJPEG_MUXER
276 AVOutputFormat ff_singlejpeg_muxer = {
277  .name = "singlejpeg",
278  .long_name = NULL_IF_CONFIG_SMALL("JPEG single image"),
279  .mime_type = "image/jpeg",
280  .audio_codec = AV_CODEC_ID_NONE,
281  .video_codec = AV_CODEC_ID_MJPEG,
282  .write_packet = ff_raw_write_packet,
283  .flags = AVFMT_NOTIMESTAMPS,
284  .write_header = force_one_stream,
285 };
286 #endif
287 
288 #if CONFIG_MLP_MUXER
289 AVOutputFormat ff_mlp_muxer = {
290  .name = "mlp",
291  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
292  .extensions = "mlp",
293  .audio_codec = AV_CODEC_ID_MLP,
294  .video_codec = AV_CODEC_ID_NONE,
295  .write_header = force_one_stream,
296  .write_packet = ff_raw_write_packet,
297  .flags = AVFMT_NOTIMESTAMPS,
298 };
299 #endif
300 
301 #if CONFIG_MPEG1VIDEO_MUXER
302 AVOutputFormat ff_mpeg1video_muxer = {
303  .name = "mpeg1video",
304  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
305  .mime_type = "video/mpeg",
306  .extensions = "mpg,mpeg,m1v",
307  .audio_codec = AV_CODEC_ID_NONE,
308  .video_codec = AV_CODEC_ID_MPEG1VIDEO,
309  .write_header = force_one_stream,
310  .write_packet = ff_raw_write_packet,
311  .flags = AVFMT_NOTIMESTAMPS,
312 };
313 #endif
314 
315 #if CONFIG_MPEG2VIDEO_MUXER
316 AVOutputFormat ff_mpeg2video_muxer = {
317  .name = "mpeg2video",
318  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
319  .extensions = "m2v",
320  .audio_codec = AV_CODEC_ID_NONE,
321  .video_codec = AV_CODEC_ID_MPEG2VIDEO,
322  .write_header = force_one_stream,
323  .write_packet = ff_raw_write_packet,
324  .flags = AVFMT_NOTIMESTAMPS,
325 };
326 #endif
327 
328 #if CONFIG_RAWVIDEO_MUXER
329 AVOutputFormat ff_rawvideo_muxer = {
330  .name = "rawvideo",
331  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
332  .extensions = "yuv,rgb",
333  .audio_codec = AV_CODEC_ID_NONE,
334  .video_codec = AV_CODEC_ID_RAWVIDEO,
335  .write_packet = ff_raw_write_packet,
336  .flags = AVFMT_NOTIMESTAMPS,
337 };
338 #endif
339 
340 #if CONFIG_TRUEHD_MUXER
341 AVOutputFormat ff_truehd_muxer = {
342  .name = "truehd",
343  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
344  .extensions = "thd",
345  .audio_codec = AV_CODEC_ID_TRUEHD,
346  .video_codec = AV_CODEC_ID_NONE,
347  .write_header = force_one_stream,
348  .write_packet = ff_raw_write_packet,
349  .flags = AVFMT_NOTIMESTAMPS,
350 };
351 #endif
352 
353 #if CONFIG_VC1_MUXER
354 AVOutputFormat ff_vc1_muxer = {
355  .name = "vc1",
356  .long_name = NULL_IF_CONFIG_SMALL("raw VC-1 video"),
357  .extensions = "vc1",
358  .audio_codec = AV_CODEC_ID_NONE,
359  .video_codec = AV_CODEC_ID_VC1,
360  .write_header = force_one_stream,
361  .write_packet = ff_raw_write_packet,
362  .flags = AVFMT_NOTIMESTAMPS,
363 };
364 #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:1424
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:204
static AVPacket pkt
Format I/O context.
Definition: avformat.h:1273
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1341
uint8_t * data
Definition: avcodec.h:1423
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:390
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:178
#define av_log(a,...)
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1292
#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:175
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:861
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1329
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:160
const char * name
Definition: avformat.h:513
int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawenc.c:26
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:107
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:472
AVIOContext * pb
I/O context.
Definition: avformat.h:1315
main external API structure.
Definition: avcodec.h:1502
Main libavformat public API header.
if(ret< 0)
Definition: vf_mcdeint.c:280
int channels
number of audio channels
Definition: avcodec.h:2263
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:327
This structure stores compressed data.
Definition: avcodec.h:1400