libavfilter/avcodec.c
Go to the documentation of this file.
00001 /*
00002  * This file is part of FFmpeg.
00003  *
00004  * FFmpeg is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * FFmpeg is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with FFmpeg; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00017  */
00018 
00024 #include "avcodec.h"
00025 
00026 int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
00027 {
00028     dst->pts    = src->pts;
00029     dst->pos    = src->pkt_pos;
00030     dst->format = src->format;
00031 
00032     switch (dst->type) {
00033     case AVMEDIA_TYPE_VIDEO:
00034         dst->video->w                   = src->width;
00035         dst->video->h                   = src->height;
00036         dst->video->sample_aspect_ratio = src->sample_aspect_ratio;
00037         dst->video->interlaced          = src->interlaced_frame;
00038         dst->video->top_field_first     = src->top_field_first;
00039         dst->video->key_frame           = src->key_frame;
00040         dst->video->pict_type           = src->pict_type;
00041     }
00042 
00043     return 0;
00044 }
00045 
00046 AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame,
00047                                                             int perms)
00048 {
00049     AVFilterBufferRef *picref =
00050         avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize, perms,
00051                                                   frame->width, frame->height,
00052                                                   frame->format);
00053     if (!picref)
00054         return NULL;
00055     avfilter_copy_frame_props(picref, frame);
00056     return picref;
00057 }
00058 
00059 int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
00060                                               const AVFilterBufferRef *picref)
00061 {
00062     if (!picref || !picref->video || !frame)
00063         return AVERROR(EINVAL);
00064 
00065     memcpy(frame->data,     picref->data,     sizeof(frame->data));
00066     memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
00067     frame->pkt_pos          = picref->pos;
00068     frame->interlaced_frame = picref->video->interlaced;
00069     frame->top_field_first  = picref->video->top_field_first;
00070     frame->key_frame        = picref->video->key_frame;
00071     frame->pict_type        = picref->video->pict_type;
00072     frame->sample_aspect_ratio = picref->video->sample_aspect_ratio;
00073 
00074     return 0;
00075 }