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 BAE8043A76 for ; Wed, 6 Jul 2022 19:03:47 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C0DC768BA9F; Wed, 6 Jul 2022 22:03:44 +0300 (EEST) Received: from mail-vs1-f45.google.com (mail-vs1-f45.google.com [209.85.217.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ECE6A68B890 for ; Wed, 6 Jul 2022 22:03:37 +0300 (EEST) Received: by mail-vs1-f45.google.com with SMTP id f68so1204862vsc.11 for ; Wed, 06 Jul 2022 12:03:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=UcCJhh+7GQFN4UCDoTtndwlXyrziYRua8sqgo5MVTl4=; b=mmeWdcv2lUEi6YjWNzv/+XNtDC6IbBka7ReIeL0Ta8NKjz7vGzfY2N96ujlnh3gOFG jtFJ2BlPbdlAgvZr/nAHolQ9Py0LT56veYArXN4XWIL8BvG3iVvcTeZX3TxHFzVnWHzJ bWPm4P8snvUyfheqv95wibp8fY7JJsy72Y7DhWGB4A5popUK4iHCQL4JotxIBlzD8fBy eQZi655dQ1yGxsDvamcMh8K38H2w2JpTVttkEt2dxIgWDwsfVdYqt/QJHFxInRU3GeoZ /C1hXbwOHTO77qHi9gGryKt8fxHp+dqZ6sCjfhMFu3zttUqohgD1oBt7HnOadZAcm1KK QAVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=UcCJhh+7GQFN4UCDoTtndwlXyrziYRua8sqgo5MVTl4=; b=nKZvV9PbA4PhlXuG9B+elii/7RC7p/zfgNtEcYmfhS6w3EgLgDmChRXqjVEZ7hEk89 m7oyRv4ury5AIEf116rW5HbJliEcoAAZRYq8khc5SlMkbDbxz8aNQdd2UvpKCEPuESsV X/skZJNRoOQpIhOmFZruFIZqYjUhc/VzzoTGLsnvoKQHGYcnIR+Fk8/QiJRLCkKuz2o6 tKt+YD9WDvo5c8bPuyiNXgyMO6i9ZxIte+ENsl53i/gGEOQZAjqQqdX0oGfV03SOrVCL tmM4FQFxdNbgWrTWLV3jQeqZs+DjUNxjD++0zymnHqpapXQq5n9F1+bv2Qvdcui1xQgt Orlg== X-Gm-Message-State: AJIora9b1SSbbnPEA3HgmpbNEQiEEManwQE4TKfepblvl7Bem4+6CF6Q pwS4VghepIg5EVmht+2E9JZaaSLDT1FIhg== X-Google-Smtp-Source: AGRyM1t7LRm02ECs7bLYvqwEUIxZKv5bs6Uee5W5XyL/l78CAolbscbwXY+nJRod0M3K8FAc7jDJag== X-Received: by 2002:a05:6102:53b:b0:354:23f9:a4db with SMTP id m27-20020a056102053b00b0035423f9a4dbmr22903957vsa.34.1657134215973; Wed, 06 Jul 2022 12:03:35 -0700 (PDT) Received: from [192.168.0.13] ([186.136.131.204]) by smtp.gmail.com with ESMTPSA id w21-20020ab05a95000000b0037f2d768f1fsm10156714uae.18.2022.07.06.12.03.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 06 Jul 2022 12:03:35 -0700 (PDT) Message-ID: <94f04adc-3aef-3e8e-cb63-5746b20e9325@gmail.com> Date: Wed, 6 Jul 2022 16:03:34 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: From: James Almer In-Reply-To: Subject: Re: [FFmpeg-devel] [PATCH] avcodec: add Radiance HDR image format support 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 7/6/2022 3:47 PM, Paul B Mahol wrote: > Added parser. > The test will be added after this is merged. [...] > +static int hdr_parse(AVCodecParserContext *s, AVCodecContext *avctx, > + const uint8_t **poutbuf, int *poutbuf_size, > + const uint8_t *buf, int buf_size) > +{ > + HDRParseContext *ipc = s->priv_data; > + uint64_t state = ipc->pc.state64; > + int next = END_NOT_FOUND, i = 0; > + > + s->pict_type = AV_PICTURE_TYPE_NONE; pict_type I, and key frame? [...] > +static int hdr_encode_frame(AVCodecContext *avctx, AVPacket *pkt, > + const AVFrame *frame, int *got_packet) > +{ > + HDREncContext *s = avctx->priv_data; > + int64_t packet_size; > + uint8_t *buf; > + int ret; > + > + packet_size = avctx->width * avctx->height * 4LL + 1024LL; > + if ((ret = ff_get_encode_buffer(avctx, pkt, packet_size, 0)) < 0) Wont using worst case scenario like this result in massive packets? av_shrink_packet() only changes the size field, it doesn't realloc the buffer to shrink it. You could allocate a buffer in HDREncContext with av_fast_padded_malloc() here, use the bytestream2 API below, then allocate the packet with ff_get_encode_buffer() using bytestream2_tell_p() as size and do a memcpy at the end. > + return ret; > + > + buf = pkt->data; > + bytestream_put_str(&buf, "#?RADIANCE\n"); > + bytestream_put_str(&buf, "SOFTWARE=lavc\n"); > + ret = snprintf(buf, 32, "PIXASPECT=%f\n", av_q2d(av_inv_q(avctx->sample_aspect_ratio))); > + if (ret > 0) > + buf += ret; > + bytestream_put_str(&buf, "FORMAT=32-bit_rle_rgbe\n\n"); > + ret = snprintf(buf, 32, "-Y %d +X %d\n", avctx->height, avctx->width); > + if (ret > 0) > + buf += ret; > + > + for (int y = 0; y < avctx->height; y++) { > + const float *red = (const float *)(frame->data[2] + y * frame->linesize[2]); > + const float *green = (const float *)(frame->data[0] + y * frame->linesize[0]); > + const float *blue = (const float *)(frame->data[1] + y * frame->linesize[1]); > + > + if (avctx->width < 8 || avctx->width > 0x7fff) { > + for (int x = 0; x < avctx->width; x++) { > + float2rgbe(buf, red[x], green[x], blue[x]); > + buf += 4; > + } > + } else { > + bytestream_put_byte(&buf, 2); > + bytestream_put_byte(&buf, 2); > + bytestream_put_byte(&buf, avctx->width >> 8); > + bytestream_put_byte(&buf, avctx->width & 0xFF); > + > + for (int x = 0; x < avctx->width; x++) > + float2rgbe(s->scanline + 4 * x, red[x], green[x], blue[x]); > + for (int p = 0; p < 4; p++) > + rle(&buf, s->scanline + p, avctx->width); > + } > + } > + > + pkt->flags |= AV_PKT_FLAG_KEY; > + > + av_shrink_packet(pkt, buf - pkt->data); > + > + *got_packet = 1; > + > + return 0; > +} _______________________________________________ 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".