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 8654146DC9 for ; Fri, 11 Aug 2023 07:37:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 949E068C770; Fri, 11 Aug 2023 10:37:53 +0300 (EEST) Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 059C568C770 for ; Fri, 11 Aug 2023 10:37:46 +0300 (EEST) Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2b9cdbf682eso25776651fa.2 for ; Fri, 11 Aug 2023 00:37:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691739466; x=1692344266; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=e1eUx4x0cXX/cSsQw7ZQH9C6HuLfZ61ktwjcwlqcyeI=; b=biGpwAsNvF2BBhIddm1RjtZKwC8W5CyBpWzVEWgDuOoqHGWUlPE3oxO1vbrYxyJOlV 2Phaf7V8MyHj66dvmPj9ysB5f08XzDtsR7zJ6s0ra/zijoaSRL8F3ySs95FjfzGM6PZE tdswHw+h75K7BfH+ntPWD3FKfaOL2w7IWCN9Z1JtN9saU/2fKN/TSVKD8eZpH0nBB36o ThYJukC9OsjjUh0iIrvvqjVC0e/N5Oqw7qck98Q+jgomCp//o3vXGGTtWlXDxUNDNz0Z cMNg6f7eq814zKYlljrvBOdK5z4TN8a3UZyawOOkpqabMM/wfoygpEqnUhzJwYNagGnY 6lDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691739466; x=1692344266; h=content-transfer-encoding:content-language:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=e1eUx4x0cXX/cSsQw7ZQH9C6HuLfZ61ktwjcwlqcyeI=; b=IjMOldre1S8QcyDyx7AbOa28cbyIkLizNCOW0HnEgwgo6nvSSbm+csfyO4R+yJ9k8u GMp5Ag/JCLFtNUdCn1rW51m0774B4MGd6JsLBA0AFWqziZ0EUdZI263vVm8jHptj1vvK 9wKMo1T0GHkY7OWrR0G7W4cQtaxRwXsYqtMnv5OvdkZjGVbRlWCRCVEy/CuYDmKRoeXD CvJ9qjZsP+/c4LefrjWPauvoebtX9R6leM5TI2+JUiLSzp/EOMvPGb4gDpqQfwLjxbMD vnzEKabQI3vCmEYz/YO+PFxSUYf6Yc/s5cfwlSCPNswMWd7/5/2oyk++GIKi+VKDnGuK eQwg== X-Gm-Message-State: AOJu0YyDhVZZfVGJtu1JJ6t2co1OdDxzXcROuO2zqEMa8t2m5KtesMFO c+Bm1oLq7r+T6y2ZoUYxvxElYtyHcAhHK2dVHkksvw== X-Google-Smtp-Source: AGHT+IHxWYRVbUjnukYFl2Zr6oNTexKVYkqX9pNxOtRUqQ8JBlntD8KazN4S4nfw24/xKFrpwc4rhA== X-Received: by 2002:a05:6512:1295:b0:4fe:7df0:41ab with SMTP id u21-20020a056512129500b004fe7df041abmr801473lfs.17.1691739465805; Fri, 11 Aug 2023 00:37:45 -0700 (PDT) Received: from [10.92.172.211] (wlan-gw.se.axis.com. [195.60.68.7]) by smtp.gmail.com with ESMTPSA id u8-20020ac248a8000000b004fe0760354bsm615084lfg.275.2023.08.11.00.37.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 11 Aug 2023 00:37:45 -0700 (PDT) Message-ID: <8604cc31-fa38-c307-4882-31504f179159@gmail.com> Date: Fri, 11 Aug 2023 09:37:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.1 From: Malek Assaad To: ffmpeg-devel@ffmpeg.org Content-Language: en-US Subject: [FFmpeg-devel] [PATCH] pssh: add a flag for writing pssh boxes 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: Hi all, I would like to add an option to create pssh boxes with ffmpeg. I have included my implementation for review. I consulted the standard: ISO/IEC 23001-7:2022 and I am looking forward for the feedback. Add a flag to create Protection System Specific Header boxes in a movie box in coherence with ISO/IEC 23001-7:2022. Signed-off-by: Malek Assaad --- libavformat/movenc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ libavformat/movenc.h | 1 + 2 files changed, 47 insertions(+) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index f1cc80b1b3..8953f8362b 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -94,6 +94,7 @@ static const AVOption options[] = { { "write_gama", "Write deprecated gama atom", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_WRITE_GAMA}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, { "use_metadata_tags", "Use mdta atom for metadata.", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_USE_MDTA}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, { "skip_trailer", "Skip writing the mfra/tfra/mfro trailer for fragmented files", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_SKIP_TRAILER}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, + { "write_pssh", "Write pssh atom", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_PSSH}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags"}, { "negative_cts_offsets", "Use negative CTS offsets (reducing the need for edit lists)", 0, AV_OPT_TYPE_CONST, {.i64 = FF_MOV_FLAG_NEGATIVE_CTS_OFFSETS}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags), { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, @@ -4506,6 +4507,45 @@ static int mov_write_uuidusmt_tag(AVIOContext *pb, AVFormatContext *s) return 0; } +static int mov_write_pssh_tag(AVIOContext *pb, MOVMuxContext *mov, AVStream *st) +{ + size_t side_data_size; + int i, j; + int64_t pos; + AVEncryptionInitInfo *info; + uint8_t *side_data = av_stream_get_side_data(st, + AV_PKT_DATA_ENCRYPTION_INIT_INFO, + &side_data_size); + info = av_encryption_init_info_get_side_data(side_data, side_data_size); + + for(AVEncryptionInitInfo *copy = info; copy; copy = copy->next) { + if (!copy->data_size && !copy->num_key_ids) + continue; + + pos = avio_tell(pb); + avio_wb32(pb, 0); /* size placeholder */ + ffio_wfourcc(pb, "pssh"); + avio_w8(pb, 1); /* version */ + avio_wb24(pb, 0); + for (i = 0; i < copy->system_id_size; i++) { + avio_w8(pb, copy->system_id[i]); + } + avio_wb32(pb, copy->num_key_ids); + for (i = 0; i < copy->num_key_ids; i++) { + for (j = 0; j < copy->key_id_size; j++) { + avio_w8(pb, copy->key_ids[i][j]); + } + } + avio_wb32(pb, copy->data_size); + for (i = 0; i < copy->data_size; i++) { + avio_w8(pb, copy->data[i]); + } + update_size(pb, pos); + } + + return 0; +} + static void build_chunks(MOVTrack *trk) { int i; @@ -4650,6 +4690,12 @@ static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, else if (mov->mode != MODE_AVIF) mov_write_udta_tag(pb, mov, s); + if (mov->flags & FF_MOV_FLAG_PSSH) { + for (i = 0; i < mov->nb_streams; i++) { + mov_write_pssh_tag(pb, mov, s->streams[i]); + } + } + return update_size(pb, pos); } diff --git a/libavformat/movenc.h b/libavformat/movenc.h index e85d83abdb..76f81bcbfd 100644 --- a/libavformat/movenc.h +++ b/libavformat/movenc.h @@ -276,6 +276,7 @@ typedef struct MOVMuxContext { #define FF_MOV_FLAG_SKIP_SIDX (1 << 21) #define FF_MOV_FLAG_CMAF (1 << 22) #define FF_MOV_FLAG_PREFER_ICC (1 << 23) +#define FF_MOV_FLAG_PSSH (1 << 24) int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt); -- 2.30.2 _______________________________________________ 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".