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
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 
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_APTX_MUXER
96  .name = "aptx",
97  .long_name = NULL_IF_CONFIG_SMALL("raw aptX (Audio Processing Technology for Bluetooth)"),
98  .extensions = "aptx",
99  .audio_codec = AV_CODEC_ID_APTX,
100  .video_codec = AV_CODEC_ID_NONE,
101  .write_header = force_one_stream,
102  .write_packet = ff_raw_write_packet,
103  .flags = AVFMT_NOTIMESTAMPS,
104 };
105 #endif
106 
107 #if CONFIG_APTX_HD_MUXER
109  .name = "aptx_hd",
110  .long_name = NULL_IF_CONFIG_SMALL("raw aptX HD (Audio Processing Technology for Bluetooth)"),
111  .extensions = "aptxhd",
112  .audio_codec = AV_CODEC_ID_APTX_HD,
113  .video_codec = AV_CODEC_ID_NONE,
114  .write_header = force_one_stream,
115  .write_packet = ff_raw_write_packet,
116  .flags = AVFMT_NOTIMESTAMPS,
117 };
118 #endif
119 
120 #if CONFIG_CAVSVIDEO_MUXER
122  .name = "cavsvideo",
123  .long_name = NULL_IF_CONFIG_SMALL("raw Chinese AVS (Audio Video Standard) video"),
124  .extensions = "cavs",
125  .audio_codec = AV_CODEC_ID_NONE,
126  .video_codec = AV_CODEC_ID_CAVS,
127  .write_header = force_one_stream,
128  .write_packet = ff_raw_write_packet,
129  .flags = AVFMT_NOTIMESTAMPS,
130 };
131 #endif
132 
133 #if CONFIG_CODEC2RAW_MUXER
135  .name = "codec2raw",
136  .long_name = NULL_IF_CONFIG_SMALL("raw codec2 muxer"),
137  .audio_codec = AV_CODEC_ID_CODEC2,
138  .video_codec = AV_CODEC_ID_NONE,
139  .write_header = force_one_stream,
140  .write_packet = ff_raw_write_packet,
141  .flags = AVFMT_NOTIMESTAMPS,
142 };
143 #endif
144 
145 
146 #if CONFIG_DATA_MUXER
148  .name = "data",
149  .long_name = NULL_IF_CONFIG_SMALL("raw data"),
150  .write_header = force_one_stream,
151  .write_packet = ff_raw_write_packet,
152  .flags = AVFMT_NOTIMESTAMPS,
153 };
154 #endif
155 
156 #if CONFIG_DIRAC_MUXER
158  .name = "dirac",
159  .long_name = NULL_IF_CONFIG_SMALL("raw Dirac"),
160  .extensions = "drc,vc2",
161  .audio_codec = AV_CODEC_ID_NONE,
162  .video_codec = AV_CODEC_ID_DIRAC,
163  .write_header = force_one_stream,
164  .write_packet = ff_raw_write_packet,
165  .flags = AVFMT_NOTIMESTAMPS,
166 };
167 #endif
168 
169 #if CONFIG_DNXHD_MUXER
171  .name = "dnxhd",
172  .long_name = NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
173  .extensions = "dnxhd,dnxhr",
174  .audio_codec = AV_CODEC_ID_NONE,
175  .video_codec = AV_CODEC_ID_DNXHD,
176  .write_header = force_one_stream,
177  .write_packet = ff_raw_write_packet,
178  .flags = AVFMT_NOTIMESTAMPS,
179 };
180 #endif
181 
182 #if CONFIG_DTS_MUXER
184  .name = "dts",
185  .long_name = NULL_IF_CONFIG_SMALL("raw DTS"),
186  .mime_type = "audio/x-dca",
187  .extensions = "dts",
188  .audio_codec = AV_CODEC_ID_DTS,
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_EAC3_MUXER
198  .name = "eac3",
199  .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
200  .mime_type = "audio/x-eac3",
201  .extensions = "eac3",
202  .audio_codec = AV_CODEC_ID_EAC3,
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_G722_MUXER
212  .name = "g722",
213  .long_name = NULL_IF_CONFIG_SMALL("raw G.722"),
214  .mime_type = "audio/G722",
215  .extensions = "g722",
216  .audio_codec = AV_CODEC_ID_ADPCM_G722,
217  .video_codec = AV_CODEC_ID_NONE,
218  .write_header = force_one_stream,
219  .write_packet = ff_raw_write_packet,
220  .flags = AVFMT_NOTIMESTAMPS,
221 };
222 #endif
223 
224 #if CONFIG_G723_1_MUXER
226  .name = "g723_1",
227  .long_name = NULL_IF_CONFIG_SMALL("raw G.723.1"),
228  .mime_type = "audio/g723",
229  .extensions = "tco,rco",
230  .audio_codec = AV_CODEC_ID_G723_1,
231  .video_codec = AV_CODEC_ID_NONE,
232  .write_header = force_one_stream,
233  .write_packet = ff_raw_write_packet,
234  .flags = AVFMT_NOTIMESTAMPS,
235 };
236 #endif
237 
238 #if CONFIG_G726_MUXER
240  .name = "g726",
241  .long_name = NULL_IF_CONFIG_SMALL("raw big-endian G.726 (\"left-justified\")"),
242  .audio_codec = AV_CODEC_ID_ADPCM_G726,
243  .video_codec = AV_CODEC_ID_NONE,
244  .write_header = force_one_stream,
245  .write_packet = ff_raw_write_packet,
246  .flags = AVFMT_NOTIMESTAMPS,
247 };
248 #endif
249 
250 #if CONFIG_G726LE_MUXER
252  .name = "g726le",
253  .long_name = NULL_IF_CONFIG_SMALL("raw little-endian G.726 (\"right-justified\")"),
254  .audio_codec = AV_CODEC_ID_ADPCM_G726LE,
255  .video_codec = AV_CODEC_ID_NONE,
256  .write_header = force_one_stream,
257  .write_packet = ff_raw_write_packet,
258  .flags = AVFMT_NOTIMESTAMPS,
259 };
260 #endif
261 
262 #if CONFIG_GSM_MUXER
264  .name = "gsm",
265  .long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
266  .mime_type = "audio/x-gsm",
267  .extensions = "gsm",
268  .audio_codec = AV_CODEC_ID_GSM,
269  .video_codec = AV_CODEC_ID_NONE,
270  .write_header = force_one_stream,
271  .write_packet = ff_raw_write_packet,
272  .flags = AVFMT_NOTIMESTAMPS,
273 };
274 #endif
275 
276 #if CONFIG_H261_MUXER
278  .name = "h261",
279  .long_name = NULL_IF_CONFIG_SMALL("raw H.261"),
280  .mime_type = "video/x-h261",
281  .extensions = "h261",
282  .audio_codec = AV_CODEC_ID_NONE,
283  .video_codec = AV_CODEC_ID_H261,
284  .write_header = force_one_stream,
285  .write_packet = ff_raw_write_packet,
286  .flags = AVFMT_NOTIMESTAMPS,
287 };
288 #endif
289 
290 #if CONFIG_H263_MUXER
292  .name = "h263",
293  .long_name = NULL_IF_CONFIG_SMALL("raw H.263"),
294  .mime_type = "video/x-h263",
295  .extensions = "h263",
296  .audio_codec = AV_CODEC_ID_NONE,
297  .video_codec = AV_CODEC_ID_H263,
298  .write_header = force_one_stream,
299  .write_packet = ff_raw_write_packet,
300  .flags = AVFMT_NOTIMESTAMPS,
301 };
302 #endif
303 
304 #if CONFIG_H264_MUXER
305 static int h264_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
306 {
307  AVStream *st = s->streams[0];
308  if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
309  AV_RB24(pkt->data) != 0x000001)
310  return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
311  return 1;
312 }
313 
315  .name = "h264",
316  .long_name = NULL_IF_CONFIG_SMALL("raw H.264 video"),
317  .extensions = "h264,264",
318  .audio_codec = AV_CODEC_ID_NONE,
319  .video_codec = AV_CODEC_ID_H264,
320  .write_header = force_one_stream,
321  .write_packet = ff_raw_write_packet,
322  .check_bitstream = h264_check_bitstream,
323  .flags = AVFMT_NOTIMESTAMPS,
324 };
325 #endif
326 
327 #if CONFIG_HEVC_MUXER
328 static int hevc_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
329 {
330  AVStream *st = s->streams[0];
331  if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
332  AV_RB24(pkt->data) != 0x000001)
333  return ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL);
334  return 1;
335 }
336 
338  .name = "hevc",
339  .long_name = NULL_IF_CONFIG_SMALL("raw HEVC video"),
340  .extensions = "hevc,h265,265",
341  .audio_codec = AV_CODEC_ID_NONE,
342  .video_codec = AV_CODEC_ID_HEVC,
343  .write_header = force_one_stream,
344  .write_packet = ff_raw_write_packet,
345  .check_bitstream = hevc_check_bitstream,
346  .flags = AVFMT_NOTIMESTAMPS,
347 };
348 #endif
349 
350 #if CONFIG_M4V_MUXER
352  .name = "m4v",
353  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-4 video"),
354  .extensions = "m4v",
355  .audio_codec = AV_CODEC_ID_NONE,
356  .video_codec = AV_CODEC_ID_MPEG4,
357  .write_header = force_one_stream,
358  .write_packet = ff_raw_write_packet,
359  .flags = AVFMT_NOTIMESTAMPS,
360 };
361 #endif
362 
363 #if CONFIG_MJPEG_MUXER
365  .name = "mjpeg",
366  .long_name = NULL_IF_CONFIG_SMALL("raw MJPEG video"),
367  .mime_type = "video/x-mjpeg",
368  .extensions = "mjpg,mjpeg",
369  .audio_codec = AV_CODEC_ID_NONE,
370  .video_codec = AV_CODEC_ID_MJPEG,
371  .write_header = force_one_stream,
372  .write_packet = ff_raw_write_packet,
373  .flags = AVFMT_NOTIMESTAMPS,
374 };
375 #endif
376 
377 #if CONFIG_SINGLEJPEG_MUXER
379  .name = "singlejpeg",
380  .long_name = NULL_IF_CONFIG_SMALL("JPEG single image"),
381  .mime_type = "image/jpeg",
382  .audio_codec = AV_CODEC_ID_NONE,
383  .video_codec = AV_CODEC_ID_MJPEG,
384  .write_packet = ff_raw_write_packet,
385  .flags = AVFMT_NOTIMESTAMPS,
386  .write_header = force_one_stream,
387 };
388 #endif
389 
390 #if CONFIG_MLP_MUXER
392  .name = "mlp",
393  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
394  .extensions = "mlp",
395  .audio_codec = AV_CODEC_ID_MLP,
396  .video_codec = AV_CODEC_ID_NONE,
397  .write_header = force_one_stream,
398  .write_packet = ff_raw_write_packet,
399  .flags = AVFMT_NOTIMESTAMPS,
400 };
401 #endif
402 
403 #if CONFIG_MP2_MUXER
405  .name = "mp2",
406  .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
407  .mime_type = "audio/mpeg",
408  .extensions = "mp2,m2a,mpa",
409  .audio_codec = AV_CODEC_ID_MP2,
410  .video_codec = AV_CODEC_ID_NONE,
411  .write_packet = ff_raw_write_packet,
412  .flags = AVFMT_NOTIMESTAMPS,
413 };
414 #endif
415 
416 #if CONFIG_MPEG1VIDEO_MUXER
418  .name = "mpeg1video",
419  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
420  .mime_type = "video/mpeg",
421  .extensions = "mpg,mpeg,m1v",
422  .audio_codec = AV_CODEC_ID_NONE,
423  .video_codec = AV_CODEC_ID_MPEG1VIDEO,
424  .write_header = force_one_stream,
425  .write_packet = ff_raw_write_packet,
426  .flags = AVFMT_NOTIMESTAMPS,
427 };
428 #endif
429 
430 #if CONFIG_MPEG2VIDEO_MUXER
432  .name = "mpeg2video",
433  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
434  .extensions = "m2v",
435  .audio_codec = AV_CODEC_ID_NONE,
436  .video_codec = AV_CODEC_ID_MPEG2VIDEO,
437  .write_header = force_one_stream,
438  .write_packet = ff_raw_write_packet,
439  .flags = AVFMT_NOTIMESTAMPS,
440 };
441 #endif
442 
443 #if CONFIG_RAWVIDEO_MUXER
445  .name = "rawvideo",
446  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
447  .extensions = "yuv,rgb",
448  .audio_codec = AV_CODEC_ID_NONE,
449  .video_codec = AV_CODEC_ID_RAWVIDEO,
450  .write_packet = ff_raw_write_packet,
451  .flags = AVFMT_NOTIMESTAMPS,
452 };
453 #endif
454 
455 #if CONFIG_SBC_MUXER
457  .name = "sbc",
458  .long_name = NULL_IF_CONFIG_SMALL("raw SBC"),
459  .mime_type = "audio/x-sbc",
460  .extensions = "sbc,msbc",
461  .audio_codec = AV_CODEC_ID_SBC,
462  .write_header = force_one_stream,
463  .write_packet = ff_raw_write_packet,
464  .flags = AVFMT_NOTIMESTAMPS,
465 };
466 #endif
467 
468 #if CONFIG_TRUEHD_MUXER
470  .name = "truehd",
471  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
472  .extensions = "thd",
473  .audio_codec = AV_CODEC_ID_TRUEHD,
474  .video_codec = AV_CODEC_ID_NONE,
475  .write_header = force_one_stream,
476  .write_packet = ff_raw_write_packet,
477  .flags = AVFMT_NOTIMESTAMPS,
478 };
479 #endif
480 
481 #if CONFIG_VC1_MUXER
483  .name = "vc1",
484  .long_name = NULL_IF_CONFIG_SMALL("raw VC-1 video"),
485  .extensions = "vc1",
486  .audio_codec = AV_CODEC_ID_NONE,
487  .video_codec = AV_CODEC_ID_VC1,
488  .write_header = force_one_stream,
489  .write_packet = ff_raw_write_packet,
490  .flags = AVFMT_NOTIMESTAMPS,
491 };
492 #endif
AVOutputFormat ff_m4v_muxer
#define NULL
Definition: coverity.c:32
Bytestream IO Context.
Definition: avio.h:161
AVOutputFormat ff_g726_muxer
static int force_one_stream(AVFormatContext *s)
Definition: rawenc.c:35
int size
Definition: avcodec.h:1431
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
AVOutputFormat ff_mpeg1video_muxer
AVOutputFormat ff_mp2_muxer
static AVPacket pkt
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3876
AVOutputFormat ff_data_muxer
AVOutputFormat ff_dirac_muxer
Format I/O context.
Definition: avformat.h:1351
AVOutputFormat ff_eac3_muxer
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:1419
AVOutputFormat ff_g722_muxer
uint8_t * data
Definition: avcodec.h:1430
AVOutputFormat ff_adx_muxer
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:218
#define av_log(a,...)
AVOutputFormat ff_h261_muxer
struct AVOutputFormat * oformat
The output container format.
Definition: avformat.h:1370
AVOutputFormat ff_hevc_muxer
#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:186
AVOutputFormat ff_h264_muxer
AVOutputFormat ff_aptx_muxer
AVOutputFormat ff_sbc_muxer
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1407
AVOutputFormat ff_rawvideo_muxer
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
AVOutputFormat ff_g723_1_muxer
AVOutputFormat ff_gsm_muxer
const char * name
Definition: avformat.h:507
#define s(width, name)
Definition: cbs_vp9.c:257
int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rawenc.c:29
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
Stream structure.
Definition: avformat.h:874
#define AVFMT_NOTIMESTAMPS
Format does not need / have any timestamps.
Definition: avformat.h:469
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
AVOutputFormat ff_truehd_muxer
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:1393
AVOutputFormat ff_mjpeg_muxer
AVOutputFormat ff_h263_muxer
AVOutputFormat ff_mpeg2video_muxer
AVOutputFormat ff_dts_muxer
AVOutputFormat ff_aptx_hd_muxer
AVOutputFormat ff_singlejpeg_muxer
AVOutputFormat ff_g726le_muxer
AVOutputFormat ff_vc1_muxer
AVOutputFormat ff_cavsvideo_muxer
Main libavformat public API header.
if(ret< 0)
Definition: vf_mcdeint.c:279
AVOutputFormat ff_ac3_muxer
as in Berlin toast format
Definition: avcodec.h:569
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition: utils.c:5490
int channels
Audio only.
Definition: avcodec.h:3990
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:377
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1021
AVOutputFormat ff_mlp_muxer
This structure stores compressed data.
Definition: avcodec.h:1407
AVOutputFormat ff_codec2raw_muxer
AVOutputFormat ff_dnxhd_muxer