Skip to content

Commit

Permalink
Fix wrong angle selection and add sanity check
Browse files Browse the repository at this point in the history
  • Loading branch information
HolyWu committed May 11, 2017
1 parent e82c6f8 commit 0c11046
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Description

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.
There are three elements in the dictionary:
* key 'clip' contains a list of full paths to each m2ts file in the playlist.
* key 'filename' contains a list of filenames of each m2ts file in the playlist.
* key 'count' contains the number of m2ts files in the playlist.


Usage
Expand All @@ -16,7 +16,7 @@ Usage

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

* angle: Selects the angle of the movie.
* angle: The angle index to select in the playlist. Index numbers start from zero. If the playlist isn't multi-angle, this setting does nothing.


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 Down
16 changes: 10 additions & 6 deletions ReadMpls/ReadMpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ static void VS_CC readMplsCreate(const VSMap *in, VSMap *out, void *userData, VS
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");
const int angle = int64ToIntS(vsapi->propGetInt(in, "angle", 0, &err));

MPLS_PL * pl = bd_read_mpls(source.c_str());
if (!pl)
Expand All @@ -40,8 +37,15 @@ static void VS_CC readMplsCreate(const VSMap *in, VSMap *out, void *userData, VS
vsapi->propSetInt(out, "count", pl->list_count, paReplace);
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";

unsigned effectiveAngle = 0;
if (pi->is_multi_angle) {
if (angle < 0 || angle >= pi->angle_count)
return vsapi->setError(out, ("ReadMpls: angle index out of range. There are only " + std::to_string(pi->angle_count) + " angles in the playlist").c_str());
effectiveAngle = angle;
}

const std::string filename = std::string{ pi->clip[effectiveAngle].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);
}
Expand Down

0 comments on commit 0c11046

Please sign in to comment.