Showing posts with label matroska. Show all posts
Showing posts with label matroska. Show all posts

Monday, October 26, 2009

MPlayer Bleeding Edge

I've been using mplayer from the git repository because it provided the best solution to the problem of Matroska order chapters (linked segments, linked chapters, whatever) in fansubbed anime. But development moved off the master branch and my earlier attempts to compile the tmp_build branch didn't work because mplayer's configure script could not find FFmpeg.

The requirement that FFmpeg be embedded in the mplayer source tree, has been removed, so you either have to build and install FFmpeg from source, or install whatever binary packages are available for your distribution. I choose the latter because I am using Debian/unstable and the packages in the multimedia repository are usually recent repository checkouts anyway.

The following packages from Debian multimedia satisfy all mplayer's FFmpeg requirements: libavcodec-dev libavformat-dev libpostproc-dev libswscale-dev.

Other packages I found useful for codecs: libx264-dev, libxvidcore4-dev; and for audio and video: libasound2-dev, libxv-dev; and for ASS substitles: libfreetype6-dev, libfontconfig1-dev, libass-dev. This list is incomplete since I haven't tracked every library I have installed. Just install what you need, when you need it.

To build the tmp_build branch:
$ git clone git://repo.or.cz/mplayer
$ cd mplayer
$ git checkout -b tmp_build origin/tmp_build
$ ./configure
$ make
$ make install
For bleeding edge software, it works great! The little glitches in the Matroska ordered chapter support are all gone which is a great improvement.

Which leads to the question: why are these improvements not being merged into the master branch? Master hasn't been updated in about four months. Even an unofficial project needs to make it clear what people should be using, otherwise someone like me will just tell the world how to use the bleeding edge development branch. That might not be what you wanted.

Saturday, September 26, 2009

MPlayer And Mkv Linked Chapters VII

Mad Fish The One tried using this post to compile mplayer with Matroska linked chapter support and found that the compile failed. After some investigation I realized that I had already discovered that problem in July, which was also the last time I compiled mplayer. Unfortunately, I neglected to tell anyone else about it! Bad me! (-_-;

Development on the mplayer git repository has moved off the master branch, perhaps prompted by a bunch of yahoos suddenly taking an interest in the work... Anyway, the mplayer master branch hasn't changed at all since early July while the ffmpeg master branch is changing very rapidly, with result that mplayer no longer compiles against a recent ffmpeg checkout.

Mad Fish posted another solution here. The disadvantage of this one is that it depends on a third party patch, but it uses a newer ffmpeg which is a huge plus compared to what I did.

My solution back in July was to compile against a specific version (svn r19395) of ffmpeg. That version is now very old so it may be missing bugs fixes and other improvements. I've been using the same mplayer I compiled in July and I haven't noticed any problems. YMMV
git clone git://repo.or.cz/mplayer.git
cd mplayer.git
git clone git://git.ffmpeg.org/ffmpeg/
cd ffmpeg
git checkout 4477ec66b # git commit matching svn r19395
cd ..
./configure
make
I tried building the mplayer git development branch and I haven't gotten past the configure step yet. There have been many changes and it is not clear to me how it is detecting ffmpeg any more.

Finally, what is the official name of this Matroska feature anyway? I perused the Matroska site and it is not at all obvious what the spec calls it. I've been using "linked chapters", but others use "linked segments" and "order chapters." None of these strings appear anywhere in the spec.

Friday, May 8, 2009

MPlayer And Mkv Linked Chapters VI

[2009/09/26: More recent info here]

Well, after upgrading to faster hardware, I tried styled subtitles with 720p video for the first time. Running through my test videos, I found a case which the patch does not handle. When the linked chapter is the first chapter, MPlayer does not display the subtitles from the main file. If the linked chapter occurs later in the chapter list, all subtitles work normally. Unfortunately, the opening title chapter is usually the first one in most anime videos, so this is big problem.

Faced with doing more serious digging into the source file, I was feeling the limitations of Subversion. While investigating MPlayer git repositories, I noticed the development branch logged some changes for “ordered chapters.” Was this yet another effort to add support for Matroska ordered chapters? Only one way to find out: try it!

The following will downloaded MPlayer source from the development branch. You will also need the FFmpeg source.
git clone git://repo.or.cz/mplayer.git
cd mplayer.git
git clone git://git.ffmpeg.org/ffmpeg/
Then configure, build and install as usual.
./configure
make
make install

This attempt at the linked chapter problem works very well. It plays all my test videos, even the ones where the encoding of the external files do not match the main file exactly. There is occasionally a slight hesitation in the video when switching between the linked chapters, but it is not consistent so it may be hard to track down. So far that is the only problem I've noticed but I'm sure I'll find something. This is the development branch after all, and I certainly wouldn't expect it to be completely problem free. However, it is a good sign that linked chapter support is finally in a repository rather than some random patches which may never be updated.

Monday, May 4, 2009

MPlayer And Mkv Linked Chapters V

An updated patch for MPlayer Matroska linked chapter support is available here. The patch should apply cleanly to a recent Subversion checkout of the MPlayer source. You will also need the development header files for the libraries that you expect to use with MPlayer. You can figure what is missing by examining the output at the end of the ./configure command. I did not pass any flags to ./configure.

Download the source:
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
Compile:
cd mplayer
./configure
make
make install
Test MPlayer thoroughly with some files that you know should work. If they do not play properly, you should figure out why before applying the patch. At this point you can still expect to get some help from the MPlayer-users mailing list.

Apply the patch and recompile:
patch -p0 <mplayer_matroska_linked_chapters.diff
./configure
make
make install
MPlayer will now play a .mkv file with linked chapters. The external files must be in the same directory as the main file, otherwise MPlayer will not find them.

The original patches that I used, can be found here for those who are curious, but you don't need them, as the updated patch includes everything from the originals. My only addition forces MPlayer to always play the external chapters even if they appear to be incompatible. I did this because there no command line option to control the flag. If the external files are really incompatible, it will be obvious anyway, and you must delete them or move them out of the directory so that MPlayer cannot find the files. Renaming will not work.

Please do not expect support for this patch on the MPlayer mailing lists since the devs did not accept the original patches. We are on own with this one. The work to add linked chapter support has moved to ffmpeg (here and here), but I couldn't find any sign that those patches were ever accepted. We may be stuck using a feature without developer support.

Wednesday, April 29, 2009

MPlayer And Mkv Linked Chapters IV

I finally got the MPlayer patches that I mentioned previously, to work. It turned out to be my own fault. While fixing a failed hunk in the configure script, I left out the line which enables the new directory scanning feature. After finding that error, the patch works now and there was much rejoicing!

It works but the external files must have the exact same codec headers as the main file, otherwise the external file will not be played. I believe the test ensures that the external files were encoded with the same settings as the main file. Whether this is a bug or feature, I'm not sure yet, but I already have one video which fails the test. I hope this is not a common problem. Only time will tell.

Thursday, April 23, 2009

MPlayer And Mkv Linked Chapters III

In the on going effort to add Matroska linked chapter support to MPlayer, I found a more recent collection of patches which adds the linked chapter support through the avformat library. The patches did not apply cleanly to the latest Subversion checkout, but once again the failures were easily corrected. Unfortunately, the patch does not work for me. The linked chapter headers are ignored even though the the avformat library is demuxing the .mkv file. Looks like I'm still going to be digging into the MPlayer source.

Sunday, April 19, 2009

MPlayer And Mkv Linked Chapters II

A few days ago I started playing with a patch which adds Matroska linked chapters support to MPlayer. I got the patch to work but there were a number of problems.

First, the patch did not apply cleanly but really two failed hunks out of forty is not bad all. I fixed the failed hunks quickly. The next problem was the build failed. The patched code was calling a function that had been removed about six months ago. I poked at this problem for a while, but eventually concluded that, since nothing actually replaced the missing function, I could just remove the call from the patched code. It was really just a wild guess but it worked! The patched code compiles cleanly now and playing a Matroska file with linked chapters proves the patch works.

But there a still problems and these will be much harder to figure out. The most obvious problem is the patch causes playback to loop forever, which is quite a strange side effect. A more subtle problem, is a timing glitch in the subtitles when the MPlayer switches between the main and linked file. The problem corrects quickly but it is noticeable.

Both of these problems will require a lot more digging, but if I'm going get that deeply into the MPlayer source, I may be better off looking at how this could done properly. In addition, the MPlayer developers have already rejected this patch so I really can't expect support from them, which will make the work much harder.

Wednesday, April 15, 2009

MPlayer And Mkv Linked Chapters

An increasing number of anime fan subbers are using the .mkv feature of linked chapters to have separate files for the opening and ending title sequences (OP and ED), which are usually constant for the duration of the series. Separating the OP and ED allows the fan subber to either make each episode file smaller, or to encode the video at a better quality setting in the same size file. Thankfully, we are a long way from everyone jumping on this bandwagon, because there is one problem. There is only one player on Windows that supports .mkv linked chapters and the feature isn't even on the road map of any of the Linux media players.

There is a patch to add .mkv linked chapters to MPlayer, but the developers have rejected the patch as an ugly hack. Even the patch submitter conceded it is crap! Even ugly hacks have been known to work so I downloaded the MPlayer source from the Subversion repositories in preparation for trying the patch. I got a working build fairly quickly which is always surprising. I only included the necessary codecs that I need for daily use and everything worked correctly with the two .mkv files that I watched tonight.

The patch will require some extra work since it does not match the current Subversion source any more. A dry run indicates that most of the patch still applies albeit with some very large fuzz offsets. However, I decided to tackle this step with a fresh mind tomorrow.