Re: [FFmpeg-devel] [PATCH] examples/vaapi_encode: Add a VA-API encode example.
On 06/11/17 06:56, Jun Zhao wrote: > From d16f766363d9ecc240b0f8e025c2a8f91ea4775e Mon Sep 17 00:00:00 2001 > From: Jun Zhao> Date: Mon, 6 Nov 2017 14:45:27 +0800 > Subject: [PATCH] examples/vaapi_encode: Add a VA-API encode example. > > add a VA-API encode example, only support NV12 input, usage like: > ./vaapi_encode 1920 1080 test.yuv test.h264 > > Signed-off-by: Jun Zhao > Signed-off-by: Liu, Kaixuan > --- > configure | 2 + > doc/examples/Makefile | 1 + > doc/examples/vaapi_encode.c | 308 > > 3 files changed, 311 insertions(+) > create mode 100644 doc/examples/vaapi_encode.c > > diff --git a/configure b/configure > index 1b0f064607..2df0205e09 100755 > --- a/configure > +++ b/configure > @@ -1524,6 +1524,7 @@ EXAMPLE_LIST=" > scaling_video_example > transcode_aac_example > transcoding_example > +vaapi_encode_example > " > > EXTERNAL_AUTODETECT_LIBRARY_LIST=" > @@ -3294,6 +3295,7 @@ resampling_audio_example_deps="avutil swresample" > scaling_video_example_deps="avutil swscale" > transcode_aac_example_deps="avcodec avformat swresample" > transcoding_example_deps="avfilter avcodec avformat avutil" > +vaapi_encode_example_deps="avfilter avcodec avformat avutil" > > # EXTRALIBS_LIST > cpu_init_extralibs="pthreads_extralibs" > diff --git a/doc/examples/Makefile b/doc/examples/Makefile > index 58afd71b85..da5af36532 100644 > --- a/doc/examples/Makefile > +++ b/doc/examples/Makefile > @@ -19,6 +19,7 @@ EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE) += > resampling_audio > EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video > EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE) += transcode_aac > EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE) += transcoding > +EXAMPLES-$(CONFIG_VAAPI_ENCODE_EXAMPLE) += vaapi_encode > > EXAMPLES := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)$(EXESUF)) > EXAMPLES_G := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)_g$(EXESUF)) > diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c > new file mode 100644 > index 00..02b1ac5a4a > --- /dev/null > +++ b/doc/examples/vaapi_encode.c > @@ -0,0 +1,308 @@ > +/* > + * Video Acceleration API (video encoding) encode sample > + * > + * This file is part of FFmpeg. > + * > + * FFmpeg is free software; you can redistribute it and/or > + * modify it under the terms of the GNU Lesser General Public > + * License as published by the Free Software Foundation; either > + * version 2.1 of the License, or (at your option) any later version. > + * > + * FFmpeg is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + * Lesser General Public License for more details. > + * > + * You should have received a copy of the GNU Lesser General Public > + * License along with FFmpeg; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + */ > + > +/** > + * @file > + * Intel VAAPI-accelerated encoding example. > + * > + * @example vaapi_encode.c > + * This example shows how to do VAAPI-accelerated encoding. now only support > NV12 > + * raw file, usage like: vaapi_enc 1920 1080 input.yuv output.h264 > + */ > + > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +typedef struct FilterContext { > +AVFilterContext *buffersink_ctx; > +AVFilterContext *buffersrc_ctx; > +AVFilterGraph *filter_graph; > +} FilterContext; > + > +static int width, height; > +static AVBufferRef *hw_device_ctx = NULL; > + > +static int init_filter(FilterContext *filter_ctx, char *args, AVBufferRef > *hw_device_ctx) > +{ > +char filter_spec[] = "format=nv12,hwupload"; > +int ret = 0, i = 0; > +const AVFilter *buffersrc, *buffersink; > +AVFilterContext *buffersrc_ctx, *buffersink_ctx; > +AVFilterInOut *outputs = avfilter_inout_alloc(); > +AVFilterInOut *inputs = avfilter_inout_alloc(); > +AVFilterGraph *filter_graph = avfilter_graph_alloc(); > + > +buffersrc = avfilter_get_by_name("buffer"); > +buffersink = avfilter_get_by_name("buffersink"); > +if (!buffersrc || !buffersink) { > +av_log(NULL, AV_LOG_ERROR, "filtering source or sink element not > found\n"); > +ret = AVERROR_UNKNOWN; > +goto fail; > +} > + > +ret = avfilter_graph_create_filter(_ctx, buffersrc, "in", > + args, NULL, filter_graph); > +if (ret < 0) { > +av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source. Error > code:%s\n", av_err2str(ret)); > +goto fail; > +} > +ret = avfilter_graph_create_filter(_ctx, buffersink, "out", > +
Re: [FFmpeg-devel] [PATCH] examples/vaapi_encode: Add a VA-API encode example.
On 2017/11/7 9:38, Michael Niedermayer wrote: > On Mon, Nov 06, 2017 at 02:56:16PM +0800, Jun Zhao wrote: >> configure |2 >> doc/examples/Makefile |1 >> doc/examples/vaapi_encode.c | 308 >> >> 3 files changed, 311 insertions(+) >> b4a1cfca5fb56770fae68218661f060e25ffe769 >> 0001-examples-vaapi_encode-Add-a-VA-API-encode-example.patch >> From d16f766363d9ecc240b0f8e025c2a8f91ea4775e Mon Sep 17 00:00:00 2001 >> From: Jun Zhao>> Date: Mon, 6 Nov 2017 14:45:27 +0800 >> Subject: [PATCH] examples/vaapi_encode: Add a VA-API encode example. >> >> add a VA-API encode example, only support NV12 input, usage like: >> ./vaapi_encode 1920 1080 test.yuv test.h264 >> >> Signed-off-by: Jun Zhao >> Signed-off-by: Liu, Kaixuan >> --- >> configure | 2 + >> doc/examples/Makefile | 1 + >> doc/examples/vaapi_encode.c | 308 >> >> 3 files changed, 311 insertions(+) >> create mode 100644 doc/examples/vaapi_encode.c > fails to build > arm$ make examples > CC doc/examples/vaapi_encode.o > src/doc/examples/vaapi_encode.c:36:39: fatal error: > libavfilter/avfiltergraph.h: No such file or directory > compilation terminated. > make: *** [doc/examples/vaapi_encode.o] Error 1 > > > [...] Will submit V2 to fix the build error. Tks. > > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] examples/vaapi_encode: Add a VA-API encode example.
On Mon, Nov 06, 2017 at 02:56:16PM +0800, Jun Zhao wrote: > > configure |2 > doc/examples/Makefile |1 > doc/examples/vaapi_encode.c | 308 > > 3 files changed, 311 insertions(+) > b4a1cfca5fb56770fae68218661f060e25ffe769 > 0001-examples-vaapi_encode-Add-a-VA-API-encode-example.patch > From d16f766363d9ecc240b0f8e025c2a8f91ea4775e Mon Sep 17 00:00:00 2001 > From: Jun Zhao> Date: Mon, 6 Nov 2017 14:45:27 +0800 > Subject: [PATCH] examples/vaapi_encode: Add a VA-API encode example. > > add a VA-API encode example, only support NV12 input, usage like: > ./vaapi_encode 1920 1080 test.yuv test.h264 > > Signed-off-by: Jun Zhao > Signed-off-by: Liu, Kaixuan > --- > configure | 2 + > doc/examples/Makefile | 1 + > doc/examples/vaapi_encode.c | 308 > > 3 files changed, 311 insertions(+) > create mode 100644 doc/examples/vaapi_encode.c fails to build arm$ make examples CC doc/examples/vaapi_encode.o src/doc/examples/vaapi_encode.c:36:39: fatal error: libavfilter/avfiltergraph.h: No such file or directory compilation terminated. make: *** [doc/examples/vaapi_encode.o] Error 1 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB The educated differ from the uneducated as much as the living from the dead. -- Aristotle signature.asc Description: Digital signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] examples/vaapi_encode: Add a VA-API encode example.
From d16f766363d9ecc240b0f8e025c2a8f91ea4775e Mon Sep 17 00:00:00 2001 From: Jun ZhaoDate: Mon, 6 Nov 2017 14:45:27 +0800 Subject: [PATCH] examples/vaapi_encode: Add a VA-API encode example. add a VA-API encode example, only support NV12 input, usage like: ./vaapi_encode 1920 1080 test.yuv test.h264 Signed-off-by: Jun Zhao Signed-off-by: Liu, Kaixuan --- configure | 2 + doc/examples/Makefile | 1 + doc/examples/vaapi_encode.c | 308 3 files changed, 311 insertions(+) create mode 100644 doc/examples/vaapi_encode.c diff --git a/configure b/configure index 1b0f064607..2df0205e09 100755 --- a/configure +++ b/configure @@ -1524,6 +1524,7 @@ EXAMPLE_LIST=" scaling_video_example transcode_aac_example transcoding_example +vaapi_encode_example " EXTERNAL_AUTODETECT_LIBRARY_LIST=" @@ -3294,6 +3295,7 @@ resampling_audio_example_deps="avutil swresample" scaling_video_example_deps="avutil swscale" transcode_aac_example_deps="avcodec avformat swresample" transcoding_example_deps="avfilter avcodec avformat avutil" +vaapi_encode_example_deps="avfilter avcodec avformat avutil" # EXTRALIBS_LIST cpu_init_extralibs="pthreads_extralibs" diff --git a/doc/examples/Makefile b/doc/examples/Makefile index 58afd71b85..da5af36532 100644 --- a/doc/examples/Makefile +++ b/doc/examples/Makefile @@ -19,6 +19,7 @@ EXAMPLES-$(CONFIG_RESAMPLING_AUDIO_EXAMPLE) += resampling_audio EXAMPLES-$(CONFIG_SCALING_VIDEO_EXAMPLE) += scaling_video EXAMPLES-$(CONFIG_TRANSCODE_AAC_EXAMPLE) += transcode_aac EXAMPLES-$(CONFIG_TRANSCODING_EXAMPLE) += transcoding +EXAMPLES-$(CONFIG_VAAPI_ENCODE_EXAMPLE) += vaapi_encode EXAMPLES := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)$(EXESUF)) EXAMPLES_G := $(EXAMPLES-yes:%=doc/examples/%$(PROGSSUF)_g$(EXESUF)) diff --git a/doc/examples/vaapi_encode.c b/doc/examples/vaapi_encode.c new file mode 100644 index 00..02b1ac5a4a --- /dev/null +++ b/doc/examples/vaapi_encode.c @@ -0,0 +1,308 @@ +/* + * Video Acceleration API (video encoding) encode sample + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Intel VAAPI-accelerated encoding example. + * + * @example vaapi_encode.c + * This example shows how to do VAAPI-accelerated encoding. now only support NV12 + * raw file, usage like: vaapi_enc 1920 1080 input.yuv output.h264 + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +typedef struct FilterContext { +AVFilterContext *buffersink_ctx; +AVFilterContext *buffersrc_ctx; +AVFilterGraph *filter_graph; +} FilterContext; + +static int width, height; +static AVBufferRef *hw_device_ctx = NULL; + +static int init_filter(FilterContext *filter_ctx, char *args, AVBufferRef *hw_device_ctx) +{ +char filter_spec[] = "format=nv12,hwupload"; +int ret = 0, i = 0; +const AVFilter *buffersrc, *buffersink; +AVFilterContext *buffersrc_ctx, *buffersink_ctx; +AVFilterInOut *outputs = avfilter_inout_alloc(); +AVFilterInOut *inputs = avfilter_inout_alloc(); +AVFilterGraph *filter_graph = avfilter_graph_alloc(); + +buffersrc = avfilter_get_by_name("buffer"); +buffersink = avfilter_get_by_name("buffersink"); +if (!buffersrc || !buffersink) { +av_log(NULL, AV_LOG_ERROR, "filtering source or sink element not found\n"); +ret = AVERROR_UNKNOWN; +goto fail; +} + +ret = avfilter_graph_create_filter(_ctx, buffersrc, "in", + args, NULL, filter_graph); +if (ret < 0) { +av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source. Error code:%s\n", av_err2str(ret)); +goto fail; +} +ret = avfilter_graph_create_filter(_ctx, buffersink, "out", + NULL, NULL, filter_graph); +if (ret < 0) { +av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink. Error code:%s\n", av_err2str(ret)); +goto fail; +} + +outputs->name = av_strdup("in"); +outputs->filter_ctx = buffersrc_ctx; +outputs->pad_idx= 0; +outputs->next