From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 6E61345884 for ; Fri, 24 Feb 2023 13:47:20 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C1ADA68C141; Fri, 24 Feb 2023 15:47:18 +0200 (EET) Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3901D68C10C for ; Fri, 24 Feb 2023 15:47:13 +0200 (EET) Received: by mail-ed1-f49.google.com with SMTP id i34so29669073eda.7 for ; Fri, 24 Feb 2023 05:47:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=wISad06gpzobtR+5lD8YVVhl0oaYtRxJaasmZ7FSeyc=; b=LEjDHkkai9aqKq1Pi8OlTgPx7o7rEILNYXuPaugVOoCxS0sL3S2asUnaFCOCuqpi+B 8gvbb3el+qHYiAnnlgQaqGFDLO7ULfgzg1e5gbPJY+hqe8Q8gFWE+BeRf5N6ZGqfbZnv o5TnrC92n38g8NOds3gQgObKdWSV3DLaUYEbZXhb+c4wq1i4I+qHIwDqZJP2x1baRwl+ gk5AwldgxO77H0ReIMdHeLcU3DeTwHKg41ojwOilmisfpQGCAyIq/+/RmcqRGY383XdC 4d8BV2+Fzsk343gG90MTDChu/KF+f+35d70E10XBhWfM3znE6W3nXMpz84bS73QPX26+ lnQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wISad06gpzobtR+5lD8YVVhl0oaYtRxJaasmZ7FSeyc=; b=Jlc3MQa9wqEdBeY1AVlm3giKh32/eznTgGye9BgtyhbsMpBMOtxxO955aju9GoMTJ8 eXQ6IbIxHl53tJu8L5ReePvRZtzjF38J9+gdBAPi/bJexTEWeXsg81D1dgEYgQyik+sm hiTqmtpO4guq5ouuN571v45re4Yh8fMHohT+K1b2deCGK4NqY+pQkoYQJ441aMi63qpr vLON6yZihkP8AGRxkmtKl7QhMf4pfugDYRyj0gEwtCVry4eNdYjwantENceWKfFI9rBM 0Jj5dXLssHvWEZk/VxEN42DEyEgklhsVcy9Vu6Cv9y7U5/zSVHI+zMaNbsYpN4EawOSl vKEQ== X-Gm-Message-State: AO0yUKUnPsPQU+dvdLIyEmZDSsiP+RVmWiuMWOMea74lJB4r04BC3aRk Jbm6oXUL8W780Q6+97oAxdruXgj0GFaBb1YRiPCYIfrGwfI= X-Google-Smtp-Source: AK7set8TGLgxPmWtvqtlevn/0cVTzUeKr9V1G3UEVPnMBdK1DFgJsUqA7/Kt5g9C34DGxvGKo2lJoECNjwhNHtDms54= X-Received: by 2002:a50:d08d:0:b0:4ad:7c43:13c with SMTP id v13-20020a50d08d000000b004ad7c43013cmr7175611edd.2.1677246432115; Fri, 24 Feb 2023 05:47:12 -0800 (PST) MIME-Version: 1.0 References: <1677176098.0668886000.bos3u4y6@frv55.fwdcdn.com> In-Reply-To: <1677176098.0668886000.bos3u4y6@frv55.fwdcdn.com> From: "Ronald S. Bultje" Date: Fri, 24 Feb 2023 08:47:00 -0500 Message-ID: To: FFmpeg development discussions and patches X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: Re: [FFmpeg-devel] How to use threads inside custom encoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Hi, On Thu, Feb 23, 2023 at 1:28 PM Alex <3.14pi@ukr.net> wrote: > Hi! > I write custom encoder codec and want to use threads to speed up encoding > process. I know what ffmpeg have frame level threads and slices threads, > but in my case best option is to use frame level threads > with FF_CODEC_ENCODE_CB() function. > But I have couple of questions: > > 1) Then I add AV_CODEC_CAP_FRAME_THREADS flag to capabilities of my > encoder then ffmpeg call init function of my encoder for each spawned > threads (for example 9 times because I have 8 core cpu ). How to prevent > this and call init function only once? (I need to reuse encoder context.) > In frame threading, each "frame instance" has its own context. They can be synchronized and use dependent data. See how other codecs do this, e.g. h264 decoder (the concept is identical between encoder & decoder). You can, for example, use avcodec->internal->is_copy for this. See update_thread_context() for synchronization between threads. If this design doesn't work for you, you don't have to use the frame-level API. Just mark them as slice threads and everything can be managed inside your codec without the frame-threading API "overhead". 2) Is it possible to request more decoded frames inside encode callback > function? > Encoders can simply buffer frames and output only when ready (this is why send/receive are separate API), see AV_CODEC_CAP_DELAY. Ronald _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".