EDL (commercial skipping) and SceneMarker support

An edit decision list (EDL) contains information about edits that should be made to the video during playback. Edit decision list information is contained in a separate file to the video that is read by XBMC Media Center just before the video is played. Inspiration for this functionality came from MPlayer EDL support.

The internal video player used by XBMC Media Center (dvdplayer) supports the following types of edits:
 * Cuts - the content is completely removed from playback as if it were never in the original video. For example, the total playback time is adjusted and the content is always automatically skipped during playback, seeking, fast forward or rewind.
 * Mute - the audio is muted, video continues playing.
 * Scene Markers - these can be used to seek to points of interest within a video similar to how chapter seeking works for DVDs.
 * Commercial Breaks - each commercial break is automatically skipped once during playback. Since commercial detection is rarely 100% accurate, commercial breaks that have already been skipped can be re-entered by seeking backwards or rewinding. If an incorrectly flagged commercial break is automatically skipped, pressing "Down" (big skip backwards) within 10 seconds will jump back to the start of the commercial break. Pressing "Up" (big skip forward) within a flagged commercial break will go to the end of the commercial break.

Supported File Formats
XBMC Media Center is able to read edit decision lists from multiple file formats. The EDL file for a video must be in the same folder as the video file and is looked for based on the file extensions for the supported formats.

For example if the video file is called The Matrix.avi XBMC will look for the following files, in order, until a valid file is found. Note the the file name may be case-sensitive based on the operating system being used.
 * 1) The Matrix.Vprj (VideoReDo)
 * 2) The Matrix.edl (MPlayer EDL)
 * 3) The Matrix.txt (Comskip)
 * 4) The Matrix.avi.chapters.xml (SnapStream BeyondTV)

If the video is being played through the MythTV integration, any commercial breaks flagged by MythTV will be used during playback.

VideoReDo
VideoReDo files are supported. The name of the file must be the same as the video but with a file extension of .Vprj.

Only lines starting with  and  are read from the file. Each  is treated as a commercial break. The file format is: [ignored] [ignored]  [ignored] [ignored]  [scene marker time] (in ms * 10,000) [start time]:[end time] (both in ms * 10,000)

For example, 2 C:\Path\To\Video.mpg  224</VideoStreamPID> 192</AudioStreamPID> </InputPIDList> <SceneMarker 1415932542>4235230000 <SceneMarker 1415932543>4284610000 <SceneMarker 1415932544>4585580000 <SceneMarker 1415932545>5035360000 <Cut>4235230000:5936600000 <Cut>9535530000:11527860000 <Cut>14385710000:16090090000

MPlayer EDL
Classic MPlayer EDL files are supported. XBMC also supports an extended version of this file format that allows extra functionality as outlined below. The name of the file must be the same as the video file but with a file extension of .edl.

The file contains the start and end times of the edits along with the type of action associated with each edit. The file format is: [start time] [end time] [action]

Start and end times can be defined as seconds, HH:MM:SS.sss, or frames. To specify frames precede the frame number with the # symbol. The original MPlayer EDL files only support seconds for start and end times.

The actions supported by this file format have also been extended by XBMC to include Scene Marker and Commercial Break actions since the original format only supports Cut and Mute. Supported actions are:
 * 0 - Cut
 * 1 - Mute
 * 2 - Scene Marker (if start and end times are specified, the end time is used)
 * 3 - Commercial Break

For example, the following .edl file content will skip from second 5.3 to second 7.1, mute at 15 seconds, unmute at 16.7 seconds, and commercial skip from 420 seconds to 822 seconds. There will be two scene markers. The first at 255.3 seconds and the next at 720.1 seconds. 5.3  7.1    0 15    16.7   1 420   822    3 1     255.3  2 720.1        2

The following .edl file content will skip from frame 127 to frame 170, mute at frame 360, unmute at frame 400, and commercial skip from frame 10080 to frame 19728. There will be two scene markers. The first at frame 6127 and the next at frame 17282.
 * 1) 127  #170    0
 * 2) 360  #400    1
 * 3) 10080 #19728 3
 * 4) 1    #6127   2
 * 5) 17282        2

The following .edl file content will skip from second 5.3 to second 7.1, mute at 15 seconds, unmute at 16.7 seconds, and commercial skip from 7 minutes to 13 minutes and 42 seconds. There will be two scene markers. The first at 4 minutes and 15.3 seconds and the next at 12 minutes and 0.1 seconds. 5.3    7.1     0 15      16.7    1 7:00    13:42   3 1       4:15.3  2 12:00.1         2

Seconds and HH:MM:SS.sss can be accurately specified to three decimal places. Currently EDL cuts and mutes are frame accurate when specifying frames. Frames are specified inclusive (specify first frame to cut and last frame to cut).

Comskip
Comskip files are supported. The name of the file must be the same as the video but with a file extension of .txt.

The file contains the start and end frame numbers for the commercial breaks that were detected. The Comskip file may or may not contain the frame rate. If the frame rate is not found, the detected frame rate of the video is used to convert from the frame numbers to time offsets.

The version 1 file format is: FILE PROCESSING COMPLETE

[start frame] [end frame]

For example, FILE PROCESSING COMPLETE

12693	17792 28578	34549 43114	48222

The version 2 file format is: FILE PROCESSING COMPLETE [number of frames] FRAMES AT [frame rate]

[start frame] [end frame]

For example, FILE PROCESSING COMPLETE 678900 FRAMES AT 25

12693	17792 28578	34549 43114	48222

SnapStream BeyondTV
BeyondTV files are supported. The name of the file must be the same as the video but with .chapters.xml appended to the filename.

Each <Region> within the XML file is treated as a commercial break. The file format is: <Region> <start comment="[start time in hh:mm:ss.sssssss format - ignored]">[start time in ms * 10,000] <end comment="[end time in hh:mm:ss.sssssss format - ignored]">[end time in ms * 10,000] </Region>

For example, <Region> <start comment="0:07:03.0000523">4235230000 <end comment="0:09:53.0000660">5936600000 </Region> <Region> <start comment="0:15:53.0000553">9535530000 <end comment="0:19:12.0000786">11527860000 </Region> <Region> <start comment="0:23:58.0000571">14385710000 <end comment="0:26:49.0000009">16090090000 </Region>

MythTV
Files that are played through the integrated MythTV support have the commercial breaks loaded from mythbackend.

Scene Markers are additionally put in at the beginning and end of the flagged commercial breaks.

= Merging or Removing Short Commercial Breaks =

The section of advancedsettings.xml can be used to:
 * Merge commercial breaks within a set of commercials that haven't been detected accurately. Very useful if you find that automatically skipped commercial breaks still end up within a set of commercial breaks.
 * Remove commercial breaks that are incorrectly identified outside of a likely set of commercial breaks. Very useful if you find that commercial skipping is happening unexpectedly while watching the TV show or Movie.

= Altering Automatic Skip Timings =

The section of advancedsettings.xml also can be used to:
 * Set how long to wait before automatically skipping when the start of a commercial break is reached. Useful if the automatic skip at the start of a set of commercial breaks is happening slightly too early for your liking, particularly if you aren't ever quite sure if that was a commercial that was about to start.
 * Set how long to rewind after automatically skipping to the end of the commercial break. Useful if it's kind of hard to tell if that was in fact the start of the TV show after a block of commercials.

= Showing EDL Information During Playback =

Information about the EDL status for the video can be obtained by showing the codec information during playback. Typically this is shown by pressing o on a keyboard or pressing the Title button on the XBox remote. See Keyboard.xml for more information.

When the codec information for the playing video is shown on screen, e.g. the video and stream codecs being used, framerate, number of dropped frames etc. information about the EDL status will also be displayed. Edit decision list information is prefixed with edl: and followed by a dash or letters followed by numbers. The letter describes the type of edit and the following number the count of that type. For example, edl: c4s8 means there are 4 commercial breaks and 8 scene markers.


 * c = cut
 * m = mute
 * b = commercial break
 * s = scene marker
 * - (dash) = no edit decision list

= Using Scene Markers =

To use any scene markers that have been read, buttons on the remote need to be configured to go to the next/previous scene marker. These buttons must use the NextScene and PreviousScene codes from Keyboard.xml.

= External Player Support =

The edit decision list information that has been read by XBMC can be used by the external MPlayer through a temporary .edl file that is generated by XBMC to a known location. Since MPlayer only supports cuts and mutes any scene markers that have been read are ignored and any commercial breaks that have been read are converted to cuts.

= Not Implemented =


 * Compensation for cuts when percentage seeking is used and the show length is unknown.

= Known Issues =


 * If the playback start time isn't detected correctly by ffmpeg, e.g. the playback time starts at something other than 00:00:00, commercials will not be skipped at the right time.
 * Reading the commercial breaks from a UCS-2 encoded BeyondTV .chapters.xml file fails.