From patchwork Tue Dec 26 22:44:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dr Alan Barclay X-Patchwork-Id: 6991 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp7362413jad; Tue, 26 Dec 2017 14:44:41 -0800 (PST) X-Google-Smtp-Source: ACJfBoufSSlgxg2QZBgU5l9K+Wr/iVXdiRgN4qGuqikuCstMNT5pvf9Bt5bNYdHBARwtWoKpR4Og X-Received: by 10.223.169.8 with SMTP id u8mr28364097wrc.232.1514328280968; Tue, 26 Dec 2017 14:44:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514328280; cv=none; d=google.com; s=arc-20160816; b=eQMYl58pogGq8r21F0/FkiZcQ4MHFzhNhkbafT4IUdNK6J+Ow6ptdUwPn8wvydwgrb 9ETNHSi5dbsauVM2oBc9x0e4USneZPy1m6W38td5spHfJ25rWiEIa5owBtsEVfNOjYW1 4qR6wqMb6Zo+e6XX41VQuxV02E1b12ITTy+lA6/oDYS6g6hY1r1RpmB5Ma8m3tMOImRu DAayYKPUkC082BMmiUuW3nifuGljMkjFVAfSPFSAmHMCjuq99e4Ur+fB949Ga5dtMYNc vkNQcd6k0eW7O1tqebtYu1bJRyapAvPZBLyY+3z9SmDkNblYOHNCLsd1o3zPEFUmEOGw m1sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:delivered-to :arc-authentication-results; bh=B25mJDW5Al/542BtjEZYZUHWWTVxIpkLiqUWUvFAvvY=; b=PsPNrQ+nphyefAUEU4SFWfYnn6apDa+CyRh76bdmMAfj8JUX+ZqLAz+cnDQT8DrzAw OPvWpIzRPwmbHNLIRqBGi21/RCTo7W+rtHRKYTdmG2DFdLCnoqr9ZpwhMpJW8BA6l+Nj YYV2olm3gniLrAW8oEAUEwqJqgTaL0y0tbOOtUKgNEduhCCrGgNef9JC0hdZx/KhoftN uzRbKtsxCvgzb5GX0IyM/Nedyd0Ob2GZdQ9gc+TWx+Xqg29h8Y1pI6xTZ0pzQ5tKomQf DvJuCjLc9cCpsKN0aH/aLggCbOXn8nkq9SftC7Yd/X9Xw1Tyr7w5hly4jYox+Cdnx03y 6bNQ== 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 d203si12292749wmc.0.2017.12.26.14.44.40; Tue, 26 Dec 2017 14:44:40 -0800 (PST) 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 4E38E688339; Wed, 27 Dec 2017 00:44:26 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mout.kundenserver.de (mout.kundenserver.de [217.72.192.73]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 047F168065E for ; Wed, 27 Dec 2017 00:44:19 +0200 (EET) Received: from [192.168.1.14] ([79.67.18.62]) by mrelayeu.kundenserver.de (mreue101 [212.227.15.183]) with ESMTPSA (Nemesis) id 0McWMC-1eCIYC3DwO-00Hck9 for ; Tue, 26 Dec 2017 23:44:33 +0100 To: ffmpeg-devel@ffmpeg.org References: From: Dr Alan Barclay Message-ID: Date: Tue, 26 Dec 2017 22:44:31 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Provags-ID: V03:K0:fjzMqYF2i7T3dJ4Az1NwAVxHHsDiPQonwPSCRaK5go5pFubXDBX xTvTrnMHqSotI41G+hP3UG4XNd9lZdATCB18foXgK9Aj9EUc7t4XZrey6FTKjecpI1O7Ywj FcFW44Zelx0ZumfbcxBMew3TrVabjeLVspNAsKqqQobpNONoV9oq3OyQRCXUVicC0XXJRJC tooLDMOoS94crFfpKwtqA== X-UI-Out-Filterresults: notjunk:1; V01:K0:8x0roCtPw0E=:0sVk5Wq5YcdDB6SDpiyn8d V0X17Yanw3FfGGKin4H0PgEREsiaTHlYtaaHewR2zTD2TDdfOZLdHQnMFZ9kqIle28DAw05yQ iG7k5vx+N/eDFsQT96r0CnwSL0RN2bBJZjtPCyxnOTDJw200+NEhswIq/SKTd9fJexMBKeoth a+O1qUhCs4VnsmMVu9Ss/3jeeiRtO1IMNLToYjo02ccPuWKM44V8rjlWUo8mGFkVTsm6KKPQh VpqPHmD1uR8XiBe7ovbk5QbU7Yh6CzEC6p4qF1K8RJrP9xmQaAob48iN6bfL42PgBTQP/IAdT UApiIuzuGGoVMNxrdgNqOZjtYkGwsVmS8UwzTqpwkxUNrIb5jqE+SdIUMKh6yM/0FvNlnM3ZA 1nO8oIOEDYXRMvC5Y0TjjUm5mLbrHRPlw6jNfK+6eQ6sPV+aXIx9gtxW3sihDP48sKWg8uzqD 1DwedmdkAg12IX+LnlgoPNr4z3hC1+veEnd3R3Jc663/lrtg9Qa6kPYO4vNOOlp4AsoSqKJJK hSYv8+ci+Pf7Oj/FPUuqWvGMyiZy/aFzMn3+Rb+xrQaXwfipMPz8+4eYthNEB5KvInFy75a2h 0C8rpaThXest5rrX08qUNQ+yvaFII7au4/hQCoi7mBPTA7n2pFECwsVu+SLNSDMvOhW5183Dj uTNpA5WLDaJP+5MoWG0Atl6kcaKkUAVoXmVBByt4DP5S5NI/YR440JvDF14hRcQffNElfOujO nwX8Exyfgg79LbWe+Lytl13C5campoSsQez4VkK97fHtQPNOkt0ly69klRQ= Subject: [FFmpeg-devel] [PATCH] Adding mkdir option for img2enc (2nd attempt) 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi All, Please would someone with an interest in img2enc take a look at my revised patches for a minor feature addition and consider committing it to the main line for me. Example: ffmpeg -i ~/trailer.mp4 -strftime 1 -mkdir 1 %Y/%m/%d/out_%H-%M-%S.jpg Without the new mkdir option, this command will fail if the directory hierarchy for the jpg files does not already exist, which can be difficult to predict for time-stamped directories. This patch adds a mkdir option to img2enc which invites it to make whatever directory hierarchy is necessary for each output file. When used in conjunction with the strftime then the jpg files will be located in a newly created (time-stamped) directory as processing progresses. My typical usage scenario is capturing a long-running live video feed (perhaps time-lapsed) and storing the resulting images in a time-stamped directory hierarchy fashion, rather than as a numbered sequence of files in a single directory. If you look at the code you will see that only a half dozen lines of code were required in img2enc. The function for creating directories already existed in hlsenc.c but I've moved into utils.c as I presumed that was a more generic location for it. All comments appreciated. Thanks ad Regards, Alan. On 17/12/17 22:46, Carl Eugen Hoyos wrote: > 2017-12-17 23:41 GMT+01:00 Dr Alan Barclay : > >> Please would someone with an interest in img2enc take a look >> at my minor feature addition and consider committing it to the >> main line for me. > To be acceptable, the patch has to be split in two and please > move the definition into internal.h > > Carl Eugen > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel --- libavformat/img2enc.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavformat/img2enc.c b/libavformat/img2enc.c index b680676bff..a8ee064396 100644 --- a/libavformat/img2enc.c +++ b/libavformat/img2enc.c @@ -42,6 +42,7 @@ typedef struct VideoMuxData { char target[4][1024]; int update; int use_strftime; + int use_mkdir; int frame_pts; const char *muxer; int use_rename; @@ -114,6 +115,12 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt) img->img_number, img->path); return AVERROR(EINVAL); } + if (img->use_mkdir) { + char *temp_filename = av_strdup(filename); + const char *temp_path = av_dirname(temp_filename); + ff_mkdir_p(temp_path); + av_free(temp_filename); + } for (i = 0; i < 4; i++) { snprintf(img->tmp[i], sizeof(img->tmp[i]), "%s.tmp", filename); av_strlcpy(img->target[i], filename, sizeof(img->target[i])); @@ -212,6 +219,7 @@ static const AVOption muxoptions[] = { { "update", "continuously overwrite one file", OFFSET(update), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { "start_number", "set first number in the sequence", OFFSET(img_number), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, ENC }, { "strftime", "use strftime for filename", OFFSET(use_strftime), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, + { "mkdir", "make sub-dirs as required", OFFSET(use_mkdir), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { "frame_pts", "use current frame pts for filename", OFFSET(frame_pts), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { "atomic_writing", "write files atomically (using temporary files and renames)", OFFSET(use_rename), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, ENC }, { NULL }, -- 2.11.0