You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +02:00 
			
		
		
		
	lavfi: add video buffer sink, and use it in avtools
Also add the public interface libavfilter/buffersink.h. Based on a commit by Stefano Sabatini.
This commit is contained in:
		
							
								
								
									
										68
									
								
								cmdutils.c
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								cmdutils.c
									
									
									
									
									
								
							| @@ -1021,74 +1021,6 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, | ||||
|     return opts; | ||||
| } | ||||
|  | ||||
| #if CONFIG_AVFILTER | ||||
|  | ||||
| static int sink_init(AVFilterContext *ctx, const char *args, void *opaque) | ||||
| { | ||||
|     SinkContext *priv = ctx->priv; | ||||
|  | ||||
|     if (!opaque) | ||||
|         return AVERROR(EINVAL); | ||||
|     *priv = *(SinkContext *)opaque; | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
| static void null_end_frame(AVFilterLink *inlink) { } | ||||
|  | ||||
| static int sink_query_formats(AVFilterContext *ctx) | ||||
| { | ||||
|     SinkContext *priv = ctx->priv; | ||||
|  | ||||
|     if (priv->pix_fmts) | ||||
|         avfilter_set_common_formats(ctx, avfilter_make_format_list(priv->pix_fmts)); | ||||
|     else | ||||
|         avfilter_default_query_formats(ctx); | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
| AVFilter sink = { | ||||
|     .name      = "sink", | ||||
|     .priv_size = sizeof(SinkContext), | ||||
|     .init      = sink_init, | ||||
|  | ||||
|     .query_formats = sink_query_formats, | ||||
|  | ||||
|     .inputs    = (AVFilterPad[]) {{ .name          = "default", | ||||
|                                     .type          = AVMEDIA_TYPE_VIDEO, | ||||
|                                     .end_frame     = null_end_frame, | ||||
|                                     .min_perms     = AV_PERM_READ, }, | ||||
|                                   { .name = NULL }}, | ||||
|     .outputs   = (AVFilterPad[]) {{ .name = NULL }}, | ||||
| }; | ||||
|  | ||||
| int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame, | ||||
|                              AVFilterBufferRef **picref_ptr, AVRational *tb) | ||||
| { | ||||
|     int ret; | ||||
|     AVFilterBufferRef *picref; | ||||
|  | ||||
|     if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0) | ||||
|         return ret; | ||||
|     if (!(picref = ctx->inputs[0]->cur_buf)) | ||||
|         return AVERROR(ENOENT); | ||||
|     *picref_ptr = picref; | ||||
|     ctx->inputs[0]->cur_buf = NULL; | ||||
|     *tb = ctx->inputs[0]->time_base; | ||||
|  | ||||
|     memcpy(frame->data,     picref->data,     sizeof(frame->data)); | ||||
|     memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize)); | ||||
|     frame->interlaced_frame    = picref->video->interlaced; | ||||
|     frame->top_field_first     = picref->video->top_field_first; | ||||
|     frame->key_frame           = picref->video->key_frame; | ||||
|     frame->pict_type           = picref->video->pict_type; | ||||
|     frame->sample_aspect_ratio = picref->video->pixel_aspect; | ||||
|  | ||||
|     return 1; | ||||
| } | ||||
|  | ||||
| #endif /* CONFIG_AVFILTER */ | ||||
|  | ||||
| void *grow_array(void *array, int elem_size, int *size, int new_size) | ||||
| { | ||||
|     if (new_size >= INT_MAX / elem_size) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user