# Clear dvr without stream restart

**URL:** https://community.wowza.com/t/clear-dvr-without-stream-restart/54781
**Category:** Wowza Developer Dojo
**Tags:** dvr
**Created:** [March 10, 2020, 12:13pm UTC](https://community.wowza.com/t/clear-dvr-without-stream-restart/54781 "2020-03-10T12:13:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mikhail\_Kartashov](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mikhail\_Kartashov](https://community.wowza.com/u/mikhail_Kartashov)
#### Post date: [March 10, 2020, 12:13pm UTC](https://community.wowza.com/t/clear-dvr-without-stream-restart/54781/1 "2020-03-10T12:13:50Z")

</div>

Hello!

I’d like to have opportunity to save DVR after stream restart but sometimes I need to clean it by hand.

Can I clear DVR for stream/application by some api call?

I’ve found purgeEntries method in [https://www.wowza.com/resources/serverapi/com/wowza/wms/dvr/IDvrStreamManager.html](https://www.wowza.com/resources/serverapi/com/wowza/wms/dvr/IDvrStreamManager.html)

This is it? If yes - how can I get DvrStreamManager from stream or application object?

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [March 10, 2020, 3:50pm UTC](https://community.wowza.com/t/clear-dvr-without-stream-restart/54781/2 "2020-03-10T15:50:24Z")

</div>

The correct call @mikhail Kartashov is:

```auto
deleteArchivedStore. https://www.wowza.com/resources/serverapi/com/wowza/wms/dvr/IDvrStreamManager.html#deleteArchivedStore-java.lang.String-

```

You would need to determine what the versioned stream name is (normally **streamName.n** ) and then pass that into the method. Also, it will upset any players currently playing from the DVR store so the call should be made before any players connect, ideally from onAppStart.

You would need to create an **IDvrStreamManager** for each stream then call deleteArchivedStore on it.

```auto
IDvrStreamManager dvrManager = appInstance.getStreams().getLiveStreamPacketizer(streamName, "dvrstreamingpacketizer", true);

```

```auto
dvrManager.deleteArchivedStore(versionedStreamName);

```

---

<div class="post-metadata">

### Author: ![mikhail\_Kartashov](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mikhail\_Kartashov](https://community.wowza.com/u/mikhail_Kartashov)
#### Post date: [March 13, 2020, 7:44am UTC](https://community.wowza.com/t/clear-dvr-without-stream-restart/54781/3 "2020-03-13T07:44:57Z")

</div>

In some cases (for example, a problem with copyright holders), we must clear the DVR in the stream, but we must not restart it, because at this moment some event may be streamed and recorded.

So I’ve done that:

public void clearDVR(String streamName, long timeShiftSeconds){

IDvrStreamManager manager = this.appInstance.getStreams().getStream(streamName).getDvrRecorder(“dvrrecorder”).getDvrManager();

// Dirty hack there. We use only one version 🙂

IDvrStreamStore store = manager.getStreamStore(stream.getName()+".0");

IDvrManifest paramIDvrManifest = store.getManifest();

DvrChannelManifest manifest = paramIDvrManifest.getManifestChannel(IVHost.CONTENTTYPE\_VIDEO);

if (manifest == null) {

manifest = paramIDvrManifest.getManifestChannel(IVHost.CONTENTTYPE\_AUDIO); // for audio-only streams

if (manifest == null) {

return;

}

}

long currentTime = manifest.getDvrTime();

DvrManifestEntryRangeGroup fragmentsToPurge = new DvrManifestEntryRangeGroup();

DvrManifestEntryRange entryRange = manifest.getLiveRangeEndingBeforeTime(currentTime - timeShiftSeconds\*1000);

if (entryRange != null && !entryRange.isEmpty()){

fragmentsToPurge.addRange(entryRange);

}

// Dirty hack there. We use only one version 🙂

manager.purgeManifestEntries(stream.getName()+".0", fragmentsToPurge);

}
