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 ESMTPS id CFF614CDAA for ; Wed, 12 Feb 2025 20:40:05 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 90B1E68C02C; Wed, 12 Feb 2025 22:40:03 +0200 (EET) Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1FA1368B548 for ; Wed, 12 Feb 2025 22:39:58 +0200 (EET) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-21c2f1b610dso2334455ad.0 for ; Wed, 12 Feb 2025 12:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739392796; x=1739997596; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jEn+kq0Qygfrtr/FtqkiODhokIcrXwScLgLZkvNh8Oc=; b=IbGy9AiTac92UZd7ZMLuog+ikrbsBr70NIryFcS1cYkh8oAbo3R63KcZi/Zr4pt75l YWmE/gF/rFZ4OMoSt+T5v8JdlAkgl1LBE+1F3a182awCnpjTTKfZ7TkJ56UNzHx9DTdZ Ww8MyHel90pbyKyAvrJP1/QExPxOFeo7dkkrt/yFYf2Vut+hbCUtNvX3/DneREVJH7yO gAn+tAm4ZO55047ac9cDzTQqU5CoGgCiY1qN0NrMLaAav9mmVkLRtR6957jSawTw/UpM 9WJm6N6EBYhCraPRgh8GHMowAziMYfefAOvKvWMVP/2FZK9YnlJuQHOGMimwTqFxBxQJ 6qGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739392796; x=1739997596; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jEn+kq0Qygfrtr/FtqkiODhokIcrXwScLgLZkvNh8Oc=; b=Rgd/YgdxDmh5zlJFdB3eoYqYovx42R/RC1P1QTk4ZV4pF41qoVvN0oa2UaQ3CDZ0QU d3vpp1HcryZ2DHYN3YI1OIF0WtTx7YBdp5Tr+ynCYED3AHl+1Odavcq3d3b/Zbs7gR8d X1VSAXFFw+5hIb26bgcmo8C9Kmbdw4spoLmHwuO83gz/cn3CoI69DtpLuITKvXBxkgvf lOcBZQTbwRENg6CwzyW4If/fsFG0nHwD8itzkkiqv/nfbeUTtdvrwf/5MaXrzawNCrNg JL6BNceccpLfn+2L5NMSivZMCdth+lnS2GtCTtsWBLRno9hw/37KvnrZlC1yf3w/SfWZ bUbA== X-Gm-Message-State: AOJu0YwWxBS2kNZC7WvWC3nwPNdGfcflWusydOwenDUVM9yRmh/8TdTg 9Ejl/cx5IvrNPYQWbd23cG7czp11cKoXlmj49M/cQbu5nEaQ95mCLO0/RQ== X-Gm-Gg: ASbGncsl4Mqr+JzJBTGD6xRwCxQeOY27a50Njh9vEftqDd6AZ0Z1Zaw/L3CAe9mIve5 vBvPqyf49fx1jRcUcT+VvwKgpdgMuguu42X4zYi0ZcUMuTMzIoUsl/GZLNfkcUr2De/kQsAW3PR +zct3m52Z01rAEgHzTJQ1ksZkROr+JkK/A6L0yjiQpwFrUYEiRcM3B5BQzbX4HRr0Gg5UVapbB5 hy3M9fJc7dIX+pNhicF1Oe1GCwdkzja0WlsJhIdH/7Wli0FdJjOXtRW1jzqSJqEP+t4z9KkXyXv XZS7VXJ8kGmqVrVi69epM+3fCQ== X-Google-Smtp-Source: AGHT+IFLlxQIJAvojbvAwPwQvat+SsIOqNXLczVD+/JeUNTKPS3ptd/X07YoF1OWrxsBHua/oxg0yg== X-Received: by 2002:a05:6a21:a8e:b0:1ee:6a20:1778 with SMTP id adf61e73a8af0-1ee6b36035fmr1526012637.20.1739392795987; Wed, 12 Feb 2025 12:39:55 -0800 (PST) Received: from Mac.localdomain ([50.35.88.47]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7308ac1a373sm6216425b3a.41.2025.02.12.12.39.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 12 Feb 2025 12:39:55 -0800 (PST) From: Srikanth Kiran Kotagiri X-Google-Original-From: Srikanth Kiran Kotagiri To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Feb 2025 12:39:45 -0800 Message-Id: <20250212203945.61469-1-srikantk@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] libavformat/mov: fix seek issues for fragmented mp4 files 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 Cc: Srikanth Kiran Kotagiri 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: From: Srikanth Kiran Kotagiri For Fragmented MP4 files where the audio and video streams are written to seperate fragments, the -ss option will cause the file pointer to be set to the first available fragment. This is due to an interaction in search_frag_timestamp() function and get_frag_time() functions. With this change, we first verify that the fragment being checked does not actually contain the requested stream before just sending AV_NOPTS_VALUE. --- libavformat/mov.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 85aef33b19..8e89f6f934 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -87,6 +87,7 @@ typedef struct MOVParseTableEntry { static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom); static int mov_read_mfra(MOVContext *c, AVIOContext *f); static void mov_free_stream_context(AVFormatContext *s, AVStream *st); +static int mov_switch_root(AVFormatContext *s, int64_t target, int index); static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb, unsigned len, const char *key) @@ -1672,6 +1673,7 @@ static int64_t get_frag_time(AVFormatContext *s, AVStream *dst_st, MOVStreamContext *sc = dst_st->priv_data; int64_t timestamp; int i, j; + int stream_present; // If the stream is referenced by any sidx, limit the search // to fragments that referenced this stream in the sidx @@ -1686,6 +1688,27 @@ static int64_t get_frag_time(AVFormatContext *s, AVStream *dst_st, return frag_stream_info->sidx_pts; } + + // Check if the requested stream is present in the fragment + stream_present = 0; + for (i = 0; i < frag_index->item[index].nb_stream_info; i++) { + if (dst_st->id != frag_index->item[index].stream_info[i].id) + continue; + if ( get_stream_info_time(&frag_index->item[index].stream_info[i]) != AV_NOPTS_VALUE) { + stream_present = 1; + break; + } + if ( mov_switch_root(s,-1,index) < 0) + return AV_NOPTS_VALUE; + if ( get_stream_info_time(&frag_index->item[index].stream_info[i]) != AV_NOPTS_VALUE) { + stream_present = 1; + break; + } + } + if (!stream_present) + return AV_NOPTS_VALUE; + + for (i = 0; i < frag_index->item[index].nb_stream_info; i++) { AVStream *frag_stream = NULL; frag_stream_info = &frag_index->item[index].stream_info[i]; -- 2.39.5 (Apple Git-154) _______________________________________________ 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".