static int gxf_write_umf_media_audio(AVIOContext *pb, GXFStreamContext *sc) { avio_wl64(pb, av_double2int(1)); /* sound level to begin to */ avio_wl64(pb, av_double2int(1)); /* sound level to begin to */ avio_wl32(pb, 0); /* number of fields over which to ramp up sound level */ avio_wl32(pb, 0); /* number of fields over which to ramp down sound level */ avio_wl32(pb, 0); /* reserved */ avio_wl32(pb, 0); /* reserved */ return 32; }
static int sox_write_header(AVFormatContext *s) { SoXContext *sox = s->priv_data; AVIOContext *pb = s->pb; AVCodecContext *enc = s->streams[0]->codec; AVDictionaryEntry *comment; size_t comment_len = 0, comment_size; comment = av_dict_get(s->metadata, "comment", NULL, 0); if (comment) comment_len = strlen(comment->value); comment_size = (comment_len + 7) & ~7; sox->header_size = SOX_FIXED_HDR + comment_size; if (enc->codec_id == AV_CODEC_ID_PCM_S32LE) { ffio_wfourcc(pb, ".SoX"); avio_wl32(pb, sox->header_size); avio_wl64(pb, 0); /* number of samples */ avio_wl64(pb, av_double2int(enc->sample_rate)); avio_wl32(pb, enc->channels); avio_wl32(pb, comment_size); } else if (enc->codec_id == AV_CODEC_ID_PCM_S32BE) { ffio_wfourcc(pb, "XoS."); avio_wb32(pb, sox->header_size); avio_wb64(pb, 0); /* number of samples */ avio_wb64(pb, av_double2int(enc->sample_rate)); avio_wb32(pb, enc->channels); avio_wb32(pb, comment_size); } else { av_log(s, AV_LOG_ERROR, "invalid codec; use pcm_s32le or pcm_s32be\n"); return -1; } if (comment_len) avio_write(pb, comment->value, comment_len); for ( ; comment_size > comment_len; comment_len++) avio_w8(pb, 0); avio_flush(pb); return 0; }
static void put_amf_double(AVIOContext *pb, double d) { avio_w8(pb, AMF_DATA_TYPE_NUMBER); avio_wb64(pb, av_double2int(d)); }
void ff_amf_write_number(uint8_t **dst, double val) { bytestream_put_byte(dst, AMF_DATA_TYPE_NUMBER); bytestream_put_be64(dst, av_double2int(val)); }
static int caf_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; AVCodecContext *enc = s->streams[0]->codec; CAFContext *caf = s->priv_data; AVDictionaryEntry *t = NULL; unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, enc->codec_id); int64_t chunk_size = 0; int frame_size = enc->frame_size; if (s->nb_streams != 1) { av_log(s, AV_LOG_ERROR, "CAF files have exactly one stream\n"); return AVERROR(EINVAL); } switch (enc->codec_id) { case AV_CODEC_ID_AAC: av_log(s, AV_LOG_ERROR, "muxing codec currently unsupported\n"); return AVERROR_PATCHWELCOME; } if (!codec_tag) { av_log(s, AV_LOG_ERROR, "unsupported codec\n"); return AVERROR_INVALIDDATA; } if (!enc->block_align && !pb->seekable) { av_log(s, AV_LOG_ERROR, "Muxing variable packet size not supported on non seekable output\n"); return AVERROR_INVALIDDATA; } if (enc->codec_id != AV_CODEC_ID_MP3 || frame_size != 576) frame_size = samples_per_packet(enc->codec_id, enc->channels, enc->block_align); ffio_wfourcc(pb, "caff"); //< mFileType avio_wb16(pb, 1); //< mFileVersion avio_wb16(pb, 0); //< mFileFlags ffio_wfourcc(pb, "desc"); //< Audio Description chunk avio_wb64(pb, 32); //< mChunkSize avio_wb64(pb, av_double2int(enc->sample_rate)); //< mSampleRate avio_wl32(pb, codec_tag); //< mFormatID avio_wb32(pb, codec_flags(enc->codec_id)); //< mFormatFlags avio_wb32(pb, enc->block_align); //< mBytesPerPacket avio_wb32(pb, frame_size); //< mFramesPerPacket avio_wb32(pb, enc->channels); //< mChannelsPerFrame avio_wb32(pb, av_get_bits_per_sample(enc->codec_id)); //< mBitsPerChannel if (enc->channel_layout) { ffio_wfourcc(pb, "chan"); avio_wb64(pb, 12); ff_mov_write_chan(pb, enc->channel_layout); } if (enc->codec_id == AV_CODEC_ID_ALAC) { ffio_wfourcc(pb, "kuki"); avio_wb64(pb, 12 + enc->extradata_size); avio_write(pb, "\0\0\0\14frmaalac", 12); avio_write(pb, enc->extradata, enc->extradata_size); } else if (enc->codec_id == AV_CODEC_ID_AMR_NB) { ffio_wfourcc(pb, "kuki"); avio_wb64(pb, 29); avio_write(pb, "\0\0\0\14frmasamr", 12); avio_wb32(pb, 0x11); /* size */ avio_write(pb, "samrFFMP", 8); avio_w8(pb, 0); /* decoder version */ avio_wb16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */ avio_w8(pb, 0x00); /* Mode change period (no restriction) */ avio_w8(pb, 0x01); /* Frames per sample */ } else if (enc->codec_id == AV_CODEC_ID_QDM2) { ffio_wfourcc(pb, "kuki"); avio_wb64(pb, enc->extradata_size); avio_write(pb, enc->extradata, enc->extradata_size); } if (av_dict_count(s->metadata)) { ffio_wfourcc(pb, "info"); //< Information chunk while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) { chunk_size += strlen(t->key) + strlen(t->value) + 2; } avio_wb64(pb, chunk_size + 4); avio_wb32(pb, av_dict_count(s->metadata)); t = NULL; while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) { avio_put_str(pb, t->key); avio_put_str(pb, t->value); } } ffio_wfourcc(pb, "data"); //< Audio Data chunk caf->data = avio_tell(pb); avio_wb64(pb, -1); //< mChunkSize avio_wb32(pb, 0); //< mEditCount avio_flush(pb); return 0; }
static int ffm_write_header(AVFormatContext *s) { FFMContext *ffm = s->priv_data; AVStream *st; AVIOContext *pb = s->pb; AVCodecContext *codec; int bit_rate, i; ffm->packet_size = FFM_PACKET_SIZE; /* header */ avio_wl32(pb, MKTAG('F', 'F', 'M', '1')); avio_wb32(pb, ffm->packet_size); avio_wb64(pb, 0); /* current write position */ avio_wb32(pb, s->nb_streams); bit_rate = 0; for(i=0;i<s->nb_streams;i++) { st = s->streams[i]; bit_rate += st->codec->bit_rate; } avio_wb32(pb, bit_rate); /* list of streams */ for(i=0;i<s->nb_streams;i++) { st = s->streams[i]; avpriv_set_pts_info(st, 64, 1, 1000000); codec = st->codec; /* generic info */ avio_wb32(pb, codec->codec_id); avio_w8(pb, codec->codec_type); avio_wb32(pb, codec->bit_rate); avio_wb32(pb, codec->flags); avio_wb32(pb, codec->flags2); avio_wb32(pb, codec->debug); /* specific info */ switch(codec->codec_type) { case AVMEDIA_TYPE_VIDEO: avio_wb32(pb, codec->time_base.num); avio_wb32(pb, codec->time_base.den); avio_wb16(pb, codec->width); avio_wb16(pb, codec->height); avio_wb16(pb, codec->gop_size); avio_wb32(pb, codec->pix_fmt); avio_w8(pb, codec->qmin); avio_w8(pb, codec->qmax); avio_w8(pb, codec->max_qdiff); avio_wb16(pb, (int) (codec->qcompress * 10000.0)); avio_wb16(pb, (int) (codec->qblur * 10000.0)); avio_wb32(pb, codec->bit_rate_tolerance); avio_put_str(pb, codec->rc_eq ? codec->rc_eq : "tex^qComp"); avio_wb32(pb, codec->rc_max_rate); avio_wb32(pb, codec->rc_min_rate); avio_wb32(pb, codec->rc_buffer_size); avio_wb64(pb, av_double2int(codec->i_quant_factor)); avio_wb64(pb, av_double2int(codec->b_quant_factor)); avio_wb64(pb, av_double2int(codec->i_quant_offset)); avio_wb64(pb, av_double2int(codec->b_quant_offset)); avio_wb32(pb, codec->dct_algo); avio_wb32(pb, codec->strict_std_compliance); avio_wb32(pb, codec->max_b_frames); avio_wb32(pb, codec->mpeg_quant); avio_wb32(pb, codec->intra_dc_precision); avio_wb32(pb, codec->me_method); avio_wb32(pb, codec->mb_decision); avio_wb32(pb, codec->nsse_weight); avio_wb32(pb, codec->frame_skip_cmp); avio_wb64(pb, av_double2int(codec->rc_buffer_aggressivity)); avio_wb32(pb, codec->codec_tag); avio_w8(pb, codec->thread_count); avio_wb32(pb, codec->coder_type); avio_wb32(pb, codec->me_cmp); avio_wb32(pb, codec->me_subpel_quality); avio_wb32(pb, codec->me_range); avio_wb32(pb, codec->keyint_min); avio_wb32(pb, codec->scenechange_threshold); avio_wb32(pb, codec->b_frame_strategy); avio_wb64(pb, av_double2int(codec->qcompress)); avio_wb64(pb, av_double2int(codec->qblur)); avio_wb32(pb, codec->max_qdiff); avio_wb32(pb, codec->refs); break; case AVMEDIA_TYPE_AUDIO: avio_wb32(pb, codec->sample_rate); avio_wl16(pb, codec->channels); avio_wl16(pb, codec->frame_size); avio_wl16(pb, codec->sample_fmt); break; default: return -1; } if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) { avio_wb32(pb, codec->extradata_size); avio_write(pb, codec->extradata, codec->extradata_size); } } /* flush until end of block reached */ while ((avio_tell(pb) % ffm->packet_size) != 0) avio_w8(pb, 0); avio_flush(pb); /* init packet mux */ ffm->packet_ptr = ffm->packet; ffm->packet_end = ffm->packet + ffm->packet_size - FFM_HEADER_SIZE; av_assert0(ffm->packet_end >= ffm->packet); ffm->frame_offset = 0; ffm->dts = 0; ffm->first_packet = 1; return 0; }
static int aiff_write_header(AVFormatContext *s) { AIFFOutputContext *aiff = s->priv_data; AVIOContext *pb = s->pb; AVCodecParameters *par; uint64_t sample_rate; int i, aifc = 0; aiff->audio_stream_idx = -1; for (i = 0; i < s->nb_streams; i++) { AVStream *st = s->streams[i]; if (aiff->audio_stream_idx < 0 && st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { aiff->audio_stream_idx = i; } else if (st->codecpar->codec_type != AVMEDIA_TYPE_VIDEO) { av_log(s, AV_LOG_ERROR, "AIFF allows only one audio stream and a picture.\n"); return AVERROR(EINVAL); } } if (aiff->audio_stream_idx < 0) { av_log(s, AV_LOG_ERROR, "No audio stream present.\n"); return AVERROR(EINVAL); } par = s->streams[aiff->audio_stream_idx]->codecpar; /* First verify if format is ok */ if (!par->codec_tag) return -1; if (par->codec_tag != MKTAG('N','O','N','E')) aifc = 1; /* FORM AIFF header */ ffio_wfourcc(pb, "FORM"); aiff->form = avio_tell(pb); avio_wb32(pb, 0); /* file length */ ffio_wfourcc(pb, aifc ? "AIFC" : "AIFF"); if (aifc) { // compressed audio if (!par->block_align) { av_log(s, AV_LOG_ERROR, "block align not set\n"); return -1; } /* Version chunk */ ffio_wfourcc(pb, "FVER"); avio_wb32(pb, 4); avio_wb32(pb, 0xA2805140); } if (par->channels > 2 && par->channel_layout) { ffio_wfourcc(pb, "CHAN"); avio_wb32(pb, 12); ff_mov_write_chan(pb, par->channel_layout); } put_meta(s, "title", MKTAG('N', 'A', 'M', 'E')); put_meta(s, "author", MKTAG('A', 'U', 'T', 'H')); put_meta(s, "copyright", MKTAG('(', 'c', ')', ' ')); put_meta(s, "comment", MKTAG('A', 'N', 'N', 'O')); /* Common chunk */ ffio_wfourcc(pb, "COMM"); avio_wb32(pb, aifc ? 24 : 18); /* size */ avio_wb16(pb, par->channels); /* Number of channels */ aiff->frames = avio_tell(pb); avio_wb32(pb, 0); /* Number of frames */ if (!par->bits_per_coded_sample) par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id); if (!par->bits_per_coded_sample) { av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n"); return -1; } if (!par->block_align) par->block_align = (par->bits_per_coded_sample * par->channels) >> 3; avio_wb16(pb, par->bits_per_coded_sample); /* Sample size */ sample_rate = av_double2int(par->sample_rate); avio_wb16(pb, (sample_rate >> 52) + (16383 - 1023)); avio_wb64(pb, UINT64_C(1) << 63 | sample_rate << 11); if (aifc) { avio_wl32(pb, par->codec_tag); avio_wb16(pb, 0); } if (par->codec_tag == MKTAG('Q','D','M','2') && par->extradata_size) { ffio_wfourcc(pb, "wave"); avio_wb32(pb, par->extradata_size); avio_write(pb, par->extradata, par->extradata_size); } /* Sound data chunk */ ffio_wfourcc(pb, "SSND"); aiff->ssnd = avio_tell(pb); /* Sound chunk size */ avio_wb32(pb, 0); /* Sound samples data size */ avio_wb32(pb, 0); /* Data offset */ avio_wb32(pb, 0); /* Block-size (block align) */ avpriv_set_pts_info(s->streams[aiff->audio_stream_idx], 64, 1, s->streams[aiff->audio_stream_idx]->codecpar->sample_rate); /* Data is starting here */ avio_flush(pb); return 0; }
static int caf_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; AVCodecContext *enc = s->streams[0]->codec; CAFContext *caf = s->priv_data; unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, enc->codec_id); switch (enc->codec_id) { case AV_CODEC_ID_AAC: case AV_CODEC_ID_AC3: av_log(s, AV_LOG_ERROR, "muxing codec currently unsupported\n"); return AVERROR_PATCHWELCOME; } switch (enc->codec_id) { case AV_CODEC_ID_PCM_S8: case AV_CODEC_ID_PCM_S16LE: case AV_CODEC_ID_PCM_S16BE: case AV_CODEC_ID_PCM_S24LE: case AV_CODEC_ID_PCM_S24BE: case AV_CODEC_ID_PCM_S32LE: case AV_CODEC_ID_PCM_S32BE: case AV_CODEC_ID_PCM_F32LE: case AV_CODEC_ID_PCM_F32BE: case AV_CODEC_ID_PCM_F64LE: case AV_CODEC_ID_PCM_F64BE: case AV_CODEC_ID_PCM_ALAW: case AV_CODEC_ID_PCM_MULAW: codec_tag = MKTAG('l','p','c','m'); } if (!codec_tag) { av_log(s, AV_LOG_ERROR, "unsupported codec\n"); return AVERROR_INVALIDDATA; } if (!enc->block_align && !pb->seekable) { av_log(s, AV_LOG_ERROR, "Muxing variable packet size not supported on non seekable output\n"); return AVERROR_INVALIDDATA; } ffio_wfourcc(pb, "caff"); //< mFileType avio_wb16(pb, 1); //< mFileVersion avio_wb16(pb, 0); //< mFileFlags ffio_wfourcc(pb, "desc"); //< Audio Description chunk avio_wb64(pb, 32); //< mChunkSize avio_wb64(pb, av_double2int(enc->sample_rate)); //< mSampleRate avio_wl32(pb, codec_tag); //< mFormatID avio_wb32(pb, codec_flags(enc->codec_id)); //< mFormatFlags avio_wb32(pb, enc->block_align); //< mBytesPerPacket avio_wb32(pb, samples_per_packet(enc->codec_id, enc->channels)); //< mFramesPerPacket avio_wb32(pb, enc->channels); //< mChannelsPerFrame avio_wb32(pb, av_get_bits_per_sample(enc->codec_id)); //< mBitsPerChannel if (enc->channel_layout) { ffio_wfourcc(pb, "chan"); avio_wb64(pb, 12); ff_mov_write_chan(pb, enc->channel_layout); } if (enc->codec_id == AV_CODEC_ID_ALAC) { ffio_wfourcc(pb, "kuki"); avio_wb64(pb, 12 + enc->extradata_size); avio_write(pb, "\0\0\0\14frmaalac", 12); avio_write(pb, enc->extradata, enc->extradata_size); } else if (enc->codec_id == AV_CODEC_ID_AMR_NB) { ffio_wfourcc(pb, "kuki"); avio_wb64(pb, 29); avio_write(pb, "\0\0\0\14frmasamr", 12); avio_wb32(pb, 0x11); /* size */ avio_write(pb, "samrFFMP", 8); avio_w8(pb, 0); /* decoder version */ avio_wb16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */ avio_w8(pb, 0x00); /* Mode change period (no restriction) */ avio_w8(pb, 0x01); /* Frames per sample */ } else if (enc->codec_id == AV_CODEC_ID_QDM2) { ffio_wfourcc(pb, "kuki"); avio_wb64(pb, enc->extradata_size); avio_write(pb, enc->extradata, enc->extradata_size); } ffio_wfourcc(pb, "data"); //< Audio Data chunk caf->data = avio_tell(pb); avio_wb64(pb, -1); //< mChunkSize avio_wb32(pb, 0); //< mEditCount avio_flush(pb); return 0; }
static int aiff_write_header(AVFormatContext *s) { AIFFOutputContext *aiff = s->priv_data; AVIOContext *pb = s->pb; AVCodecContext *enc = s->streams[0]->codec; uint64_t sample_rate; int aifc = 0; /* First verify if format is ok */ if (!enc->codec_tag) return -1; if (enc->codec_tag != MKTAG('N','O','N','E')) aifc = 1; /* FORM AIFF header */ ffio_wfourcc(pb, "FORM"); aiff->form = avio_tell(pb); avio_wb32(pb, 0); /* file length */ ffio_wfourcc(pb, aifc ? "AIFC" : "AIFF"); if (aifc) { // compressed audio enc->bits_per_coded_sample = 16; if (!enc->block_align) { av_log(s, AV_LOG_ERROR, "block align not set\n"); return -1; } /* Version chunk */ ffio_wfourcc(pb, "FVER"); avio_wb32(pb, 4); avio_wb32(pb, 0xA2805140); } if (enc->channels > 2 && enc->channel_layout) { ffio_wfourcc(pb, "CHAN"); avio_wb32(pb, 12); ff_mov_write_chan(pb, enc->channel_layout); } /* Common chunk */ ffio_wfourcc(pb, "COMM"); avio_wb32(pb, aifc ? 24 : 18); /* size */ avio_wb16(pb, enc->channels); /* Number of channels */ aiff->frames = avio_tell(pb); avio_wb32(pb, 0); /* Number of frames */ if (!enc->bits_per_coded_sample) enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id); if (!enc->bits_per_coded_sample) { av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n"); return -1; } if (!enc->block_align) enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3; avio_wb16(pb, enc->bits_per_coded_sample); /* Sample size */ sample_rate = av_double2int(enc->sample_rate); avio_wb16(pb, (sample_rate >> 52) + (16383 - 1023)); avio_wb64(pb, UINT64_C(1) << 63 | sample_rate << 11); if (aifc) { avio_wl32(pb, enc->codec_tag); avio_wb16(pb, 0); } if (enc->codec_tag == MKTAG('Q','D','M','2') && enc->extradata_size) { ffio_wfourcc(pb, "wave"); avio_wb32(pb, enc->extradata_size); avio_write(pb, enc->extradata, enc->extradata_size); } /* Sound data chunk */ ffio_wfourcc(pb, "SSND"); aiff->ssnd = avio_tell(pb); /* Sound chunk size */ avio_wb32(pb, 0); /* Sound samples data size */ avio_wb32(pb, 0); /* Data offset */ avio_wb32(pb, 0); /* Block-size (block align) */ avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); /* Data is starting here */ avio_flush(pb); return 0; }