void ff_rtp_send_punch_packets(URLContext* rtp_handle) { AVIOContext *pb; uint8_t *buf; int len; /* Send a small RTP packet */ if (avio_open_dyn_buf(&pb) < 0) return; avio_w8(pb, (RTP_VERSION << 6)); avio_w8(pb, 0); /* Payload type */ avio_wb16(pb, 0); /* Seq */ avio_wb32(pb, 0); /* Timestamp */ avio_wb32(pb, 0); /* SSRC */ avio_flush(pb); len = avio_close_dyn_buf(pb, &buf); if ((len > 0) && buf) ffurl_write(rtp_handle, buf, len); av_free(buf); /* Send a minimal RTCP RR */ if (avio_open_dyn_buf(&pb) < 0) return; avio_w8(pb, (RTP_VERSION << 6)); avio_w8(pb, RTCP_RR); /* receiver report */ avio_wb16(pb, 1); /* length in words - 1 */ avio_wb32(pb, 0); /* our own SSRC */ avio_flush(pb); len = avio_close_dyn_buf(pb, &buf); if ((len > 0) && buf) ffurl_write(rtp_handle, buf, len); av_free(buf); }
static int mmf_write_header(AVFormatContext *s) { MMFContext *mmf = s->priv_data; AVIOContext *pb = s->pb; int64_t pos; int rate; rate = mmf_rate_code(s->streams[0]->codec->sample_rate); if(rate < 0) { av_log(s, AV_LOG_ERROR, "Unsupported sample rate %d\n", s->streams[0]->codec->sample_rate); return -1; } ffio_wfourcc(pb, "MMMD"); avio_wb32(pb, 0); pos = ff_start_tag(pb, "CNTI"); avio_w8(pb, 0); /* class */ avio_w8(pb, 0); /* type */ avio_w8(pb, 0); /* code type */ avio_w8(pb, 0); /* status */ avio_w8(pb, 0); /* counts */ avio_write(pb, "VN:libavcodec,", sizeof("VN:libavcodec,") -1); /* metadata ("ST:songtitle,VN:version,...") */ end_tag_be(pb, pos); avio_write(pb, "ATR\x00", 4); avio_wb32(pb, 0); mmf->atrpos = avio_tell(pb); avio_w8(pb, 0); /* format type */ avio_w8(pb, 0); /* sequence type */ avio_w8(pb, (0 << 7) | (1 << 4) | rate); /* (channel << 7) | (format << 4) | rate */ avio_w8(pb, 0); /* wave base bit */ avio_w8(pb, 2); /* time base d */ avio_w8(pb, 2); /* time base g */ ffio_wfourcc(pb, "Atsq"); avio_wb32(pb, 16); mmf->atsqpos = avio_tell(pb); /* Will be filled on close */ avio_write(pb, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); mmf->awapos = ff_start_tag(pb, "Awa\x01"); av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); avio_flush(pb); return 0; }
static int au_write_header(AVFormatContext *s) { AVIOContext *pb = s->pb; s->priv_data = NULL; /* format header */ if (put_au_header(pb, s->streams[0]->codec) < 0) { return -1; } avio_flush(pb); return 0; }
/** * mpeg1_write_trailer * We set AVOutputFormat->write_trailer to this function for mpeg1. That way, * the mpeg1 video gets a proper trailer when it is closed. * * Returns 0 * */ static int mpeg1_write_trailer(AVFormatContext *s) { #if defined FF_API_NEW_AVIO avio_write(s->pb, mpeg1_trailer, 4); avio_flush(s->pb); #elif LIBAVFORMAT_BUILD >= (52<<16) put_buffer(s->pb, mpeg1_trailer, 4); put_flush_packet(s->pb); #else put_buffer(&s->pb, mpeg1_trailer, 4); put_flush_packet(&s->pb); #endif /* FF_API_NEW_AVIO -- LIBAVFORMAT_BUILD >= (52<<16) */ return 0; /* success */ }
static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt) { RCVContext *ctx = s->priv_data; AVIOContext *pb = s->pb; if (!pkt->size) return 0; avio_wl32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0)); avio_wl32(pb, pkt->pts); avio_write(pb, pkt->data, pkt->size); avio_flush(pb); ctx->frames++; return 0; }
static int write_trailer(AVFormatContext *s) { WVMuxContext *wc = s->priv_data; AVIOContext *pb = s->pb; ff_ape_write(s); if (pb->seekable) { avio_seek(pb, 12, SEEK_SET); avio_wl32(pb, wc->duration); avio_flush(pb); } return 0; }
static void md5_finish(struct AVFormatContext *s, char *buf) { uint8_t md5[16]; int i, offset = strlen(buf); av_md5_final(s->priv_data, md5); for (i = 0; i < sizeof(md5); i++) { snprintf(buf + offset, 3, "%02"PRIx8, md5[i]); offset += 2; } buf[offset] = '\n'; buf[offset+1] = 0; avio_write(s->pb, buf, strlen(buf)); avio_flush(s->pb); }
static int rm_write_header(AVFormatContext *s) { RMMuxContext *rm = s->priv_data; StreamInfo *stream; int n; AVCodecContext *codec; for(n=0;n<s->nb_streams;n++) { AVStream *st = s->streams[n]; int frame_size; s->streams[n]->id = n; codec = s->streams[n]->codec; stream = &rm->streams[n]; memset(stream, 0, sizeof(StreamInfo)); stream->num = n; stream->bit_rate = codec->bit_rate; stream->enc = codec; switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: rm->audio_stream = stream; frame_size = av_get_audio_frame_duration(codec, 0); stream->frame_rate = (float)codec->sample_rate / (float)frame_size; /* XXX: dummy values */ stream->packet_max_size = 1024; stream->nb_packets = 0; stream->total_frames = stream->nb_packets; break; case AVMEDIA_TYPE_VIDEO: rm->video_stream = stream; // TODO: should be avg_frame_rate stream->frame_rate = (float)st->time_base.den / (float)st->time_base.num; /* XXX: dummy values */ stream->packet_max_size = 4096; stream->nb_packets = 0; stream->total_frames = stream->nb_packets; break; default: return -1; } } if (rv10_write_header(s, 0, 0)) return AVERROR_INVALIDDATA; avio_flush(s->pb); return 0; }
static int rm_write_header(AVFormatContext *s) { RMMuxContext *rm = s->priv_data; StreamInfo *stream; int n; AVCodecContext *codec; if (s->nb_streams > 2) { av_log(s, AV_LOG_ERROR, "At most 2 streams are currently supported for muxing in RM\n"); return AVERROR_PATCHWELCOME; } for(n=0;n<s->nb_streams;n++) { s->streams[n]->id = n; codec = s->streams[n]->codec; stream = &rm->streams[n]; memset(stream, 0, sizeof(StreamInfo)); stream->num = n; stream->bit_rate = codec->bit_rate; stream->enc = codec; switch(codec->codec_type) { case AVMEDIA_TYPE_AUDIO: rm->audio_stream = stream; stream->frame_rate = (float)codec->sample_rate / (float)codec->frame_size; /* XXX: dummy values */ stream->packet_max_size = 1024; stream->nb_packets = 0; stream->total_frames = stream->nb_packets; break; case AVMEDIA_TYPE_VIDEO: rm->video_stream = stream; stream->frame_rate = (float)codec->time_base.den / (float)codec->time_base.num; /* XXX: dummy values */ stream->packet_max_size = 4096; stream->nb_packets = 0; stream->total_frames = stream->nb_packets; break; default: return -1; } } if (rv10_write_header(s, 0, 0)) return AVERROR_INVALIDDATA; avio_flush(s->pb); return 0; }
static int write_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; GetBitContext gb; int i; avio_wl16(pb, SYNC_WORD); avio_wl16(pb, 8 * 10); init_get_bits(&gb, pkt->data, 8*10); for(i=0; i< 8 * 10; i++) avio_wl16(pb, get_bits1(&gb) ? BIT_1 : BIT_0); avio_flush(pb); return 0; }
static int write_packet(AVFormatContext *s, AVPacket *pkt) { AVIOContext *pb = s->pb; WtvContext *wctx = s->priv_data; // write timestamp chunk write_timestamp(s, pkt); write_chunk_header(s, &ff_data_guid, pkt->size, INDEX_BASE + pkt->stream_index); avio_write(pb, pkt->data, pkt->size); write_pad(pb, WTV_PAD8(pkt->size) - pkt->size); wctx->serial++; avio_flush(pb); return 0; }
static int au_write_trailer(AVFormatContext *s) { AVIOContext *pb = s->pb; int64_t file_size = avio_tell(pb); if (s->pb->seekable && file_size < INT32_MAX) { /* update file size */ avio_seek(pb, 8, SEEK_SET); avio_wb32(pb, (uint32_t)(file_size - AU_HEADER_SIZE)); avio_seek(pb, file_size, SEEK_SET); avio_flush(pb); } return 0; }
void record_segment_time(Output_Context *ptr_output_ctx){ if(ptr_output_ctx->start_time_mark == 0){ ptr_output_ctx->start_time_mark = 1; //printf("混蛋。。。、\n"); ptr_output_ctx->prev_segment_time = av_q2d(ptr_output_ctx->video_stream->time_base) * (ptr_output_ctx->pkt.pts ) - (double)ptr_output_ctx->ptr_format_ctx->start_time / AV_TIME_BASE; printf("ptr_output_ctx->prev_segment_time = %f \n" ,ptr_output_ctx->prev_segment_time); } ptr_output_ctx->curr_segment_time = av_q2d(ptr_output_ctx->video_stream->time_base) * (ptr_output_ctx->pkt.pts ) - (double)ptr_output_ctx->ptr_format_ctx->start_time / AV_TIME_BASE; if(ptr_output_ctx->vcodec_copy_mark == 1){ //video codecContext copy ptr_output_ctx->sync_ipts = ptr_output_ctx->curr_segment_time; } // //time meet if(ptr_output_ctx->curr_segment_time - ptr_output_ctx->prev_segment_time >= ptr_output_ctx->segment_duration){ //printf("...meet time ...\n" ); av_write_trailer(ptr_output_ctx->ptr_format_ctx); // close ts file and free memory avio_flush(ptr_output_ctx->ptr_format_ctx->pb); avio_close(ptr_output_ctx->ptr_format_ctx->pb); printf("complete the %d.ts ,and write the m3u8 file..\n" ,ptr_output_ctx->segment_no); write_m3u8_body( ptr_output_ctx ,ptr_output_ctx->curr_segment_time - ptr_output_ctx->prev_segment_time ,0 ); //concat ts file name sprintf(&(ptr_output_ctx->ts_name[ptr_output_ctx->dir_name_len]) ,"%s-%d.ts" ,ptr_output_ctx->ts_prfix_name ,++ptr_output_ctx->segment_no); if (avio_open(&(ptr_output_ctx->ptr_format_ctx->pb), ptr_output_ctx->ts_name, AVIO_FLAG_WRITE) < 0) { fprintf(stderr, "Could not open '%s'\n", ptr_output_ctx->ts_name); exit(OPEN_MUX_FILE_FAIL); } // Write a new header at the start of each file if (avformat_write_header(ptr_output_ctx->ptr_format_ctx, NULL)) { fprintf(stderr, "Could not write mpegts header to first output file\n"); exit(AVFORMAT_WRITE_HEADER_FAIL); } ptr_output_ctx->prev_segment_time = ptr_output_ctx->curr_segment_time; //place here } }
static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) { GXFContext *gxf = s->priv_data; AVIOContext *pb = s->pb; AVStream *st = s->streams[pkt->stream_index]; int64_t pos = avio_tell(pb); int padding = 0; int packet_start_offset = avio_tell(pb) / 1024; gxf_write_packet_header(pb, PKT_MEDIA); if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ padding = 4 - pkt->size % 4; else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) padding = GXF_AUDIO_PACKET_SIZE - pkt->size; gxf_write_media_preamble(s, pkt, pkt->size + padding); avio_write(pb, pkt->data, pkt->size); gxf_write_padding(pb, padding); if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { if (!(gxf->flt_entries_nb % 500)) { gxf->flt_entries = av_realloc(gxf->flt_entries, (gxf->flt_entries_nb + 500) * sizeof(*gxf->flt_entries)); if (!gxf->flt_entries) { av_log(s, AV_LOG_ERROR, "could not reallocate flt entries\n"); return -1; } } gxf->flt_entries[gxf->flt_entries_nb++] = packet_start_offset; gxf->nb_fields += 2; // count fields } updatePacketSize(pb, pos); gxf->packet_count++; if (gxf->packet_count == 100) { gxf_write_map_packet(s, 0); gxf->packet_count = 0; } avio_flush(pb); return 0; }
void avcodec_decoder_release(avcodec_decoder d) { if (d->codec) { avcodec_free_context(&d->codec); } if (d->container) { avformat_close_input(&d->container); } if (d->avio) { avio_flush(d->avio); av_free(d->avio->buffer); av_free(d->avio); } delete d; }
static int srt_write_packet(AVFormatContext *avf, AVPacket *pkt) { SRTContext *srt = avf->priv_data; int write_ts = avf->streams[0]->codec->codec_id != AV_CODEC_ID_SRT; if (write_ts) { int64_t s = pkt->pts, e, d = pkt->duration; int size, x1 = -1, y1 = -1, x2 = -1, y2 = -1; const uint8_t *p; p = av_packet_get_side_data(pkt, AV_PKT_DATA_SUBTITLE_POSITION, &size); if (p && size == 16) { x1 = AV_RL32(p ); y1 = AV_RL32(p + 4); x2 = AV_RL32(p + 8); y2 = AV_RL32(p + 12); } if (d <= 0) /* For backward compatibility, fallback to convergence_duration. */ d = pkt->convergence_duration; if (s == AV_NOPTS_VALUE || d < 0) { av_log(avf, AV_LOG_WARNING, "Insufficient timestamps in event number %d.\n", srt->index); return 0; } e = s + d; avio_printf(avf->pb, "%d\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d", srt->index, (int)(s / 3600000), (int)(s / 60000) % 60, (int)(s / 1000) % 60, (int)(s % 1000), (int)(e / 3600000), (int)(e / 60000) % 60, (int)(e / 1000) % 60, (int)(e % 1000)); if (p) avio_printf(avf->pb, " X1:%03d X2:%03d Y1:%03d Y2:%03d", x1, x2, y1, y2); avio_printf(avf->pb, "\n"); } avio_write(avf->pb, pkt->data, pkt->size); if (write_ts) avio_write(avf->pb, "\n\n", 2); avio_flush(avf->pb); srt->index++; return 0; }
static int ico_write_packet(AVFormatContext *s, AVPacket *pkt) { IcoMuxContext *ico = s->priv_data; IcoImage *image; AVIOContext *pb = s->pb; AVCodecContext *c = s->streams[pkt->stream_index]->codec; int i; if (ico->current_image >= ico->nb_images) { av_log(s, AV_LOG_ERROR, "ICO already contains %d images\n", ico->current_image); return AVERROR(EIO); } image = &ico->images[ico->current_image++]; image->offset = avio_tell(pb); image->width = (c->width == 256) ? 0 : c->width; image->height = (c->height == 256) ? 0 : c->height; if (c->codec_id == CODEC_ID_PNG) { image->bits = c->bits_per_coded_sample; image->size = pkt->size; avio_write(pb, pkt->data, pkt->size); } else { // BMP if (AV_RL32(pkt->data + 14) != 40) { // must be BITMAPINFOHEADER av_log(s, AV_LOG_ERROR, "Invalid BMP\n"); return AVERROR(EINVAL); } image->bits = AV_RL16(pkt->data + 28); // allows things like 1bit and 4bit images to be preserved image->size = pkt->size - 14 + c->height * (c->width + 7) / 8; avio_write(pb, pkt->data + 14, 8); // Skip the BITMAPFILEHEADER header avio_wl32(pb, AV_RL32(pkt->data + 22) * 2); // rewrite height as 2 * height avio_write(pb, pkt->data + 26, pkt->size - 26); for (i = 0; i < c->height * (c->width + 7) / 8; ++i) avio_w8(pb, 0x00); // Write bitmask (opaque) } avio_flush(pb); return 0; }
static int au_write_trailer(AVFormatContext *s) { AVIOContext *pb = s->pb; int64_t file_size; if (s->pb->seekable) { /* update file size */ file_size = avio_tell(pb); avio_seek(pb, 8, SEEK_SET); avio_wb32(pb, (uint32_t)(file_size - 24)); avio_seek(pb, file_size, SEEK_SET); avio_flush(pb); } return 0; }
static int smjpeg_write_trailer(AVFormatContext *s) { SMJPEGMuxContext *smc = s->priv_data; AVIOContext *pb = s->pb; int64_t currentpos; if (pb->seekable) { currentpos = avio_tell(pb); avio_seek(pb, 12, SEEK_SET); avio_wb32(pb, smc->duration); avio_seek(pb, currentpos, SEEK_SET); } avio_wl32(pb, SMJPEG_DONE); avio_flush(pb); return 0; }
static void hash_finish(struct AVFormatContext *s, char *buf) { struct HashContext *c = s->priv_data; uint8_t hash[AV_HASH_MAX_SIZE]; int i, offset = strlen(buf); int len = av_hash_get_size(c->hash); av_assert0(len > 0 && len <= sizeof(hash)); av_hash_final(c->hash, hash); for (i = 0; i < len; i++) { snprintf(buf + offset, 3, "%02"PRIx8, hash[i]); offset += 2; } buf[offset] = '\n'; buf[offset+1] = 0; avio_write(s->pb, buf, strlen(buf)); avio_flush(s->pb); }
/* send an rtcp sender report packet */ static void rtcp_send_sr(AVFormatContext *s1, int64_t ntp_time, int bye) { RTPMuxContext *s = s1->priv_data; uint32_t rtp_ts; av_log(s1, AV_LOG_TRACE, "RTCP: %02x %"PRIx64" %x\n", s->payload_type, ntp_time, s->timestamp); s->last_rtcp_ntp_time = ntp_time; rtp_ts = av_rescale_q(ntp_time - s->first_rtcp_ntp_time, (AVRational){1, 1000000}, s1->streams[0]->time_base) + s->base_timestamp; avio_w8(s1->pb, RTP_VERSION << 6); avio_w8(s1->pb, RTCP_SR); avio_wb16(s1->pb, 6); /* length in words - 1 */ avio_wb32(s1->pb, s->ssrc); avio_wb32(s1->pb, ntp_time / 1000000); avio_wb32(s1->pb, ((ntp_time % 1000000) << 32) / 1000000); avio_wb32(s1->pb, rtp_ts); avio_wb32(s1->pb, s->packet_count); avio_wb32(s1->pb, s->octet_count); if (s->cname) { int len = FFMIN(strlen(s->cname), 255); avio_w8(s1->pb, (RTP_VERSION << 6) + 1); avio_w8(s1->pb, RTCP_SDES); avio_wb16(s1->pb, (7 + len + 3) / 4); /* length in words - 1 */ avio_wb32(s1->pb, s->ssrc); avio_w8(s1->pb, 0x01); /* CNAME */ avio_w8(s1->pb, len); avio_write(s1->pb, s->cname, len); avio_w8(s1->pb, 0); /* END */ for (len = (7 + len) % 4; len % 4; len++) avio_w8(s1->pb, 0); } if (bye) { avio_w8(s1->pb, (RTP_VERSION << 6) | 1); avio_w8(s1->pb, RTCP_BYE); avio_wb16(s1->pb, 1); /* length in words - 1 */ avio_wb32(s1->pb, s->ssrc); } avio_flush(s1->pb); }
static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags) { RMMuxContext *rm = s->priv_data; AVIOContext *pb = s->pb; StreamInfo *stream = rm->video_stream; int key_frame = !!(flags & AV_PKT_FLAG_KEY); /* XXX: this is incorrect: should be a parameter */ /* Well, I spent some time finding the meaning of these bits. I am not sure I understood everything, but it works !! */ #if 1 write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame); /* bit 7: '1' if final packet of a frame converted in several packets */ avio_w8(pb, 0x81); /* bit 7: '1' if I frame. bits 6..0 : sequence number in current frame starting from 1 */ if (key_frame) { avio_w8(pb, 0x81); } else { avio_w8(pb, 0x01); } if(size >= 0x4000){ avio_wb32(pb, size); /* total frame size */ avio_wb32(pb, size); /* offset from the start or the end */ }else{ avio_wb16(pb, 0x4000 | size); /* total frame size */ avio_wb16(pb, 0x4000 | size); /* offset from the start or the end */ } #else /* full frame */ write_packet_header(s, size + 6); avio_w8(pb, 0xc0); avio_wb16(pb, 0x4000 + size); /* total frame size */ avio_wb16(pb, 0x4000 + packet_number * 126); /* position in stream */ #endif avio_w8(pb, stream->nb_frames & 0xff); avio_write(pb, buf, size); avio_flush(pb); stream->nb_frames++; return 0; }
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; }
void avio_write(AVIOContext *s, const unsigned char *buf, int size) { if (s->direct && !s->update_checksum) { avio_flush(s); writeout(s, buf, size); return; } while (size > 0) { int len = FFMIN(s->buf_end - s->buf_ptr, size); memcpy(s->buf_ptr, buf, len); s->buf_ptr += len; if (s->buf_ptr >= s->buf_end) flush_buffer(s); buf += len; size -= len; } }
void Close() { if(ctx){ avio_flush(ctx); // TODO leaking memory, but if it's enabled ffmpeg crashes. // av_freep(&buffer); av_free(ctx); ctx = NULL; buffer = NULL; } if(f){ fclose(f); f = NULL; } }
static int sox_write_trailer(AVFormatContext *s) { SoXContext *sox = s->priv_data; AVIOContext *pb = s->pb; AVCodecContext *enc = s->streams[0]->codec; if (s->pb->seekable) { /* update number of samples */ int64_t file_size = avio_tell(pb); int64_t num_samples = (file_size - sox->header_size - 4LL) >> 2LL; avio_seek(pb, 8, SEEK_SET); if (enc->codec_id == AV_CODEC_ID_PCM_S32LE) { avio_wl64(pb, num_samples); } else avio_wb64(pb, num_samples); avio_seek(pb, file_size, SEEK_SET); avio_flush(pb); }
static int microdvd_write_header(struct AVFormatContext *s) { AVCodecContext *avctx = s->streams[0]->codec; AVRational tb = avctx->time_base; if (s->nb_streams != 1 || avctx->codec_id != AV_CODEC_ID_MICRODVD) { av_log(s, AV_LOG_ERROR, "Exactly one MicroDVD stream is needed.\n"); return -1; } if (avctx->extradata && avctx->extradata_size > 0) { avio_write(s->pb, "{DEFAULT}{}", 11); avio_write(s->pb, avctx->extradata, avctx->extradata_size); avio_flush(s->pb); } avpriv_set_pts_info(s->streams[0], 64, tb.num, tb.den); return 0; }
static int wav_write_header(AVFormatContext *s) { WAVMuxContext *wav = s->priv_data; AVIOContext *pb = s->pb; int64_t fmt; ffio_wfourcc(pb, "RIFF"); avio_wl32(pb, 0); /* file length */ ffio_wfourcc(pb, "WAVE"); /* format header */ fmt = ff_start_tag(pb, "fmt "); if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) { av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n", s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE"); return -1; } ff_end_tag(pb, fmt); if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */ && s->pb->seekable) { wav->fact_pos = ff_start_tag(pb, "fact"); avio_wl32(pb, 0); ff_end_tag(pb, wav->fact_pos); } if (wav->write_bext) bwf_write_bext_chunk(s); avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); wav->maxpts = wav->last_duration = 0; wav->minpts = INT64_MAX; /* info header */ ff_riff_write_info(s); /* data header */ wav->data = ff_start_tag(pb, "data"); avio_flush(pb); return 0; }
static int w64_write_trailer(AVFormatContext *s) { AVIOContext *pb = s->pb; WAVMuxContext *wav = s->priv_data; int64_t file_size; if (pb->seekable) { end_guid(pb, wav->data); file_size = avio_tell(pb); avio_seek(pb, 16, SEEK_SET); avio_wl64(pb, file_size); avio_seek(pb, file_size, SEEK_SET); avio_flush(pb); } return 0; }
static int write_trailer(AVFormatContext *s) { FilmstripMuxContext *film = s->priv_data; AVIOContext *pb = s->pb; AVStream *st = s->streams[0]; int i; avio_wb32(pb, RAND_TAG); avio_wb32(pb, film->nb_frames); avio_wb16(pb, 0); // packing method avio_wb16(pb, 0); // reserved avio_wb16(pb, st->codec->width); avio_wb16(pb, st->codec->height); avio_wb16(pb, 0); // leading avio_wb16(pb, 1/av_q2d(st->codec->time_base)); for (i = 0; i < 16; i++) avio_w8(pb, 0x00); // reserved avio_flush(pb); return 0; }