<html><head></head><body><div dir="auto">Hello there,<br><br>we are in the same boat!<br>For a project, I'm also injecting custom per-Frame data using SEI Messages into an H.264 Stream. JSON Data of a bunch of sensors in my case. Works great.<br><br>Also turns out, Apple does the same on iPhones to inject per frame brightness, as read by their environment sensors for use in HDR video: <a href="https://patchwork.ffmpeg.org/project/ffmpeg/patch/1648471271-22016-2-git-send-email-lance.lmwang@gmail.com/#71019">https://patchwork.ffmpeg.org/project/ffmpeg/patch/1648471271-22016-2-git-send-email-lance.lmwang@gmail.com/#71019</a><br><br>For reference, here is my implementation I'm C# in the context of a memory leak I was Chasing, as archived by this mailing list:<br><a href="https://lists.ffmpeg.org/pipermail/libav-user/2023-March/013296.html">https://lists.ffmpeg.org/pipermail/libav-user/2023-March/013296.html</a><br><a href="https://lists.ffmpeg.org/pipermail/libav-user/2023-March/013340.html">https://lists.ffmpeg.org/pipermail/libav-user/2023-March/013340.html</a><br><br><br>> I am however struggling to get this to work as I am always reading back the custom message I used for the first frame.<br><br>You can't, at least using FFmpeg Tools. I am not sure if there is an libavXXX function which would allow you to, but FFMpeg tools themselves cannot. Looking at the FFmpeg patches for Apple's ambient viewing brightness, and from Discussions in the FFmpeg IRC, I understand that to extract that data you need to register a UUID for your usecase in libavcodec to be able to pull information, which means modifying libavcodec. Don't know how accurate my understanding is though.<br><br>You can follow <<a href="https://stackoverflow.com/questions/67283568">https://stackoverflow.com/questions/67283568</a> to get FFMpeg to announce the presence of an unrecognized custom SEI Message, but there is no function to actually display it.<br><br>In my project I resorted to reading the H264 Stream binary as a whole, scanning for the UUID / Magic Number of the SEI Message and extracting the JSON Data that way. Performance wise this was actually really good, as I could export nice Charts of my Data without interfacing with FFmpeg, but that is really more of a hackye workaround.<br><br>I think injecting custom data through SEI messages is really cool, as you can Livestream sensor data in tandem with video, without sync issues. Hope this workflow can become more elegant and less hacky.<br><br><br>Best regards <br><br>Vlad</div><br><br><div class="gmail_quote"><div dir="auto">On May 21, 2024 6:00:05 PM GMT+09:00, Tom Vercauteren <tom.vercauteren@gmail.com> wrote:</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="ltr"><div>Hello,</div><div><br></div><div>I am interested in storing custom metadata on a per frame level in a mov or mp4 file. It looks like using <span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass gmail-js-skip-tagsearch">user data unregistered (UDU) supplemental enhancement information (SEI) may be a suitable approach for this. I am however struggling to get this to work as I am always reading back the custom message I used for the first frame.</span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass gmail-js-skip-tagsearch"><br></span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass gmail-js-skip-tagsearch">Below is a basic change I made to the mux.c and demux_decode.c examples from ffmpeg that shows my attempt:</span></div><div><a href="https://gist.github.com/tvercaut/94c68e46d0d0321a2c83b88024d9cd69/revisions">https://gist.github.com/tvercaut/94c68e46d0d0321a2c83b88024d9cd69/revisions</a></div><div><br></div><div>Essentially, I have tried to use</div><div>`<span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass"><span class="gmail-pl-en">av_frame_new_side_data_from_buf</span>(f<span class="gmail-pl-c1">rame</span>, <span class="gmail-pl-c1">AV_FRAME_DATA_SEI_UNREGISTERED</span>, <span class="gmail-pl-s1">my_sei_buffer</span>);`</span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass">at muxing time and</span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass">`</span><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass"><span class="gmail-pl-en">av_frame_get_side_data</span>(<span class="gmail-pl-s1">frame</span>, <span class="gmail-pl-c1">AV_FRAME_DATA_SEI_UNREGISTERED</span>);`</span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass">at demuxing/decoding time.</span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass"><br></span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass">I also realised I had to set the `</span><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass"><span class="gmail-pl-s">udu_sei` flag when muxing:<br></span></span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass">`</span><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass"><span class="gmail-pl-en">av_dict_set_int</span>(<span class="gmail-pl-c1">&</span><span class="gmail-pl-s1">opt</span>, <span class="gmail-pl-s">"udu_sei"</span>, <span class="gmail-pl-c1">1</span>, <span class="gmail-pl-c1">0</span>);`</span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass"><br></span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass">I have looked for additional material / documentation on how to do this but couldn't find a lot. Am I missing a key step here?</span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass"><br></span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass">Also, is there a way to display the UDU SEI messages using ffmpeg or ffprobe command line tools? I tried using</span></div><div><span class="gmail-blob-code-inner gmail-blob-code-marker gmail-js-code-nav-pass">`</span>ffmpeg -i test.mov -vf showinfo -f null -`</div><div>but this doesn't display the content to the UDU SEI messages I provided.<br></div><div><br></div><div>P.S.: This is a bit of a follow-up from an old post of mine but trying a different approach for per-frame metadata: <a href="https://lists.ffmpeg.org/pipermail/libav-user/2022-April/013051.html">https://lists.ffmpeg.org/pipermail/libav-user/2022-April/013051.html</a></div><div><br></div><div>Best wishes,</div><div>Tom<br></div></div>
</blockquote></div></body></html>