3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2005 Alex Beregszaszi
6 * This file is part of FFmpeg.
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.
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.
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
23 #include "libavutil/intreadwrite.h"
29 int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt)
31 avio_write(s->pb, pkt->data, pkt->size);
35 static int force_one_stream(AVFormatContext *s)
37 if (s->nb_streams != 1) {
38 av_log(s, AV_LOG_ERROR, "%s files have exactly one stream\n",
40 return AVERROR(EINVAL);
42 if ( s->oformat->audio_codec != AV_CODEC_ID_NONE
43 && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
44 av_log(s, AV_LOG_ERROR, "%s files have exactly one audio stream\n",
46 return AVERROR(EINVAL);
48 if ( s->oformat->video_codec != AV_CODEC_ID_NONE
49 && s->streams[0]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) {
50 av_log(s, AV_LOG_ERROR, "%s files have exactly one video stream\n",
52 return AVERROR(EINVAL);
57 /* Note: Do not forget to add new entries to the Makefile as well. */
60 AVOutputFormat ff_ac3_muxer = {
62 .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"),
63 .mime_type = "audio/x-ac3",
65 .audio_codec = AV_CODEC_ID_AC3,
66 .video_codec = AV_CODEC_ID_NONE,
67 .write_header = force_one_stream,
68 .write_packet = ff_raw_write_packet,
69 .flags = AVFMT_NOTIMESTAMPS,
75 static int adx_write_trailer(AVFormatContext *s)
77 AVIOContext *pb = s->pb;
78 AVCodecParameters *par = s->streams[0]->codecpar;
80 if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
81 int64_t file_size = avio_tell(pb);
82 uint64_t sample_count = (file_size - 36) / par->channels / 18 * 32;
83 if (sample_count <= UINT32_MAX) {
84 avio_seek(pb, 12, SEEK_SET);
85 avio_wb32(pb, sample_count);
86 avio_seek(pb, file_size, SEEK_SET);
93 AVOutputFormat ff_adx_muxer = {
95 .long_name = NULL_IF_CONFIG_SMALL("CRI ADX"),
97 .audio_codec = AV_CODEC_ID_ADPCM_ADX,
98 .video_codec = AV_CODEC_ID_NONE,
99 .write_header = force_one_stream,
100 .write_packet = ff_raw_write_packet,
101 .write_trailer = adx_write_trailer,
102 .flags = AVFMT_NOTIMESTAMPS,
106 #if CONFIG_APTX_MUXER
107 AVOutputFormat ff_aptx_muxer = {
109 .long_name = NULL_IF_CONFIG_SMALL("raw aptX (Audio Processing Technology for Bluetooth)"),
110 .extensions = "aptx",
111 .audio_codec = AV_CODEC_ID_APTX,
112 .video_codec = AV_CODEC_ID_NONE,
113 .write_header = force_one_stream,
114 .write_packet = ff_raw_write_packet,
115 .flags = AVFMT_NOTIMESTAMPS,
119 #if CONFIG_APTX_HD_MUXER
120 AVOutputFormat ff_aptx_hd_muxer = {
122 .long_name = NULL_IF_CONFIG_SMALL("raw aptX HD (Audio Processing Technology for Bluetooth)"),
123 .extensions = "aptxhd",
124 .audio_codec = AV_CODEC_ID_APTX_HD,
125 .video_codec = AV_CODEC_ID_NONE,
126 .write_header = force_one_stream,
127 .write_packet = ff_raw_write_packet,
128 .flags = AVFMT_NOTIMESTAMPS,
132 #if CONFIG_AVS2_MUXER
133 AVOutputFormat ff_avs2_muxer = {
135 .long_name = NULL_IF_CONFIG_SMALL("raw AVS2-P2/IEEE1857.4 video"),
136 .extensions = "avs,avs2",
137 .audio_codec = AV_CODEC_ID_NONE,
138 .video_codec = AV_CODEC_ID_AVS2,
139 .write_header = force_one_stream,
140 .write_packet = ff_raw_write_packet,
141 .flags = AVFMT_NOTIMESTAMPS,
145 #if CONFIG_CAVSVIDEO_MUXER
146 AVOutputFormat ff_cavsvideo_muxer = {
148 .long_name = NULL_IF_CONFIG_SMALL("raw Chinese AVS (Audio Video Standard) video"),
149 .extensions = "cavs",
150 .audio_codec = AV_CODEC_ID_NONE,
151 .video_codec = AV_CODEC_ID_CAVS,
152 .write_header = force_one_stream,
153 .write_packet = ff_raw_write_packet,
154 .flags = AVFMT_NOTIMESTAMPS,
158 #if CONFIG_CODEC2RAW_MUXER
159 AVOutputFormat ff_codec2raw_muxer = {
161 .long_name = NULL_IF_CONFIG_SMALL("raw codec2 muxer"),
162 .audio_codec = AV_CODEC_ID_CODEC2,
163 .video_codec = AV_CODEC_ID_NONE,
164 .write_header = force_one_stream,
165 .write_packet = ff_raw_write_packet,
166 .flags = AVFMT_NOTIMESTAMPS,
171 #if CONFIG_DATA_MUXER
172 AVOutputFormat ff_data_muxer = {
174 .long_name = NULL_IF_CONFIG_SMALL("raw data"),
175 .write_header = force_one_stream,
176 .write_packet = ff_raw_write_packet,
177 .flags = AVFMT_NOTIMESTAMPS,
181 #if CONFIG_DIRAC_MUXER
182 AVOutputFormat ff_dirac_muxer = {
184 .long_name = NULL_IF_CONFIG_SMALL("raw Dirac"),
185 .extensions = "drc,vc2",
186 .audio_codec = AV_CODEC_ID_NONE,
187 .video_codec = AV_CODEC_ID_DIRAC,
188 .write_header = force_one_stream,
189 .write_packet = ff_raw_write_packet,
190 .flags = AVFMT_NOTIMESTAMPS,
194 #if CONFIG_DNXHD_MUXER
195 AVOutputFormat ff_dnxhd_muxer = {
197 .long_name = NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"),
198 .extensions = "dnxhd,dnxhr",
199 .audio_codec = AV_CODEC_ID_NONE,
200 .video_codec = AV_CODEC_ID_DNXHD,
201 .write_header = force_one_stream,
202 .write_packet = ff_raw_write_packet,
203 .flags = AVFMT_NOTIMESTAMPS,
208 AVOutputFormat ff_dts_muxer = {
210 .long_name = NULL_IF_CONFIG_SMALL("raw DTS"),
211 .mime_type = "audio/x-dca",
213 .audio_codec = AV_CODEC_ID_DTS,
214 .video_codec = AV_CODEC_ID_NONE,
215 .write_header = force_one_stream,
216 .write_packet = ff_raw_write_packet,
217 .flags = AVFMT_NOTIMESTAMPS,
221 #if CONFIG_EAC3_MUXER
222 AVOutputFormat ff_eac3_muxer = {
224 .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"),
225 .mime_type = "audio/x-eac3",
226 .extensions = "eac3",
227 .audio_codec = AV_CODEC_ID_EAC3,
228 .video_codec = AV_CODEC_ID_NONE,
229 .write_header = force_one_stream,
230 .write_packet = ff_raw_write_packet,
231 .flags = AVFMT_NOTIMESTAMPS,
235 #if CONFIG_G722_MUXER
236 AVOutputFormat ff_g722_muxer = {
238 .long_name = NULL_IF_CONFIG_SMALL("raw G.722"),
239 .mime_type = "audio/G722",
240 .extensions = "g722",
241 .audio_codec = AV_CODEC_ID_ADPCM_G722,
242 .video_codec = AV_CODEC_ID_NONE,
243 .write_header = force_one_stream,
244 .write_packet = ff_raw_write_packet,
245 .flags = AVFMT_NOTIMESTAMPS,
249 #if CONFIG_G723_1_MUXER
250 AVOutputFormat ff_g723_1_muxer = {
252 .long_name = NULL_IF_CONFIG_SMALL("raw G.723.1"),
253 .mime_type = "audio/g723",
254 .extensions = "tco,rco",
255 .audio_codec = AV_CODEC_ID_G723_1,
256 .video_codec = AV_CODEC_ID_NONE,
257 .write_header = force_one_stream,
258 .write_packet = ff_raw_write_packet,
259 .flags = AVFMT_NOTIMESTAMPS,
263 #if CONFIG_G726_MUXER
264 AVOutputFormat ff_g726_muxer = {
266 .long_name = NULL_IF_CONFIG_SMALL("raw big-endian G.726 (\"left-justified\")"),
267 .audio_codec = AV_CODEC_ID_ADPCM_G726,
268 .video_codec = AV_CODEC_ID_NONE,
269 .write_header = force_one_stream,
270 .write_packet = ff_raw_write_packet,
271 .flags = AVFMT_NOTIMESTAMPS,
275 #if CONFIG_G726LE_MUXER
276 AVOutputFormat ff_g726le_muxer = {
278 .long_name = NULL_IF_CONFIG_SMALL("raw little-endian G.726 (\"right-justified\")"),
279 .audio_codec = AV_CODEC_ID_ADPCM_G726LE,
280 .video_codec = AV_CODEC_ID_NONE,
281 .write_header = force_one_stream,
282 .write_packet = ff_raw_write_packet,
283 .flags = AVFMT_NOTIMESTAMPS,
288 AVOutputFormat ff_gsm_muxer = {
290 .long_name = NULL_IF_CONFIG_SMALL("raw GSM"),
291 .mime_type = "audio/x-gsm",
293 .audio_codec = AV_CODEC_ID_GSM,
294 .video_codec = AV_CODEC_ID_NONE,
295 .write_header = force_one_stream,
296 .write_packet = ff_raw_write_packet,
297 .flags = AVFMT_NOTIMESTAMPS,
301 #if CONFIG_H261_MUXER
302 AVOutputFormat ff_h261_muxer = {
304 .long_name = NULL_IF_CONFIG_SMALL("raw H.261"),
305 .mime_type = "video/x-h261",
306 .extensions = "h261",
307 .audio_codec = AV_CODEC_ID_NONE,
308 .video_codec = AV_CODEC_ID_H261,
309 .write_header = force_one_stream,
310 .write_packet = ff_raw_write_packet,
311 .flags = AVFMT_NOTIMESTAMPS,
315 #if CONFIG_H263_MUXER
316 AVOutputFormat ff_h263_muxer = {
318 .long_name = NULL_IF_CONFIG_SMALL("raw H.263"),
319 .mime_type = "video/x-h263",
320 .extensions = "h263",
321 .audio_codec = AV_CODEC_ID_NONE,
322 .video_codec = AV_CODEC_ID_H263,
323 .write_header = force_one_stream,
324 .write_packet = ff_raw_write_packet,
325 .flags = AVFMT_NOTIMESTAMPS,
329 #if CONFIG_H264_MUXER
330 static int h264_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
332 AVStream *st = s->streams[0];
333 if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
334 AV_RB24(pkt->data) != 0x000001)
335 return ff_stream_add_bitstream_filter(st, "h264_mp4toannexb", NULL);
339 AVOutputFormat ff_h264_muxer = {
341 .long_name = NULL_IF_CONFIG_SMALL("raw H.264 video"),
342 .extensions = "h264,264",
343 .audio_codec = AV_CODEC_ID_NONE,
344 .video_codec = AV_CODEC_ID_H264,
345 .write_header = force_one_stream,
346 .write_packet = ff_raw_write_packet,
347 .check_bitstream = h264_check_bitstream,
348 .flags = AVFMT_NOTIMESTAMPS,
352 #if CONFIG_HEVC_MUXER
353 static int hevc_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
355 AVStream *st = s->streams[0];
356 if (pkt->size >= 5 && AV_RB32(pkt->data) != 0x0000001 &&
357 AV_RB24(pkt->data) != 0x000001)
358 return ff_stream_add_bitstream_filter(st, "hevc_mp4toannexb", NULL);
362 AVOutputFormat ff_hevc_muxer = {
364 .long_name = NULL_IF_CONFIG_SMALL("raw HEVC video"),
365 .extensions = "hevc,h265,265",
366 .audio_codec = AV_CODEC_ID_NONE,
367 .video_codec = AV_CODEC_ID_HEVC,
368 .write_header = force_one_stream,
369 .write_packet = ff_raw_write_packet,
370 .check_bitstream = hevc_check_bitstream,
371 .flags = AVFMT_NOTIMESTAMPS,
376 AVOutputFormat ff_m4v_muxer = {
378 .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-4 video"),
380 .audio_codec = AV_CODEC_ID_NONE,
381 .video_codec = AV_CODEC_ID_MPEG4,
382 .write_header = force_one_stream,
383 .write_packet = ff_raw_write_packet,
384 .flags = AVFMT_NOTIMESTAMPS,
388 #if CONFIG_MJPEG_MUXER
389 AVOutputFormat ff_mjpeg_muxer = {
391 .long_name = NULL_IF_CONFIG_SMALL("raw MJPEG video"),
392 .mime_type = "video/x-mjpeg",
393 .extensions = "mjpg,mjpeg",
394 .audio_codec = AV_CODEC_ID_NONE,
395 .video_codec = AV_CODEC_ID_MJPEG,
396 .write_header = force_one_stream,
397 .write_packet = ff_raw_write_packet,
398 .flags = AVFMT_NOTIMESTAMPS,
402 #if CONFIG_SINGLEJPEG_MUXER
403 AVOutputFormat ff_singlejpeg_muxer = {
404 .name = "singlejpeg",
405 .long_name = NULL_IF_CONFIG_SMALL("JPEG single image"),
406 .mime_type = "image/jpeg",
407 .audio_codec = AV_CODEC_ID_NONE,
408 .video_codec = AV_CODEC_ID_MJPEG,
409 .write_packet = ff_raw_write_packet,
410 .flags = AVFMT_NOTIMESTAMPS,
411 .write_header = force_one_stream,
416 AVOutputFormat ff_mlp_muxer = {
418 .long_name = NULL_IF_CONFIG_SMALL("raw MLP"),
420 .audio_codec = AV_CODEC_ID_MLP,
421 .video_codec = AV_CODEC_ID_NONE,
422 .write_header = force_one_stream,
423 .write_packet = ff_raw_write_packet,
424 .flags = AVFMT_NOTIMESTAMPS,
429 AVOutputFormat ff_mp2_muxer = {
431 .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"),
432 .mime_type = "audio/mpeg",
433 .extensions = "mp2,m2a,mpa",
434 .audio_codec = AV_CODEC_ID_MP2,
435 .video_codec = AV_CODEC_ID_NONE,
436 .write_packet = ff_raw_write_packet,
437 .flags = AVFMT_NOTIMESTAMPS,
441 #if CONFIG_MPEG1VIDEO_MUXER
442 AVOutputFormat ff_mpeg1video_muxer = {
443 .name = "mpeg1video",
444 .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"),
445 .mime_type = "video/mpeg",
446 .extensions = "mpg,mpeg,m1v",
447 .audio_codec = AV_CODEC_ID_NONE,
448 .video_codec = AV_CODEC_ID_MPEG1VIDEO,
449 .write_header = force_one_stream,
450 .write_packet = ff_raw_write_packet,
451 .flags = AVFMT_NOTIMESTAMPS,
455 #if CONFIG_MPEG2VIDEO_MUXER
456 AVOutputFormat ff_mpeg2video_muxer = {
457 .name = "mpeg2video",
458 .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"),
460 .audio_codec = AV_CODEC_ID_NONE,
461 .video_codec = AV_CODEC_ID_MPEG2VIDEO,
462 .write_header = force_one_stream,
463 .write_packet = ff_raw_write_packet,
464 .flags = AVFMT_NOTIMESTAMPS,
468 #if CONFIG_RAWVIDEO_MUXER
469 AVOutputFormat ff_rawvideo_muxer = {
471 .long_name = NULL_IF_CONFIG_SMALL("raw video"),
472 .extensions = "yuv,rgb",
473 .audio_codec = AV_CODEC_ID_NONE,
474 .video_codec = AV_CODEC_ID_RAWVIDEO,
475 .write_packet = ff_raw_write_packet,
476 .flags = AVFMT_NOTIMESTAMPS,
481 AVOutputFormat ff_sbc_muxer = {
483 .long_name = NULL_IF_CONFIG_SMALL("raw SBC"),
484 .mime_type = "audio/x-sbc",
485 .extensions = "sbc,msbc",
486 .audio_codec = AV_CODEC_ID_SBC,
487 .write_header = force_one_stream,
488 .write_packet = ff_raw_write_packet,
489 .flags = AVFMT_NOTIMESTAMPS,
493 #if CONFIG_TRUEHD_MUXER
494 AVOutputFormat ff_truehd_muxer = {
496 .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"),
498 .audio_codec = AV_CODEC_ID_TRUEHD,
499 .video_codec = AV_CODEC_ID_NONE,
500 .write_header = force_one_stream,
501 .write_packet = ff_raw_write_packet,
502 .flags = AVFMT_NOTIMESTAMPS,
507 AVOutputFormat ff_vc1_muxer = {
509 .long_name = NULL_IF_CONFIG_SMALL("raw VC-1 video"),
511 .audio_codec = AV_CODEC_ID_NONE,
512 .video_codec = AV_CODEC_ID_VC1,
513 .write_header = force_one_stream,
514 .write_packet = ff_raw_write_packet,
515 .flags = AVFMT_NOTIMESTAMPS,