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_AVS2_MUXER
122  .name = "avs2",
123  .long_name = NULL_IF_CONFIG_SMALL("raw AVS2-P2/IEEE1857.4 video"),
124  .extensions = "avs,avs2",
125  .audio_codec = AV_CODEC_ID_NONE,
126  .video_codec = AV_CODEC_ID_AVS2,
127  .write_header = force_one_stream,
128  .write_packet = ff_raw_write_packet,
129  .flags = AVFMT_NOTIMESTAMPS,
130 };
131 #endif
132 
133 #if CONFIG_CAVSVIDEO_MUXER
135  .name = "cavsvideo",
136  .long_name = NULL_IF_CONFIG_SMALL("raw Chinese AVS (Audio Video Standard) video"),
137  .extensions = "cavs",
138  .audio_codec = AV_CODEC_ID_NONE,
139  .video_codec = AV_CODEC_ID_CAVS,
140  .write_header = force_one_stream,
141  .write_packet = ff_raw_write_packet,
142  .flags = AVFMT_NOTIMESTAMPS,
143 };
144 #endif
145 
146 #if CONFIG_CODEC2RAW_MUXER
148  .name = "codec2raw",
149  .long_name = NULL_IF_CONFIG_SMALL("raw codec2 muxer"),
150  .audio_codec = AV_CODEC_ID_CODEC2,
151  .video_codec = AV_CODEC_ID_NONE,
152  .write_header = force_one_stream,
153  .write_packet = ff_raw_write_packet,
154  .flags = AVFMT_NOTIMESTAMPS,
155 };
156 #endif
157 
158 
159 #if CONFIG_DATA_MUXER
161  .name = "data",
162  .long_name = NULL_IF_CONFIG_SMALL("raw data"),
163  .write_header = force_one_stream,
164  .write_packet = ff_raw_write_packet,
165  .flags = AVFMT_NOTIMESTAMPS,
166 };
167 #endif
168 
169 #if CONFIG_DIRAC_MUXER
171  .name = "dirac",
172  .long_name = NULL_IF_CONFIG_SMALL("raw Dirac"),
173  .extensions = "drc,vc2",
174  .audio_codec = AV_CODEC_ID_NONE,
175  .video_codec = AV_CODEC_ID_DIRAC,
176  .write_header = force_one_stream,
177  .write_packet = ff_raw_write_packet,
178  .flags = AVFMT_NOTIMESTAMPS,
179 };
180 #endif
181 
182 #if CONFIG_DNXHD_MUXER
184  .name = "dnxhd",
185  .long_name = NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
186  .extensions = "dnxhd,dnxhr",
187  .audio_codec = AV_CODEC_ID_NONE,
188  .video_codec = AV_CODEC_ID_DNXHD,
189  .write_header = force_one_stream,
190  .write_packet = ff_raw_write_packet,
191  .flags = AVFMT_NOTIMESTAMPS,
192 };
193 #endif
194 
195 #if CONFIG_DTS_MUXER
197  .name = "dts",
198  .long_name = NULL_IF_CONFIG_SMALL("raw DTS"),
199  .mime_type = "audio/x-dca",
200  .extensions = "dts",
201  .audio_codec = AV_CODEC_ID_DTS,
202  .video_codec = AV_CODEC_ID_NONE,
203  .write_header = force_one_stream,
204  .write_packet = ff_raw_write_packet,
205  .flags = AVFMT_NOTIMESTAMPS,
206 };
207 #endif
208 
209 #if CONFIG_EAC3_MUXER
211  .name = "eac3",
212  .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
213  .mime_type = "audio/x-eac3",
214  .extensions = "eac3",
215  .audio_codec = AV_CODEC_ID_EAC3,
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_G722_MUXER
225  .name = "g722",
226  .long_name = NULL_IF_CONFIG_SMALL("raw G.722"),
227  .mime_type = "audio/G722",
228  .extensions = "g722",
229  .audio_codec = AV_CODEC_ID_ADPCM_G722,
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_G723_1_MUXER
239  .name = "g723_1",
240  .long_name = NULL_IF_CONFIG_SMALL("raw G.723.1"),
241  .mime_type = "audio/g723",
242  .extensions = "tco,rco",
243  .audio_codec = AV_CODEC_ID_G723_1,
244  .video_codec = AV_CODEC_ID_NONE,
245  .write_header = force_one_stream,
246  .write_packet = ff_raw_write_packet,
247  .flags = AVFMT_NOTIMESTAMPS,
248 };
249 #endif
250 
251 #if CONFIG_G726_MUXER
253  .name = "g726",
254  .long_name = NULL_IF_CONFIG_SMALL("raw big-endian G.726 (\"left-justified\")"),
255  .audio_codec = AV_CODEC_ID_ADPCM_G726,
256  .video_codec = AV_CODEC_ID_NONE,
257  .write_header = force_one_stream,
258  .write_packet = ff_raw_write_packet,
259  .flags = AVFMT_NOTIMESTAMPS,
260 };
261 #endif
262 
263 #if CONFIG_G726LE_MUXER
265  .name = "g726le",
266  .long_name = NULL_IF_CONFIG_SMALL("raw little-endian G.726 (\"right-justified\")"),
267  .audio_codec = AV_CODEC_ID_ADPCM_G726LE,
268  .video_codec = AV_CODEC_ID_NONE,
269  .write_header = force_one_stream,
270  .write_packet = ff_raw_write_packet,
271  .flags = AVFMT_NOTIMESTAMPS,
272 };
273 #endif
274 
275 #if CONFIG_GSM_MUXER
277  .name = "gsm",
278  .long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
279  .mime_type = "audio/x-gsm",
280  .extensions = "gsm",
281  .audio_codec = AV_CODEC_ID_GSM,
282  .video_codec = AV_CODEC_ID_NONE,
283  .write_header = force_one_stream,
284  .write_packet = ff_raw_write_packet,
285  .flags = AVFMT_NOTIMESTAMPS,
286 };
287 #endif
288 
289 #if CONFIG_H261_MUXER
291  .name = "h261",
292  .long_name = NULL_IF_CONFIG_SMALL("raw H.261"),
293  .mime_type = "video/x-h261",
294  .extensions = "h261",
295  .audio_codec = AV_CODEC_ID_NONE,
296  .video_codec = AV_CODEC_ID_H261,
297  .write_header = force_one_stream,
298  .write_packet = ff_raw_write_packet,
299  .flags = AVFMT_NOTIMESTAMPS,
300 };
301 #endif
302 
303 #if CONFIG_H263_MUXER
305  .name = "h263",
306  .long_name = NULL_IF_CONFIG_SMALL("raw H.263"),
307  .mime_type = "video/x-h263",
308  .extensions = "h263",
309  .audio_codec = AV_CODEC_ID_NONE,
310  .video_codec = AV_CODEC_ID_H263,
311  .write_header = force_one_stream,
312  .write_packet = ff_raw_write_packet,
313  .flags = AVFMT_NOTIMESTAMPS,
314 };
315 #endif
316 
317 #if CONFIG_H264_MUXER
318 static int h264_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
319 {
320  AVStream *st = s->streams[0];
321  if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
322  AV_RB24(pkt->data) != 0x000001)
323  return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
324  return 1;
325 }
326 
328  .name = "h264",
329  .long_name = NULL_IF_CONFIG_SMALL("raw H.264 video"),
330  .extensions = "h264,264",
331  .audio_codec = AV_CODEC_ID_NONE,
332  .video_codec = AV_CODEC_ID_H264,
333  .write_header = force_one_stream,
334  .write_packet = ff_raw_write_packet,
335  .check_bitstream = h264_check_bitstream,
336  .flags = AVFMT_NOTIMESTAMPS,
337 };
338 #endif
339 
340 #if CONFIG_HEVC_MUXER
341 static int hevc_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
342 {
343  AVStream *st = s->streams[0];
344  if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
345  AV_RB24(pkt->data) != 0x000001)
346  return ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL);
347  return 1;
348 }
349 
351  .name = "hevc",
352  .long_name = NULL_IF_CONFIG_SMALL("raw HEVC video"),
353  .extensions = "hevc,h265,265",
354  .audio_codec = AV_CODEC_ID_NONE,
355  .video_codec = AV_CODEC_ID_HEVC,
356  .write_header = force_one_stream,
357  .write_packet = ff_raw_write_packet,
358  .check_bitstream = hevc_check_bitstream,
359  .flags = AVFMT_NOTIMESTAMPS,
360 };
361 #endif
362 
363 #if CONFIG_M4V_MUXER
365  .name = "m4v",
366  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-4 video"),
367  .extensions = "m4v",
368  .audio_codec = AV_CODEC_ID_NONE,
369  .video_codec = AV_CODEC_ID_MPEG4,
370  .write_header = force_one_stream,
371  .write_packet = ff_raw_write_packet,
372  .flags = AVFMT_NOTIMESTAMPS,
373 };
374 #endif
375 
376 #if CONFIG_MJPEG_MUXER
378  .name = "mjpeg",
379  .long_name = NULL_IF_CONFIG_SMALL("raw MJPEG video"),
380  .mime_type = "video/x-mjpeg",
381  .extensions = "mjpg,mjpeg",
382  .audio_codec = AV_CODEC_ID_NONE,
383  .video_codec = AV_CODEC_ID_MJPEG,
384  .write_header = force_one_stream,
385  .write_packet = ff_raw_write_packet,
386  .flags = AVFMT_NOTIMESTAMPS,
387 };
388 #endif
389 
390 #if CONFIG_SINGLEJPEG_MUXER
392  .name = "singlejpeg",
393  .long_name = NULL_IF_CONFIG_SMALL("JPEG single image"),
394  .mime_type = "image/jpeg",
395  .audio_codec = AV_CODEC_ID_NONE,
396  .video_codec = AV_CODEC_ID_MJPEG,
397  .write_packet = ff_raw_write_packet,
398  .flags = AVFMT_NOTIMESTAMPS,
399  .write_header = force_one_stream,
400 };
401 #endif
402 
403 #if CONFIG_MLP_MUXER
405  .name = "mlp",
406  .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
407  .extensions = "mlp",
408  .audio_codec = AV_CODEC_ID_MLP,
409  .video_codec = AV_CODEC_ID_NONE,
410  .write_header = force_one_stream,
411  .write_packet = ff_raw_write_packet,
412  .flags = AVFMT_NOTIMESTAMPS,
413 };
414 #endif
415 
416 #if CONFIG_MP2_MUXER
418  .name = "mp2",
419  .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
420  .mime_type = "audio/mpeg",
421  .extensions = "mp2,m2a,mpa",
422  .audio_codec = AV_CODEC_ID_MP2,
423  .video_codec = AV_CODEC_ID_NONE,
424  .write_packet = ff_raw_write_packet,
425  .flags = AVFMT_NOTIMESTAMPS,
426 };
427 #endif
428 
429 #if CONFIG_MPEG1VIDEO_MUXER
431  .name = "mpeg1video",
432  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
433  .mime_type = "video/mpeg",
434  .extensions = "mpg,mpeg,m1v",
435  .audio_codec = AV_CODEC_ID_NONE,
436  .video_codec = AV_CODEC_ID_MPEG1VIDEO,
437  .write_header = force_one_stream,
438  .write_packet = ff_raw_write_packet,
439  .flags = AVFMT_NOTIMESTAMPS,
440 };
441 #endif
442 
443 #if CONFIG_MPEG2VIDEO_MUXER
445  .name = "mpeg2video",
446  .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
447  .extensions = "m2v",
448  .audio_codec = AV_CODEC_ID_NONE,
449  .video_codec = AV_CODEC_ID_MPEG2VIDEO,
450  .write_header = force_one_stream,
451  .write_packet = ff_raw_write_packet,
452  .flags = AVFMT_NOTIMESTAMPS,
453 };
454 #endif
455 
456 #if CONFIG_RAWVIDEO_MUXER
458  .name = "rawvideo",
459  .long_name = NULL_IF_CONFIG_SMALL("raw video"),
460  .extensions = "yuv,rgb",
461  .audio_codec = AV_CODEC_ID_NONE,
462  .video_codec = AV_CODEC_ID_RAWVIDEO,
463  .write_packet = ff_raw_write_packet,
464  .flags = AVFMT_NOTIMESTAMPS,
465 };
466 #endif
467 
468 #if CONFIG_SBC_MUXER
470  .name = "sbc",
471  .long_name = NULL_IF_CONFIG_SMALL("raw SBC"),
472  .mime_type = "audio/x-sbc",
473  .extensions = "sbc,msbc",
474  .audio_codec = AV_CODEC_ID_SBC,
475  .write_header = force_one_stream,
476  .write_packet = ff_raw_write_packet,
477  .flags = AVFMT_NOTIMESTAMPS,
478 };
479 #endif
480 
481 #if CONFIG_TRUEHD_MUXER
483  .name = "truehd",
484  .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
485  .extensions = "thd",
486  .audio_codec = AV_CODEC_ID_TRUEHD,
487  .video_codec = AV_CODEC_ID_NONE,
488  .write_header = force_one_stream,
489  .write_packet = ff_raw_write_packet,
490  .flags = AVFMT_NOTIMESTAMPS,
491 };
492 #endif
493 
494 #if CONFIG_VC1_MUXER
496  .name = "vc1",
497  .long_name = NULL_IF_CONFIG_SMALL("raw VC-1 video"),
498  .extensions = "vc1",
499  .audio_codec = AV_CODEC_ID_NONE,
500  .video_codec = AV_CODEC_ID_VC1,
501  .write_header = force_one_stream,
502  .write_packet = ff_raw_write_packet,
503  .flags = AVFMT_NOTIMESTAMPS,
504 };
505 #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:1446
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_avs2_muxer
AVOutputFormat ff_mp2_muxer
static AVPacket pkt
This struct describes the properties of an encoded stream.
Definition: avcodec.h:3892
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:1445
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:576
int ff_stream_add_bitstream_filter(AVStream *st, const char *name, const char *args)
Add a bitstream filter to a stream.
Definition: utils.c:5545
int channels
Audio only.
Definition: avcodec.h:4006
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:1422
AVOutputFormat ff_codec2raw_muxer
AVOutputFormat ff_dnxhd_muxer