avcodec.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2011 Stefano Sabatini | stefasab at gmail.com
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * libavcodec/libavfilter gluing utilities
  23. */
  24. #include "avcodec.h"
  25. #include "libavutil/opt.h"
  26. AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame,
  27. int perms)
  28. {
  29. AVFilterBufferRef *picref =
  30. avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize, perms,
  31. frame->width, frame->height,
  32. frame->format);
  33. if (!picref)
  34. return NULL;
  35. avfilter_copy_frame_props(picref, frame);
  36. return picref;
  37. }
  38. AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame,
  39. int perms)
  40. {
  41. AVFilterBufferRef *picref =
  42. avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms,
  43. frame->nb_samples, frame->format,
  44. av_frame_get_channel_layout(frame));
  45. if (!picref)
  46. return NULL;
  47. avfilter_copy_frame_props(picref, frame);
  48. return picref;
  49. }
  50. int avfilter_fill_frame_from_audio_buffer_ref(AVFrame *frame,
  51. const AVFilterBufferRef *samplesref)
  52. {
  53. if (!samplesref || !samplesref->audio || !frame)
  54. return AVERROR(EINVAL);
  55. memcpy(frame->data, samplesref->data, sizeof(frame->data));
  56. memcpy(frame->linesize, samplesref->linesize, sizeof(frame->linesize));
  57. av_frame_set_pkt_pos(frame, samplesref->pos);
  58. frame->format = samplesref->format;
  59. frame->nb_samples = samplesref->audio->nb_samples;
  60. frame->pts = samplesref->pts;
  61. frame->sample_rate = samplesref->audio->sample_rate;
  62. frame->channel_layout = samplesref->audio->channel_layout;
  63. return 0;
  64. }
  65. int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame,
  66. const AVFilterBufferRef *picref)
  67. {
  68. if (!picref || !picref->video || !frame)
  69. return AVERROR(EINVAL);
  70. memcpy(frame->data, picref->data, sizeof(frame->data));
  71. memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize));
  72. av_frame_set_pkt_pos(frame, picref->pos);
  73. frame->interlaced_frame = picref->video->interlaced;
  74. frame->top_field_first = picref->video->top_field_first;
  75. frame->key_frame = picref->video->key_frame;
  76. frame->pict_type = picref->video->pict_type;
  77. frame->sample_aspect_ratio = picref->video->sample_aspect_ratio;
  78. frame->width = picref->video->w;
  79. frame->height = picref->video->h;
  80. frame->format = picref->format;
  81. frame->pts = picref->pts;
  82. return 0;
  83. }
  84. int avfilter_fill_frame_from_buffer_ref(AVFrame *frame,
  85. const AVFilterBufferRef *ref)
  86. {
  87. if (!ref)
  88. return AVERROR(EINVAL);
  89. return ref->video ? avfilter_fill_frame_from_video_buffer_ref(frame, ref)
  90. : avfilter_fill_frame_from_audio_buffer_ref(frame, ref);
  91. }