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 "libavutil/intreadwrite.h"
24 
25 #include "avformat.h"
26 #include "rawenc.h"
27 #include "internal.h"
28 
30 {
31  avio_write(s->pb, pkt->data, pkt->size);
32  return 0;
33 }
34 
36 {
37  if (s->nb_streams != 1) {
38  av_log(s, AV_LOG_ERROR, "%s files have exactly one stream\n",
39  s->oformat->name);
40  return AVERROR(EINVAL);
41  }
42  return 0;
43 }
44 
45 /* Note: Do not forget to add new entries to the Makefile as well. */
46 
47 #if CONFIG_AC3_MUXER
48 AVOutputFormat ff_ac3_muxer = {
49  .name = "ac3",
50  .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"),
51  .mime_type = "audio/x-ac3",
52  .extensions = "ac3",
53  .audio_codec = AV_CODEC_ID_AC3,
54  .video_codec = AV_CODEC_ID_NONE,
55  .write_header = force_one_stream,
56  .write_packet = ff_raw_write_packet,
57  .flags = AVFMT_NOTIMESTAMPS,
58 };
59 #endif
60 
61 #if CONFIG_ADX_MUXER
62 
63 static int adx_write_trailer(AVFormatContext *s)
64 {
65  AVIOContext *pb = s->pb;
66  AVCodecParameters *par = s->streams[0]->codecpar;
67 
68  if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
69  int64_t file_size = avio_tell(pb);
70  uint64_t sample_count = (file_size - 36) / par->channels / 18 * 32;
71  if (sample_count <= UINT32_MAX) {
72  avio_seek(pb, 12, SEEK_SET);
73  avio_wb32(pb, sample_count);
74  avio_seek(pb, file_size, SEEK_SET);
75  }
76  }
77 
78  return 0;
79 }
80 
81 AVOutputFormat ff_adx_muxer = {
82  .name = "adx",
83  .long_name = NULL_IF_CONFIG_SMALL("CRI ADX"),
84  .extensions = "adx",
85  .audio_codec = AV_CODEC_ID_ADPCM_ADX,
86  .video_codec = AV_CODEC_ID_NONE,
87  .write_header = force_one_stream,
88  .write_packet = ff_raw_write_packet,
89  .write_trailer = adx_write_trailer,
90  .flags = AVFMT_NOTIMESTAMPS,
91 };
92 #endif
93 
94 #if CONFIG_CAVSVIDEO_MUXER
95 AVOutputFormat ff_cavsvideo_muxer = {
96  .name = "cavsvideo",
97  .long_name = NULL_IF_CONFIG_SMALL("raw Chinese AVS (Audio Video Standard) video"),
98  .extensions = "cavs",
99  .audio_codec = AV_CODEC_ID_NONE,
100  .video_codec = AV_CODEC_ID_CAVS,
101  .write_header = force_one_stream,
102  .write_packet = ff_raw_write_packet,
103  .flags = AVFMT_NOTIMESTAMPS,
104 };
105 #endif
106 
107 #if CONFIG_DATA_MUXER
108 AVOutputFormat ff_data_muxer = {
109  .name = "data",
110  .long_name = NULL_IF_CONFIG_SMALL("raw data"),
111  .write_header = force_one_stream,
112  .write_packet = ff_raw_write_packet,
113  .flags = AVFMT_NOTIMESTAMPS,
114 };
115 #endif
116 
117 #if CONFIG_DIRAC_MUXER
118 AVOutputFormat ff_dirac_muxer = {
119  .name = "dirac",
120  .long_name = NULL_IF_CONFIG_SMALL("raw Dirac"),
121  .extensions = "drc,vc2",
122  .audio_codec = AV_CODEC_ID_NONE,
123  .video_codec = AV_CODEC_ID_DIRAC,
124  .write_header = force_one_stream,
125  .write_packet = ff_raw_write_packet,
126  .flags = AVFMT_NOTIMESTAMPS,
127 };
128 #endif
129 
130 #if CONFIG_DNXHD_MUXER
131 AVOutputFormat ff_dnxhd_muxer = {
132  .name = "dnxhd",
133  .long_name = NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
134  .extensions = "dnxhd,dnxhr",
135  .audio_codec = AV_CODEC_ID_NONE,
136  .video_codec = AV_CODEC_ID_DNXHD,
137  .write_header = force_one_stream,
138  .write_packet = ff_raw_write_packet,
139  .flags = AVFMT_NOTIMESTAMPS,
140 };
141 #endif
142 
143 #if CONFIG_DTS_MUXER
144 AVOutputFormat ff_dts_muxer = {
145  .name = "dts",
146  .long_name = NULL_IF_CONFIG_SMALL("raw DTS"),
147  .mime_type = "audio/x-dca",
148  .extensions = "dts",
149  .audio_codec = AV_CODEC_ID_DTS,
150  .video_codec = AV_CODEC_ID_NONE,
151  .write_header = force_one_stream,
152  .write_packet = ff_raw_write_packet,
153  .flags = AVFMT_NOTIMESTAMPS,
154 };
155 #endif
156 
157 #if CONFIG_EAC3_MUXER
158 AVOutputFormat ff_eac3_muxer = {
159  .name = "eac3",
160  .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
161  .mime_type = "audio/x-eac3",
162  .extensions = "eac3",
163  .audio_codec = AV_CODEC_ID_EAC3,
164  .video_codec = AV_CODEC_ID_NONE,
165  .write_header = force_one_stream,
166  .write_packet = ff_raw_write_packet,
167  .flags = AVFMT_NOTIMESTAMPS,
168 };
169 #endif
170 
171 #if CONFIG_G722_MUXER
172 AVOutputFormat ff_g722_muxer = {
173  .name = "g722",
174  .long_name = NULL_IF_CONFIG_SMALL("raw G.722"),
175  .mime_type = "audio/G722",
176  .extensions = "g722",
177  .audio_codec = AV_CODEC_ID_ADPCM_G722,
178  .video_codec = AV_CODEC_ID_NONE,
179  .write_header = force_one_stream,
180  .write_packet = ff_raw_write_packet,
181  .flags = AVFMT_NOTIMESTAMPS,
182 };
183 #endif
184 
185 #if CONFIG_G723_1_MUXER
186 AVOutputFormat ff_g723_1_muxer = {
187  .name = "g723_1",
188  .long_name = NULL_IF_CONFIG_SMALL("raw G.723.1"),
189  .mime_type = "audio/g723",
190  .extensions = "tco,rco",
191  .audio_codec = AV_CODEC_ID_G723_1,
192  .video_codec = AV_CODEC_ID_NONE,
193  .write_header = force_one_stream,
194  .write_packet = ff_raw_write_packet,
195  .flags = AVFMT_NOTIMESTAMPS,
196 };
197 #endif
198 
199 #if CONFIG_G726_MUXER
200 AVOutputFormat ff_g726_muxer = {
201  .name = "g726",
202  .long_name = NULL_IF_CONFIG_SMALL("raw big-endian G.726 (\"left-justified\")"),
203  .audio_codec = AV_CODEC_ID_ADPCM_G726,
204  .video_codec = AV_CODEC_ID_NONE,
205  .write_header = force_one_stream,
206  .write_packet = ff_raw_write_packet,
207  .flags = AVFMT_NOTIMESTAMPS,
208 };
209 #endif
210 
211 #if CONFIG_G726LE_MUXER
212 AVOutputFormat ff_g726le_muxer = {
213  .name = "g726le",
214  .long_name = NULL_IF_CONFIG_SMALL("raw little-endian G.726 (\"right-justified\")"),
215  .audio_codec = AV_CODEC_ID_ADPCM_G726LE,
216  .video_codec = AV_CODEC_ID_NONE,
217  .write_header = force_one_stream,
218  .write_packet = ff_raw_write_packet,
219  .flags = AVFMT_NOTIMESTAMPS,
220 };
221 #endif
222 
223 #if CONFIG_GSM_MUXER
224 AVOutputFormat ff_gsm_muxer = {
225  .name = "gsm",
226  .long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
227  .mime_type = "audio/x-gsm",
228  .extensions = "gsm",
229  .audio_codec = AV_CODEC_ID_GSM,
230  .video_codec = AV_CODEC_ID_NONE,
231  .write_header = force_one_stream,
232  .write_packet = ff_raw_write_packet,
233  .flags = AVFMT_NOTIMESTAMPS,
234 };
235 #endif
236 
237 #if CONFIG_H261_MUXER
238 AVOutputFormat ff_h261_muxer = {
239  .name = "h261",
240  .long_name = NULL_IF_CONFIG_SMALL("raw H.261"),
241  .mime_type = "video/x-h261",
242  .extensions = "h261",
243  .audio_codec = AV_CODEC_ID_NONE,
244  .video_codec = AV_CODEC_ID_H261,
245  .write_header = force_one_stream,
246  .write_packet = ff_raw_write_packet,
247  .flags = AVFMT_NOTIMESTAMPS,
248 };
249 #endif
250 
251 #if CONFIG_H263_MUXER
252 AVOutputFormat ff_h263_muxer = {
253  .name = "h263",
254  .long_name = NULL_IF_CONFIG_SMALL("raw H.263"),
255  .mime_type = "video/x-h263",
256  .extensions = "h263",
257  .audio_codec = AV_CODEC_ID_NONE,
258  .video_codec = AV_CODEC_ID_H263,
259  .write_header = force_one_stream,
260  .write_packet = ff_raw_write_packet,
261  .flags = AVFMT_NOTIMESTAMPS,
262 };
263 #endif
264 
265 #if CONFIG_H264_MUXER
266 static int h264_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
267 {
268  AVStream *st = s->streams[0];
269  if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
270  AV_RB24(pkt->data) != 0x000001)
271  return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
272  return 1;
273 }
274 
275 AVOutputFormat ff_h264_muxer = {
276  .name = "h264",
277  .long_name = NULL_IF_CONFIG_SMALL("raw H.264 video"),
278  .extensions = "h264,264",
279  .audio_codec = AV_CODEC_ID_NONE,
280  .video_codec = AV_CODEC_ID_H264,
281  .write_header = force_one_stream,
282  .write_packet = ff_raw_write_packet,
283  .check_bitstream = h264_check_bitstream,
284  .flags = AVFMT_NOTIMESTAMPS,
285 };
286 #endif
287 
288 #if CONFIG_HEVC_MUXER
289 static int hevc_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
290 {
291  AVStream *st = s->streams[0];
292  if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
293  AV_RB24(pkt->data) != 0x000001)
294  return ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL);
295  return 1;
296 }
297 
298 AVOutputFormat ff_hevc_muxer = {
299  .name = "hevc",
300  .long_name = NULL_IF_CONFIG_SMALL("raw HEVC video"),
301  .extensions = "hevc,h265,265",
302  .audio_codec = AV_CODEC_ID_NONE,
303  .video_codec = AV_CODEC_ID_HEVC,
304  .write_header = force_one_stream,
305  .write_packet = ff_raw_write_packet,
306  .check_bitstream = hevc_check_bitstream,
307  .flags = AVFMT_NOTIMESTAMPS,
308 };
309 #endif
310 
311 #if CONFIG_M4V_MUXER
312 AVOutputFormat ff_m4v_muxer = {
313  .name = "m4v",
314  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-4 video"),
315  .extensions = "m4v",
316  .audio_codec = AV_CODEC_ID_NONE,
317  .video_codec = AV_CODEC_ID_MPEG4,
318  .write_header = force_one_stream,
319  .write_packet = ff_raw_write_packet,
320  .flags = AVFMT_NOTIMESTAMPS,
321 };
322 #endif
323 
324 #if CONFIG_MJPEG_MUXER
325 AVOutputFormat ff_mjpeg_muxer = {
326  .name = "mjpeg",
327  .long_name = NULL_IF_CONFIG_SMALL("raw MJPEG video"),
328  .mime_type = "video/x-mjpeg",
329  .extensions = "mjpg,mjpeg",
330  .audio_codec = AV_CODEC_ID_NONE,
331  .video_codec = AV_CODEC_ID_MJPEG,
332  .write_header = force_one_stream,
333  .write_packet = ff_raw_write_packet,
334  .flags = AVFMT_NOTIMESTAMPS,
335 };
336 #endif
337 
338 #if CONFIG_SINGLEJPEG_MUXER
339 AVOutputFormat ff_singlejpeg_muxer = {
340  .name = "singlejpeg",
341  .long_name = NULL_IF_CONFIG_SMALL("JPEG single image"),
342  .mime_type = "image/jpeg",
343  .audio_codec = AV_CODEC_ID_NONE,
344  .video_codec = AV_CODEC_ID_MJPEG,
345  .write_packet = ff_raw_write_packet,
346  .flags = AVFMT_NOTIMESTAMPS,
347  .write_header = force_one_stream,
348 };
349 #endif
350 
351 #if CONFIG_MLP_MUXER
352 AVOutputFormat ff_mlp_muxer = {
353  .name = "mlp",
354  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
355  .extensions = "mlp",
356  .audio_codec = AV_CODEC_ID_MLP,
357  .video_codec = AV_CODEC_ID_NONE,
358  .write_header = force_one_stream,
359  .write_packet = ff_raw_write_packet,
360  .flags = AVFMT_NOTIMESTAMPS,
361 };
362 #endif
363 
364 #if CONFIG_MP2_MUXER
365 AVOutputFormat ff_mp2_muxer = {
366  .name = "mp2",
367  .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
368  .mime_type = "audio/mpeg",
369  .extensions = "mp2,m2a,mpa",
370  .audio_codec = AV_CODEC_ID_MP2,
371  .video_codec = AV_CODEC_ID_NONE,
372  .write_packet = ff_raw_write_packet,
373  .flags = AVFMT_NOTIMESTAMPS,
374 };
375 #endif
376 
377 #if CONFIG_MPEG1VIDEO_MUXER
378 AVOutputFormat ff_mpeg1video_muxer = {
379  .name = "mpeg1video",
380  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
381  .mime_type = "video/mpeg",
382  .extensions = "mpg,mpeg,m1v",
383  .audio_codec = AV_CODEC_ID_NONE,
384  .video_codec = AV_CODEC_ID_MPEG1VIDEO,
385  .write_header = force_one_stream,
386  .write_packet = ff_raw_write_packet,
387  .flags = AVFMT_NOTIMESTAMPS,
388 };
389 #endif
390 
391 #if CONFIG_MPEG2VIDEO_MUXER
392 AVOutputFormat ff_mpeg2video_muxer = {
393  .name = "mpeg2video",
394  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
395  .extensions = "m2v",
396  .audio_codec = AV_CODEC_ID_NONE,
397  .video_codec = AV_CODEC_ID_MPEG2VIDEO,
398  .write_header = force_one_stream,
399  .write_packet = ff_raw_write_packet,
400  .flags = AVFMT_NOTIMESTAMPS,
401 };
402 #endif
403 
404 #if CONFIG_RAWVIDEO_MUXER
405 AVOutputFormat ff_rawvideo_muxer = {
406  .name = "rawvideo",
407  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
408  .extensions = "yuv,rgb",
409  .audio_codec = AV_CODEC_ID_NONE,
410  .video_codec = AV_CODEC_ID_RAWVIDEO,
411  .write_packet = ff_raw_write_packet,
412  .flags = AVFMT_NOTIMESTAMPS,
413 };
414 #endif
415 
416 #if CONFIG_TRUEHD_MUXER
417 AVOutputFormat ff_truehd_muxer = {
418  .name = "truehd",
419  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
420  .extensions = "thd",
421  .audio_codec = AV_CODEC_ID_TRUEHD,
422  .video_codec = AV_CODEC_ID_NONE,
423  .write_header = force_one_stream,
424  .write_packet = ff_raw_write_packet,
425  .flags = AVFMT_NOTIMESTAMPS,
426 };
427 #endif
428 
429 #if CONFIG_VC1_MUXER
430 AVOutputFormat ff_vc1_muxer = {
431  .name = "vc1",
432  .long_name = NULL_IF_CONFIG_SMALL("raw VC-1 video"),
433  .extensions = "vc1",
434  .audio_codec = AV_CODEC_ID_NONE,
435  .video_codec = AV_CODEC_ID_VC1,
436  .write_header = force_one_stream,
437  .write_packet = ff_raw_write_packet,
438  .flags = AVFMT_NOTIMESTAMPS,
439 };
440 #endif
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
Bytestream IO Context.
Definition: avio.h:161
static int force_one_stream(AVFormatContext *s)
Definition: rawenc.c:35
int size
Definition: avcodec.h:1680
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:244
static AVPacket pkt
This struct describes the properties of an encoded stream.
Definition: avcodec.h:4144
Format I/O context.
Definition: avformat.h:1349
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:87
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1417
uint8_t * data
Definition: avcodec.h:1679
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:556
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:216
#define av_log(a,...)
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1368
#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:179
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1405
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:261
const char * name
Definition: avformat.h:524
int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawenc.c:29
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:219
Stream structure.
Definition: avformat.h:889
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:486
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_RB24
Definition: bytestream.h:87
AVIOContext * pb
I/O context.
Definition: avformat.h:1391
Main libavformat public API header.
if(ret< 0)
Definition: vf_mcdeint.c:279
as in Berlin toast format
Definition: avcodec.h:574
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition: utils.c:5324
int channels
Audio only.
Definition: avcodec.h:4258
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:382
AVCodecParameters * codecpar
Definition: avformat.h:1252
This structure stores compressed data.
Definition: avcodec.h:1656