From patchwork Fri Jul 21 05:40:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhong Li X-Patchwork-Id: 4407 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp476512vsb; Thu, 20 Jul 2017 22:39:15 -0700 (PDT) X-Received: by 10.28.128.215 with SMTP id b206mr3982720wmd.88.1500615555512; Thu, 20 Jul 2017 22:39:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500615555; cv=none; d=google.com; s=arc-20160816; b=KilC83sHEcRhVnE5wvYFu7QvTHxh3tFw6MqVt7W2CwXPTBZN9kzSD/8L9rzecc84aJ 43c0fuVM5UrWeRbEsLIaaqNA1ZYPeZsOrvfjWn05NrXEKp6LxZBvaJJl56FrZ1TKRwjP a7783DzOZrIW6CJl0sqD6EwwAbQ0j7G7CSgbOCaHgdXaAG2WJuo9lQhW6AmcFRsAu0cT fEA6gN4jEH+7eybxQcNgKSJvCtNYfLmUdo1u/O2YE5rLkIQY+zksTh656iA/iKKnb2Mi loFwjwhV0Jr/cO2VoS1nX25eKWSuikMaMXzRUn646bpZ+IpDOGv3qqrZiUGeJGA3Lf1y xF3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=7RzgZUiITbwcrrWOTeKQ3gApZW4TBTD8T4jGbzSCu3A=; b=KS9I+dhk8m5nrc+Lp1lxic3DCNkBOSbIbOp2F9vzi4pGl/C2b3qsUc3le6cdkVzA8q yrQMosz9wYuPcjt9PaJc3ry8gkK01w+e08jp5JWJFhYNDt2AprPVH/3dFjIGW/0pY0CZ 274cejNVpPvHNYn4l/HvdGScHMbCZCeJKI3ESVQMM7oaK9XxPoE60rhlZIMRqum8VCxy 9cINTOsjil/5+9HxPgPuqFGvUilRKU1/vg7a0iNqYsvYnrrshPT/N1DqWunGDSh8xYuY FSzGfLcYg8ai+9Sph7zPC4kCH+0tkN3zePuiNmuOBY1kvYfG8iz6Tm8Ynx2IuWmmk2rD 50Sw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id t128si418833wma.277.2017.07.20.22.39.12; Thu, 20 Jul 2017 22:39:15 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EED52689254; Fri, 21 Jul 2017 08:39:00 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A833C6891DD for ; Fri, 21 Jul 2017 08:38:54 +0300 (EEST) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP; 20 Jul 2017 22:39:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,388,1496127600"; d="scan'208";a="127631040" Received: from unknown (HELO localhost.localdomain.sh.intel.com) ([10.239.13.23]) by orsmga005.jf.intel.com with ESMTP; 20 Jul 2017 22:38:59 -0700 From: Zhong Li To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 Jul 2017 01:40:59 -0400 Message-Id: <1500615659-5332-1-git-send-email-zhong.li@intel.com> X-Mailer: git-send-email 1.8.3.1 Subject: [FFmpeg-devel] [PATCH] doc/examples/encode_video: add qsv encoder support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Zhong Li , sw@jkqxz.net, jun.zhao@intel.com, nfxjfg@googlemail.com MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Zhong Li --- doc/examples/encode_video.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/doc/examples/encode_video.c b/doc/examples/encode_video.c index 8cd1321..9c26f63 100644 --- a/doc/examples/encode_video.c +++ b/doc/examples/encode_video.c @@ -35,6 +35,8 @@ #include #include +#include "libavutil/buffer.h" +#include "libavutil/hwcontext.h" static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt, FILE *outfile) @@ -75,7 +77,10 @@ int main(int argc, char **argv) FILE *f; AVFrame *frame; AVPacket *pkt; + AVBufferRef* encode_device = NULL; uint8_t endcode[] = { 0, 0, 1, 0xb7 }; + enum AVHWDeviceType hw_device_type = AV_HWDEVICE_TYPE_NONE; + enum AVPixelFormat pixel_format = AV_PIX_FMT_YUV420P; if (argc <= 2) { fprintf(stderr, "Usage: %s \n", argv[0]); @@ -86,6 +91,21 @@ int main(int argc, char **argv) avcodec_register_all(); + if (strstr(codec_name, "qsv")) { + hw_device_type = AV_HWDEVICE_TYPE_QSV; + pixel_format = AV_PIX_FMT_NV12; + } + + /* open the hardware device */ + if (hw_device_type != AV_HWDEVICE_TYPE_NONE) { + ret = av_hwdevice_ctx_create(&encode_device, hw_device_type, + NULL, NULL, 0); + if (ret < 0) { + fprintf(stderr, "Cannot open the hardware device\n"); + exit(1); + } + } + /* find the mpeg1video encoder */ codec = avcodec_find_encoder_by_name(codec_name); if (!codec) { @@ -120,7 +140,7 @@ int main(int argc, char **argv) */ c->gop_size = 10; c->max_b_frames = 1; - c->pix_fmt = AV_PIX_FMT_YUV420P; + c->pix_fmt = pixel_format; if (codec->id == AV_CODEC_ID_H264) av_opt_set(c->priv_data, "preset", "slow", 0); @@ -173,8 +193,13 @@ int main(int argc, char **argv) /* Cb and Cr */ for (y = 0; y < c->height/2; y++) { for (x = 0; x < c->width/2; x++) { - frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2; - frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5; + if (frame->format == AV_PIX_FMT_YUV420P) { + frame->data[1][y * frame->linesize[1] + x] = 128 + y + i * 2; + frame->data[2][y * frame->linesize[2] + x] = 64 + x + i * 5; + } else if (frame->format == AV_PIX_FMT_NV12) { + frame->data[1][y * frame->linesize[1] + 2 * x] = 128 + y + i * 2; + frame->data[1][y * frame->linesize[1] + 2 * x + 1] = 64 + x + i * 5; + } } } @@ -194,6 +219,7 @@ int main(int argc, char **argv) avcodec_free_context(&c); av_frame_free(&frame); av_packet_free(&pkt); + av_buffer_unref(&encode_device); return 0; }