Skip to content

Commit

Permalink
Add "angle" parameter and export "filename" in the dict
Browse files Browse the repository at this point in the history
  • Loading branch information
HolyWu committed May 10, 2017
1 parent 4d8e727 commit e82c6f8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
Description
===========

Reads a mpls file and returns a dictionary, not a clip. There are two elements in the dictionary. The element with the key 'clip' contains a list of full path to each m2ts file in the playlist. The element with the key 'count' contains the number of m2ts file in the playlist.
Reads a mpls file and returns a dictionary, not a clip.

There are three elements in the dictionary.
* The element with the key 'clip' contains a list of full paths to each m2ts file in the playlist.
* The element with the key 'filename' contains a list of filenames of each m2ts file in the playlist.
* The element with the key 'count' contains the number of m2ts files in the playlist.


Usage
=====

mpls.Read(string source)
mpls.Read(string source[, int angle=0])

* source: The full path of the mpls file. Don't use relative path.

* angle: Selects the angle of the movie.


After obtaining the dictionary, you can use your favorite source filter to open them all with a for-loop and splice them together. For example:

Expand All @@ -19,6 +26,16 @@ mpls = core.mpls.Read('D:/rule6/BDMV/PLAYLIST/00001.mpls')
ret = core.std.Splice([core.ffms2.Source(mpls['clip'][i]) for i in range(mpls['count'])])
```

If you want to put ffms2's index file at another place rather than the same directory of the source file, here is the example:

```python
mpls = core.mpls.Read('D:/rule6/BDMV/PLAYLIST/00001.mpls')
clips = []
for i in range(mpls['count']):
clips.append(core.ffms2.Source(source=mpls['clip'][i], cachefile='D:/indexes/rule6/' + mpls['filename'][i].decode() + '.ffindex'))
clip = core.std.Splice(clips)
```


Compilation
===========
Expand Down
30 changes: 24 additions & 6 deletions ReadMpls/ReadMpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,37 @@
#include "mpls_parse.h"
#include <libbluray/bluray.h>

#include <algorithm>
#include <string>

#include <VapourSynth.h>
#include <VSHelper.h>

static void VS_CC readMplsCreate(const VSMap *in, VSMap *out, void *userData, VSCore *core, const VSAPI *vsapi) {
int err;

const std::string source{ vsapi->propGetData(in, "source", 0, nullptr) };
int angle = int64ToIntS(vsapi->propGetInt(in, "angle", 0, &err));

if (angle < 0)
return vsapi->setError(out, "ReadMpls: angle must be greater than or equal to 0");

mpls_pl * pl = bd_read_mpls(source.c_str());
MPLS_PL * pl = bd_read_mpls(source.c_str());
if (!pl)
return vsapi->setError(out, ("ReadMpls: failed to open " + source).c_str());

vsapi->propSetInt(out, "count", pl->list_count, paReplace);
for (unsigned i = 0; i < pl->list_count; i++)
vsapi->propSetData(out, "clip", (source.substr(0, source.find_last_of("/\\") - 8) + "STREAM/" + pl->play_item[i].clip[0].clip_id + ".m2ts").c_str(), -1, paAppend);
if (pl->list_count == 1)
for (unsigned i = 0; i < pl->list_count; i++) {
const MPLS_PI * pi = &pl->play_item[i];
angle = std::min(angle, pi->angle_count - 1);
const std::string filename = std::string{ pi->clip[angle].clip_id } + ".m2ts";
vsapi->propSetData(out, "filename", filename.c_str(), -1, paAppend);
vsapi->propSetData(out, "clip", (source.substr(0, source.find_last_of("/\\") - 8) + "STREAM/" + filename).c_str(), -1, paAppend);
}
if (pl->list_count == 1) {
vsapi->propSetData(out, "filename", "", -1, paAppend);
vsapi->propSetData(out, "clip", "", -1, paAppend);
}

bd_free_mpls(pl);
}
Expand All @@ -42,6 +57,9 @@ static void VS_CC readMplsCreate(const VSMap *in, VSMap *out, void *userData, VS
// Init

VS_EXTERNAL_API(void) VapourSynthPluginInit(VSConfigPlugin configFunc, VSRegisterFunction registerFunc, VSPlugin *plugin) {
configFunc("com.holywu.readmpls", "mpls", "Reads a mpls file and returns a dict", VAPOURSYNTH_API_VERSION, 1, plugin);
registerFunc("Read", "source:data;", readMplsCreate, nullptr, plugin);
configFunc("com.holywu.readmpls", "mpls", "Reads a mpls file and returns a dictionary", VAPOURSYNTH_API_VERSION, 1, plugin);
registerFunc("Read",
"source:data;"
"angle:int:opt;",
readMplsCreate, nullptr, plugin);
}

0 comments on commit e82c6f8

Please sign in to comment.