# Where is commercial offset data stored

**URL:** <https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334>\
**Category:** Live TV & DVR\
**Tags:** server-windows\
**Created:** [April 14, 2021, 1:52am UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334 "2021-04-14T01:52:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![dannytrigo2](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@dannytrigo2](https://forums.plex.tv/u/dannytrigo2)\
**Post date:** [April 14, 2021, 1:52am UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/1 "2021-04-14T01:52:19Z")

</div>

I have some episodes that were recorded and marked as the wrong episode number in the guide. I renamed the file, but now the commercial offsets that were detected seem to apply to the wrong episode.

Where does plex store the offsets extracted from comskip so that I can adjust it?

Is it possible to run detection again manually for a specific file? (this would also be useful for tuning comskip.ini settings)

I also tried to run it manually from the command line but I get errors about the video codec not being supported so I guess it’s not finding the correct libraries

---

<div class="post-metadata">

**Author:** ![pl\_5309](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pl\_5309](https://forums.plex.tv/u/pl_5309)\
**Post date:** [April 14, 2021, 2:06pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/2 "2021-04-14T14:06:32Z")

</div>

Data is stored in the database, do a getinfo on the file.  
You should have Plex “danced” the file before renaming so the entry would have been removed from the database.

If the DVR and Library are set to detect commercials on all items, you can analyze the season or dance the file to get Plex to re-detect commercials. Alternatively, you can create a custom comskip.ini file and all your DVR media will be rescanned. [Removing Commercials | Plex Support](https://support.plex.tv/articles/115003944134-removing-commercials/)

---

<div class="post-metadata">

**Author:** ![dannytrigo2](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@dannytrigo2](https://forums.plex.tv/u/dannytrigo2)\
**Post date:** [April 14, 2021, 4:49pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/3 "2021-04-14T16:49:33Z")

</div>

Thanks for the reply. Please can you expand further on what you mean by “danced” the file? By getinfo, do you mean the XML info of the file via the UI/API?

I searched the sqlite database but could not locate any data for the ads/commercials. Do you know where in the database they’re stored - which table?

I recently added a custom comskip, but its not been used yet. I ideally don’t want to run the comskip on all the media in the library, since most of the historical media has the commercials cut out already. Its only recent recordings I want to run (or rerun) it for, because I did not get good episode numbering when recording, and I’ve also adjusted my comskip.ini.

If I understood you correctly, I could set the library to run for all - then run ‘analyse’ on the episodes I want, then unset at the library level?

---

<div class="post-metadata">

**Author:** ![pshanew](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/pshanew/32/160555_2.png) [@pshanew](https://forums.plex.tv/u/pshanew)\
**Post date:** [April 14, 2021, 5:11pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/4 "2021-04-14T17:11:25Z")

</div>

> [@dannytrigo2](#):
>
> I searched the sqlite database but could not locate any data for the ads/commercials. Do you know where in the database they’re stored - which table?

Commercial (and intro) markers live in the `media_parts` table, in the `extra_data` column; the data in this column is URL-encoded. However, this table doesn’t hold the actual name of the media to which the data belongs; to get that, you’ll have to use the `media_item_id` to join on the `media_items` table. And from there, you’ll need to use that table’s `metadata_item_id` column to join on the `metadata_items` table.

Editing the data in `media_parts` to adjust the markers probably isn’t practical. I agree with @pl_5309, the best way to correct your commercial markers would be to configure the library for ad detection for all items and then perform the [Plex Dance](https://forums.plex.tv/t/the-plex-dance/197064) on the affected items. After doing so, forcing a media analysis should cause ad detection to run; I’d wait until intro detection for the items has completed, however.

---

<div class="post-metadata">

**Author:** ![pl\_5309](https://avatars.discourse-cdn.com/v4/letter/p/2bfe46/32.png) [@pl\_5309](https://forums.plex.tv/u/pl_5309)\
**Post date:** [April 14, 2021, 5:22pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/5 "2021-04-14T17:22:33Z")

</div>

I would strongly recommend keeping your existing TV/Movies libraries in separate directories than the ones for use with the DVR due to past, present and future oddities that have occurred.

If no commercials are detected, it will rescan the file every night until you remove it as an example.

---

<div class="post-metadata">

**Author:** ![pshanew](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/pshanew/32/160555_2.png) [@pshanew](https://forums.plex.tv/u/pshanew)\
**Post date:** [April 14, 2021, 5:25pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/6 "2021-04-14T17:25:14Z")

</div>

> [@pl\_5309](#):
>
> I would strongly recommend keeping your existing TV/Movies libraries in separate directories than the ones for use with the DVR due to past, present and future oddities that have occurred.

Great point; I’d assumed we were talking about a DVR-only library since that’s how I have mine organized. It’s probably not always a safe assumption to make.

---

<div class="post-metadata">

**Author:** ![dannytrigo2](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@dannytrigo2](https://forums.plex.tv/u/dannytrigo2)\
**Post date:** [April 14, 2021, 6:25pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/7 "2021-04-14T18:25:29Z")

</div>

I normally would use a separate library - but this is already a specific library for one specific show - so it would mean two libraries for a single TV show.

I tried setting the library to run commercial detection for recorded content, then running Analyse on the individual episodes, but it only does intro detection, probably because it doesn’t know they’re recorded since I changed the filenames.

I will try setting it to all content, analysing, then disabling that. If anyone has any hints on the other questions about where this commercial metadata is stored it would also be highly  
appreciated.

---

<div class="post-metadata">

**Author:** ![pshanew](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/pshanew/32/160555_2.png) [@pshanew](https://forums.plex.tv/u/pshanew)\
**Post date:** [April 14, 2021, 6:35pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/8 "2021-04-14T18:35:05Z")

</div>

> [@dannytrigo2](#):
>
> If anyone has any hints on the other questions about where this commercial metadata is stored it would also be highly  
> appreciated.

That’s what the [first paragraph](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/4) of my post above addressed…

---

<div class="post-metadata">

**Author:** ![dannytrigo2](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@dannytrigo2](https://forums.plex.tv/u/dannytrigo2)\
**Post date:** [April 14, 2021, 7:29pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/9 "2021-04-14T19:29:53Z")

</div>

Perfect! Sorry, I had missed your reply in the thread.  
Thanks @pl_5309 and @pshanew

---

<div class="post-metadata">

**Author:** ![dannytrigo2](https://avatars.discourse-cdn.com/v4/letter/d/4bbf92/32.png) [@dannytrigo2](https://forums.plex.tv/u/dannytrigo2)\
**Post date:** [April 18, 2021, 5:25pm UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/10 "2021-04-18T17:25:29Z")

</div>

In case anyone else benefits, I discovered to run the Plex commercial skipper (comskip) manually you need to set the FFMEPG\_EXTERNAL\_LIBS environment variable in this format (on Windows):

`set FFMPEG_EXTERNAL_LIBS=\\\\?\\C\:\\Users\\<username>\\AppData\\Local\\Plex\ Media\ Server\\Codecs\\73e06c8-3759-windows-x86\\`

The exact path will differ, but I was previously missing all the extra backslash escapes and ? before the drive, etc.

---

<div class="post-metadata">

**Author:** ![plex321a](https://avatars.discourse-cdn.com/v4/letter/p/f0a364/32.png) [@plex321a](https://forums.plex.tv/u/plex321a)\
**Post date:** [July 7, 2021, 12:09am UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/11 "2021-07-07T00:09:46Z")

</div>

@dannytrigo2 your question was spot on for me and my needs!

@pshanew your explanation of the `media_parts` and `media_items` tables was perfect for me. Once turning on ad detection, I was able to use the following `sqlite3` query to check each day how ad detection was progressing during the maintenance hours over night as PMS worked to retroactively ad detect shows in my library.

```auto
sqlite3 com.plexapp.plugins.library.db '
  SELECT hints 
  FROM media_items, media_parts 
  WHERE media_parts.media_item_id = media_items.id
    AND media_parts.extra_data LIKE "%commercials=%";' \
 ".exit"

```

Thank you, @pl_5309 and @pshanew

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [October 5, 2021, 12:10am UTC](https://forums.plex.tv/t/where-is-commercial-offset-data-stored/709334/12 "2021-10-05T00:10:19Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
