From: A <ahmadsharif@gmail.com> To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] avformat_seek_file in H265 video seeks beyond the max_ts passed in? Date: Mon, 12 Aug 2024 16:24:53 -0400 Message-ID: <CAEsFZvHQ89RN9ZwH-hV8ZXVnUPuTn=F7kyxMaKb4j2eNPvw4zg@mail.gmail.com> (raw) 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".
next reply other threads:[~2024-08-12 20:25 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-08-12 20:24 A [this message] 2024-08-12 20:57 ` A
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CAEsFZvHQ89RN9ZwH-hV8ZXVnUPuTn=F7kyxMaKb4j2eNPvw4zg@mail.gmail.com' \ --to=ahmadsharif@gmail.com \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git