00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "avcodec.h"
00027 #include "libavutil/opt.h"
00028
00029 AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame,
00030 int perms)
00031 {
00032 AVFilterBufferRef *picref =
00033 avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize, perms,
00034 frame->width, frame->height,
00035 frame->format);
00036 if (!picref)
00037 return NULL;
00038 avfilter_copy_frame_props(picref, frame);
00039 return picref;
00040 }
00041
00042 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame,
00043 int perms)
00044 {
00045 AVFilterBufferRef *picref =
00046 avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms,
00047 frame->nb_samples, frame->format,
00048 av_frame_get_channel_layout(frame));
00049 if (!picref)
00050 return NULL;
00051 avfilter_copy_frame_props(picref, frame);
00052 return picref;
00053 }
00054
00055 int avfilter_fill_frame_from_audio_buffer_ref(AVFrame *frame,
00056 const AVFilterBufferRef *samplesref)
00057 {
00058 if (!samplesref || !samplesref->audio || !frame)
00059 return AVERROR(EINVAL);
00060
00061 memcpy(frame->data, samplesref->data, sizeof(frame->data));
00062 memcpy(frame->linesize, samplesref->linesize, sizeof(frame->linesize));
00063 av_frame_set_pkt_pos(frame, samplesref->pos);
00064 frame->format = samplesref->format;
00065 frame->nb_samples = samplesref->audio->nb_samples;
00066 frame->pts = samplesref->pts;
00067 frame->sample_rate = samplesref->audio->sample_rate;
00068 frame->channel_layout = samplesref->audio->channel_layout;
00069
00070 return 0;
00071 }
00072
00073 int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
00074 const AVFilterBufferRef *picref)
00075 {
00076 if (!picref || !picref->video || !frame)
00077 return AVERROR(EINVAL);
00078
00079 memcpy(frame->data, picref->data, sizeof(frame->data));
00080 memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
00081 av_frame_set_pkt_pos(frame, picref->pos);
00082 frame->interlaced_frame = picref->video->interlaced;
00083 frame->top_field_first = picref->video->top_field_first;
00084 frame->key_frame = picref->video->key_frame;
00085 frame->pict_type = picref->video->pict_type;
00086 frame->sample_aspect_ratio = picref->video->sample_aspect_ratio;
00087 frame->width = picref->video->w;
00088 frame->height = picref->video->h;
00089 frame->format = picref->format;
00090 frame->pts = picref->pts;
00091
00092 return 0;
00093 }
00094
00095 int avfilter_fill_frame_from_buffer_ref(AVFrame *frame,
00096 const AVFilterBufferRef *ref)
00097 {
00098 if (!ref)
00099 return AVERROR(EINVAL);
00100 return ref->video ? avfilter_fill_frame_from_video_buffer_ref(frame, ref)
00101 : avfilter_fill_frame_from_audio_buffer_ref(frame, ref);
00102 }