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 D8CB44CA24 for ; Mon, 12 Aug 2024 20:25:16 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6789968DA8E; Mon, 12 Aug 2024 23:25:13 +0300 (EEST) Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 72A2B68D94A for ; Mon, 12 Aug 2024 23:25:06 +0300 (EEST) Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3db13410adfso3225434b6e.2 for ; Mon, 12 Aug 2024 13:25:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723494304; x=1724099104; darn=ffmpeg.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=M34hUMOwmUU1oTei80sy1xiy5E3hMPKlotwM7EqJS6E=; b=KTX3UhA6UqU4sEIZ5FlfQU4WnzmPm1wLLjtuIbCH2IdReHUYq8zGZbXphohoCtpYcg LSAm8eZ84qf5LreeJLbhVWZ+QuT/0zSblY55Oawz/eQqKXRbJVyjaavCKZxNs36xAHxE h5zBQOHeeR3nfEhogtJSC03oW+PnE66B0G0/CFGi8xAqcNHSYXJKRsx7fXYimo+pCPot 5wJUrybQ53an7fjUSXexKjv4jR5VuKzKsmJykREekURCOksLKwTbda8WZLH35VMd+wcA IU1WSsbfw+wYdgBlpRG8aCKrLk192qaDqsywmq8lbtfIVxIHnpPTApFBUoOiJMWjVyez THqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723494304; x=1724099104; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=M34hUMOwmUU1oTei80sy1xiy5E3hMPKlotwM7EqJS6E=; b=flboX41LM53pJC1xMv4jfLCuScgvAOjDjbSUTymV1VJu0eP7qGCn0ZFJtL2hP5Uk1X +y1TYyQuB9fBg+p7fkrhjhtUse81xENi7TjT3ok4080eYxVWja+y/ZwiUBfhPy4aBEnk Kkw3gD8wHLph/E0UABOVctAmc7GUhSJB0KTfeRhcy/tbMVgae+nj+4+StEUwQaUMsP3X xHoGKk3oT5AWAyCoD0oxsXKlIlH+ukYBHCDAPB+ThJxkoo7wASa+Q9jpukCIF9BPaRto mjshX+JslkYfWapceHL+M2Gga7BA0qZ1woOK7MU19z6/xGDScgyH3DX6uWNL3UXcG0Ju PCuA== X-Gm-Message-State: AOJu0Yx4NxEIO983YsvarvELpxNxEGuqXlDMT+oP9Rx532NPAyANtu3R Wl+/8kzLlSxgplI0ousD9WNKrIsOt7nKrVKhd54SvQuCG01UhfI5pzifXWw5wNh8d06J2O0AsKG qtu845VhmpvLsX7TDhQs4ZIPiyk9cPI5Z X-Google-Smtp-Source: AGHT+IGpRDaUD/Q4Q8O34Vt07wO7D6ju9+Juu/I2InOfqbf1QhULt5Yx1KCurTjB+yzzzKOM0oFKlpjAKI27B6g1r/o= X-Received: by 2002:a05:6808:2203:b0:3d8:499f:1de2 with SMTP id 5614622812f47-3dd1eecfa73mr1496949b6e.35.1723494304561; Mon, 12 Aug 2024 13:25:04 -0700 (PDT) MIME-Version: 1.0 From: A Date: Mon, 12 Aug 2024 16:24:53 -0400 Message-ID: To: ffmpeg-devel@ffmpeg.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 Subject: [FFmpeg-devel] avformat_seek_file in H265 video seeks beyond the max_ts passed in? 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-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: Hi, My understanding is that avformat_seek_file() with these parameters: avformat_seek_file(format_context, 0, INT64_MIN, timestamp, timestamp) should seek in the video to an I-Frame that is strictly <= timestamp (because ts=timestamp and max_ts=timestamp). However, the observed behavior that I see is that for certain H265 videos, FFMPEG seeks beyond the timestamp passed in. To repro this behavior I ran these commands: # Create a clean conda environment for testing purposes conda create --name test conda activate test conda install -c conda-forge x265 # Install some build pre-requisites conda install pkg-config # Build ffmpeg from source with x265 enabled git clone https://github.com/FFmpeg/FFmpeg.git ./configure --enable-nonfree --enable-gpl --prefix=$(readlink -f ../bin) --enable-libx265 --enable-rpath --extra-ldflags=-Wl,-rpath=$CONDA_PREFIX/lib --enable-filter=drawtext --enable-libfontconfig --enable-libfreetype --enable-libharfbuzz make -j install # Now generate a video with just frame numbers in the text per frame: ffmpeg -f lavfi -i color=size=128x128:duration=1:rate=10:color=blue -vf "drawtext=fontsize=30:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2:text='Frame %{frame_num}'" -vcodec libx265 -pix_fmt yuv420p -g 2 -crf 10 test.mp4 -y Note that this video has 10 frames. ffprobe shows the following: ffprobe -v error -select_streams v:0 -show_entries frame=pts,pts_time,duration,pkt_pts_time,pkt_duration,key_frame -of csv test.mp4 frame,1,0,0.000000,1024,1024, frame,0,1024,0.100000,1024,1024 frame,1,2048,0.200000,1024,1024 frame,0,3072,0.300000,1024,1024 frame,1,4096,0.400000,1024,1024 frame,0,5120,0.500000,1024,1024 frame,1,6144,0.600000,1024,1024 frame,0,7168,0.700000,1024,1024 frame,1,8192,0.800000,1024,1024 frame,0,9216,0.900000,1024,1024 Now, when I open this video using FFMPEG as a library, I get an AVFormatContext. I want to decode the frame with pts=0.5. So I call avformat_seek_file with min_ts=-INT64_MAX, ts=0.5 and max_ts=0.5. I expect that FFMPEG will seek to the frame with pts=0.4 so I can then decode forward and eventually get frame with pts=0.5 with avcodec_receive_frame(), but it seems like the first frame that I get from avcodec_receive_frame() is the one with pts=0.6. More context: I am writing a library that wraps FFMPEG and returns frames at arbitrary timestamps. The full source code of the library is here: https://github.com/pytorch/torchcodec. The pull-request that reproduces this exact scenario is here: https://github.com/pytorch/torchcodec/pull/178. It would be nice if FFMPEG always seeked to a frame with pts <= the max_pts passed into avformat_seek_file. This normally does work with other codecs. Am I calling the library wrong? Should I be calling avformat_seek_file() with other flags? The documentation of avformat_seek_file is here: https://ffmpeg.org/doxygen/7.0/group__lavf__decoding.html#ga3b40fc8d2fda6992ae6ea2567d71ba30 Here is the seek call in my code: https://github.com/pytorch/torchcodec/blob/dbfef1223522639d2b036a185b444eecf7748466/src/torchcodec/decoders/_core/VideoDecoder.cpp#L735 I would be happy to file a ticket as well, if that helps. The full repro instructions are in this email for reference. _______________________________________________ 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".