{"id":23178,"url":"https://patchwork.libcamera.org/api/1.1/patches/23178/?format=json","web_url":"https://patchwork.libcamera.org/patch/23178/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<Z/t0OSQynbJ0BhEX@duo.ucw.cz>","date":"2025-04-13T08:22:17","name":"cam: Implement %x handling","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"5d961869b4b0143fd27e8107b7d534f674dcc59a","submitter":{"id":49,"url":"https://patchwork.libcamera.org/api/1.1/people/49/?format=json","name":"Pavel Machek","email":"pavel@ucw.cz"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/23178/mbox/","series":[{"id":5125,"url":"https://patchwork.libcamera.org/api/1.1/series/5125/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5125","date":"2025-04-13T08:22:17","name":"cam: Implement %x handling","version":1,"mbox":"https://patchwork.libcamera.org/series/5125/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/23178/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/23178/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 86C85C3213\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 13 Apr 2025 08:22:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 350B268AB5;\n\tSun, 13 Apr 2025 10:22:20 +0200 (CEST)","from jabberwock.ucw.cz (jabberwock.ucw.cz [46.255.230.98])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 914FD68A38\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 13 Apr 2025 10:22:18 +0200 (CEST)","by jabberwock.ucw.cz (Postfix, from userid 1017)\n\tid 58EB71C013F; Sun, 13 Apr 2025 10:22:18 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ucw.cz header.i=@ucw.cz header.b=\"qMzubpqe\";\n\tdkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1;\n\tt=1744532538;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:mime-version:mime-version:content-type:content-type;\n\tbh=jrTEkKh1Zj48gkbYSn8Ajw8g2OFmEZud4PZv+nEpYo0=;\n\tb=qMzubpqe1q4UpmaSGkYxfdhHMte7Nr6ApQVAKVNVpi8m2QsUHgD80+57A7Jq60CLHjtcmo\n\tGmUCtJGP4LiNV8H1HLv0wcYy1bq01W0VPFet2FxZfoMtzrEX4OX/JROhJjwmPFEgkmrUhM\n\tZcW18qEIiAL1zA6NFxxCR19ytMXkjhQ=","Date":"Sun, 13 Apr 2025 10:22:17 +0200","From":"Pavel Machek <pavel@ucw.cz>","To":"laurent.pinchart@ideasonboard.com, libcamera-devel@lists.libcamera.org","Subject":"[PATCH] cam: Implement %x handling","Message-ID":"<Z/t0OSQynbJ0BhEX@duo.ucw.cz>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha1;\n\tprotocol=\"application/pgp-signature\"; boundary=\"D4dHpADtmSy0A1Yp\"","Content-Disposition":"inline","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"With raw files, we have no good place to store the metadata, yet\ntimestamp, width / height and format is useful for further\nprocessing. Implement %x so that timestamped frames etc are possible.\n    \nSigned-off-by: Pavel Machek <pavel@ucw.cz>","diff":"diff --git a/src/apps/cam/file_sink.cpp b/src/apps/cam/file_sink.cpp\nindex 65794a2f..22cdaaa2 100644\n--- a/src/apps/cam/file_sink.cpp\n+++ b/src/apps/cam/file_sink.cpp\n@@ -16,6 +16,8 @@\n #include <string.h>\n #include <unistd.h>\n #include <utility>\n+#include <chrono>\n+#include <ctime>\n \n #include <libcamera/camera.h>\n \n@@ -116,6 +118,44 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer,\n \t\tfilename.replace(pos, 1, ss.str());\n \t}\n \n+\tstd::ostringstream result;\n+\tfor (size_t i = 0; i < filename.size(); ++i) {\n+\t\tif (filename[i] == '%' && i + 1 < filename.size()) {\n+\t\t\tchar specifier = filename[i + 1];\n+\t\t\ti++; // Skip specifier character\n+\t\t\tswitch (specifier) {\n+\t\t\tcase 's':\n+\t\t\t\tresult << std::setw(6) << std::setfill('0') << buffer->metadata().sequence;\n+\t\t\t\tbreak;\n+\t\t\tcase 'w':\n+\t\t\t\tresult << stream->configuration().size.width;\n+\t\t\t\tbreak;\n+\t\t\tcase 'h':\n+\t\t\t\tresult << stream->configuration().size.height;\n+\t\t\t\tbreak;\n+\t\t\tcase 'f':\n+\t\t\t\tresult << stream->configuration().pixelFormat;\n+\t\t\t\tbreak;\n+\t\t\tcase 't': {\n+\t\t\t\tauto now = std::chrono::system_clock::now();\n+\t\t\t\tauto micros = std::chrono::duration_cast<std::chrono::microseconds>(\n+\t\t\t\t\tnow.time_since_epoch()).count();\n+\t\t\t\tresult << micros;\n+\t\t\t\tbreak;\n+\t\t\t}\n+\t\t\tcase '%':\n+\t\t\t\tresult << '%' << specifier;\n+\t\t\t\tbreak;\n+\t\t\tdefault:\n+\t\t\t\tresult << \"%BAD%\";\n+\t\t\t}\n+\t\t} else {\n+\t\t\tresult << filename[i];\n+\t\t}\n+\t}\n+\t\n+\tfilename =  result.str();\n+\t\n \tImage *image = mappedBuffers_[buffer].get();\n \n #ifdef HAVE_TIFF\n","prefixes":[]}