You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.6KB

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