Lines Matching refs:ost

126 static void add_stream(OutputStream *ost, AVFormatContext *oc,
141 ost->tmp_pkt = av_packet_alloc();
142 if (!ost->tmp_pkt) {
147 ost->st = avformat_new_stream(oc, NULL);
148 if (!ost->st) {
152 ost->st->id = oc->nb_streams-1;
158 ost->enc = c;
174 ost->st->time_base = (AVRational){ 1, c->sample_rate };
188 ost->st->time_base = (AVRational){ 1, STREAM_FRAME_RATE };
189 c->time_base = ost->st->time_base;
246 OutputStream *ost, AVDictionary *opt_arg)
253 c = ost->enc;
265 ost->t = 0;
266 ost->tincr = 2 * M_PI * 110.0 / c->sample_rate;
268 ost->tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate;
275 ost->frame = alloc_audio_frame(c->sample_fmt, &c->ch_layout,
277 ost->tmp_frame = alloc_audio_frame(AV_SAMPLE_FMT_S16, &c->ch_layout,
281 ret = avcodec_parameters_from_context(ost->st->codecpar, c);
288 ost->swr_ctx = swr_alloc();
289 if (!ost->swr_ctx) {
295 av_opt_set_chlayout (ost->swr_ctx, "in_chlayout", &c->ch_layout, 0);
296 av_opt_set_int (ost->swr_ctx, "in_sample_rate", c->sample_rate, 0);
297 av_opt_set_sample_fmt(ost->swr_ctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
298 av_opt_set_chlayout (ost->swr_ctx, "out_chlayout", &c->ch_layout, 0);
299 av_opt_set_int (ost->swr_ctx, "out_sample_rate", c->sample_rate, 0);
300 av_opt_set_sample_fmt(ost->swr_ctx, "out_sample_fmt", c->sample_fmt, 0);
303 if ((ret = swr_init(ost->swr_ctx)) < 0) {
311 static AVFrame *get_audio_frame(OutputStream *ost)
313 AVFrame *frame = ost->tmp_frame;
318 if (av_compare_ts(ost->next_pts, ost->enc->time_base,
323 v = (int)(sin(ost->t) * 10000);
324 for (i = 0; i < ost->enc->ch_layout.nb_channels; i++)
326 ost->t += ost->tincr;
327 ost->tincr += ost->tincr2;
330 frame->pts = ost->next_pts;
331 ost->next_pts += frame->nb_samples;
340 static int write_audio_frame(AVFormatContext *oc, OutputStream *ost)
347 c = ost->enc;
349 frame = get_audio_frame(ost);
354 dst_nb_samples = av_rescale_rnd(swr_get_delay(ost->swr_ctx, c->sample_rate) + frame->nb_samples,
362 ret = av_frame_make_writable(ost->frame);
367 ret = swr_convert(ost->swr_ctx,
368 ost->frame->data, dst_nb_samples,
374 frame = ost->frame;
376 frame->pts = av_rescale_q(ost->samples_count, (AVRational){1, c->sample_rate}, c->time_base);
377 ost->samples_count += dst_nb_samples;
380 return write_frame(oc, c, ost->st, frame, ost->tmp_pkt);
410 OutputStream *ost, AVDictionary *opt_arg)
413 AVCodecContext *c = ost->enc;
427 ost->frame = alloc_picture(c->pix_fmt, c->width, c->height);
428 if (!ost->frame) {
436 ost->tmp_frame = NULL;
438 ost->tmp_frame = alloc_picture(AV_PIX_FMT_YUV420P, c->width, c->height);
439 if (!ost->tmp_frame) {
446 ret = avcodec_parameters_from_context(ost->st->codecpar, c);
475 static AVFrame *get_video_frame(OutputStream *ost)
477 AVCodecContext *c = ost->enc;
480 if (av_compare_ts(ost->next_pts, c->time_base,
486 if (av_frame_make_writable(ost->frame) < 0)
492 if (!ost->sws_ctx) {
493 ost->sws_ctx = sws_getContext(c->width, c->height,
498 if (!ost->sws_ctx) {
504 fill_yuv_image(ost->tmp_frame, ost->next_pts, c->width, c->height);
505 sws_scale(ost->sws_ctx, (const uint8_t * const *) ost->tmp_frame->data,
506 ost->tmp_frame->linesize, 0, c->height, ost->frame->data,
507 ost->frame->linesize);
509 fill_yuv_image(ost->frame, ost->next_pts, c->width, c->height);
512 ost->frame->pts = ost->next_pts++;
514 return ost->frame;
521 static int write_video_frame(AVFormatContext *oc, OutputStream *ost)
523 return write_frame(oc, ost->enc, ost->st, get_video_frame(ost), ost->tmp_pkt);
526 static void close_stream(AVFormatContext *oc, OutputStream *ost)
528 avcodec_free_context(&ost->enc);
529 av_frame_free(&ost->frame);
530 av_frame_free(&ost->tmp_frame);
531 av_packet_free(&ost->tmp_pkt);
532 sws_freeContext(ost->sws_ctx);
533 swr_free(&ost->swr_ctx);