Category Archives: bend / dvd2mkv

fun with mplayer: save / resume playback script

I must be on a roll. I just got my other big problem with mplayer solved: resuming playback. :)

It turns out that MPlayer has a lot more slave / LIRC events than I knew about, and one of them is ‘get_time_pos’ which prints out the current playback position to stdout. With that, I was able to write a php shell script to save that value to a file, and read it on playback and seek to that position. Pretty cool stuff.

Here’s the script, I’ve added it to my SVN repository for bend:

Right now the only problem it has is that it’s PHP5 dependent, and only then because I use file_put_contents() and file_get_contents(). I haven’t been using PHP4 for a long time, so I was too lazy to make it backwards compatible, but I’ll fix it later.

I’ve documented how to use it in the script, so everything is already covered there. I’ve been testing it and it works great. Now I can seek chapters on my video files and leave and come back anytime I want. I’m pretty excited about that. :)

Leave a comment

Filed under bend / dvd2mkv, Computers, MPlayer, Multimedia

ask, and ye shall receive

One of my biggest beefs about media players (if you haven’t noticed yet) is the lack of support for my favorite media wrapper, Matroska. If you don’t know what that is, just ask me next time I’m around, and watch me shift into extreme-fanboyism explanation mode. Simply put, though, its similar in concept to AVI, but far superior in features.

My favorite part of it is you can have chapters in any Matroska file just like you can in an DVD. The reason I want something like that so badly is for two reasons. One is that once I have a feature in one format, I’ll go stir crazy until I have it another. The second one is that the chances of me sitting through one movie in an entire sitting are pretty low. My threshold is at about an hour, max.

So, if I leave and come back often … I want to be able to *quickly* get to where I left off. Either by resume playback completely (I’m working on that one) or skipping to the next chapter. No, I don’t want to skip ahead 5 seconds / minutes / hours. I want to skip to the next chapter.

My whole point of this is that it finally occurred to me to actually ask for this feature on the MPlayer mailing list instead of constantly complaining that it didn’t have it. Well, much to my surprise, someone much smarter than me posted a patch just a few hours later, and to make a long story short … it works great. :D

I’m hoping it gets included into the main program soon. That would be really cool. I’m still just really stoked that my most wished-for mplayer feature got added. Not to mention that it was really easy just to ask for it. :) I really should try out this strange thing called “communication” some more.

Leave a comment

Filed under bend / dvd2mkv, Computers, MPlayer, Multimedia

changeset #10

I’ve run out of interesting titles for my ‘bend’ updates, so I figure the changeset # is just as non-entertaining.

I hit a critical point today in the coding — I’m finally at a point (again) where I’d use the current snapshot to go ahead and rip / encode my DVDs. Yay! Basically all I did was finish up the encoding part so it outputs to the correct filename: 104._High_Diving_Hare.mkv. That would be season one, episode 4 of Looney Tunes. And that is also one of the funniest cartoons ever. I love Bugs Bunny. :)

Now all I need is a media player for Linux that can resume playback for my movies. Nevermind that my DVD players have had that feature for at least the past 7 years. I’m not bitter about it.

Actually, I did find something, but it’s not working right. And, it’s written in perl, so I’m up the river on trying to fix it myself. Theres a project called mplayer-tools that has a bunch of little wrapper scripts around mplayer. I can get it working half the time, and the other half it just skips back a few seconds on resuming. Very odd. If I could figure out how to write a shell script to capture the output of mplayer, then I could write my own, but I can’t even get that far. Ah well, on with searching / tweaking.

Leave a comment

Filed under bend / dvd2mkv, Computers, MPlayer

another update

I only worked on ‘bend’ a little bit today. The main new feature is that ripping works 100% now, and I’ve cleaned up a lot of old bugs. Encoding is the last thing left, and then I can finish up dvd2mkv.

One interesting little feature I added is that now you can rip the same disc in one or more session at the same time. Something I don’t recommend in the least, since it increases the disc readtime quite a bit. However, sooner or later, I’ll have it so you can pass bend --rip in one shell, and bend --rip --dvd_device /dev/dvd1 in the other. That can come in handy if you have more than one DVD drive and want to rip more stuff at once.

Leave a comment

Filed under bend / dvd2mkv, Computers

big changes

I’m a little tired. I ended up working on bend all day today (check out the huge changelog, I just checked it in). I got a lot of good stuff done though, and learned lots too.

I’ve done a rewrite this time with the whole interactive mode in mind. At first it got really tricky because I was having problems accessing stdin within a loop. The code wouldn’t wait for the user input, it would just keep going. Turns out that using handles to open and close it were the culprit, so now I just do $foo = fread(STDIN, 255); The php manual has a really good introductory chapter that covers that stuff (like say, important constants). It helped me get over the rough spots.

Another interesting part of the code is I’m using do … while control statements, which I’ve never had to use before. In this case, I need them because I can’t let them continue until the input matches a certain string or valid entry. Pretty interesting approach.

The code is coming along. I’d say its about halfway done overall, but the second half is going to be a snap since I don’t need to replace hardly any of it. I’ve got it setup so you can “archive” a disc. That doesn’t sound impressive at all, but the hard part was that all of it is completely driven by the user interface *and* you can do it either interactively through the console questions or with the argument flags. I like it. :)

All the other stuff is really simple, since it’s just a matter of rip track foo to location bar and encode with options x and y. All the settings are already in the user’s config file, and the functions are already working great, so it should go really fast from here on out. I’d just like to be able to use it again soon so I can watch some Brady Bunch.

Leave a comment

Filed under bend / dvd2mkv, Computers

cleaning up old code

I’m working on my ‘bend’ script tonight, cleaning up some old code that’s been irking me. Ugh. This is one of those projects that it would have gone a lot smoother if I had put all my pseudo code on paper first. Naturally, all my real planning is done at work while all my enthusiastic creativity is used at home. There’s gotta be some way to combine the two. Maybe I’ll reward myself in Twinkies for a good OSS program done right. :)

So, right now, I’m working on *simplifying* everything. I’m dumping everything in the class, making the functions more basic (doing one tiny thing) and other horrific “what was I thinking” code cleanup. Someday I’ll get a release out the door.

In the meantime, I just added a tiny still-not-perfect function I wrote to pull in options from stdin:

$ bend --rip   --debug
Your DVD is not in the database.
Would you like to archive it now? [y/N] yes
string(3) "yes"

Pretty funky … at least, I think it’s cool writing PHP shell scripts that are interactive. This certainly deserves a Hostess-brand sponge cake reward.

Leave a comment

Filed under bend / dvd2mkv, Computers

new trac setup

I setup a new trac project for bend: I included a very mini howto on the wiki if you want to try it out — dvd2mkv, at least … bend would be far too complex and confusing right now. Just download the two php files from the browse source page, and make sure you have all the dependencies.

Getting the trac frontend online is going to help a lot … at least now I can file bugs for myself so I don’t have to remember what else I need to get done. Maybe that’ll light a little fire under me at the same time. :)

Leave a comment

Filed under bend / dvd2mkv, Computers

bend / dvd2mkv madness

You know you’ve been neglecting your pet project for a while when you try to run it and your system is missing one of the required libraries. Whoops.

Just yesterday I found a program that is going to help me a lot with the project. Ogle to the rescue, again. libdvdread comes with a binary called ‘disc_id’ which gives a unique identifier for a DVD. That is a godsend, since my way of getting a “unique” identifier for the discs was to read the disc title and then check it against a regular expression pattern in my database of possible values for titles. Needless to say, a 32 number hash is much simpler.

So, I’ve started plugging away at it again. It’s safe to say that this little script needs a lot of work. But in its most basic form, it works perfectly well once you get it setup. The backend is a still an utter and complete mess though. I’ve gone from writing it in a class to procedural back to a class. Oy. And I haven’t commented things very well, and it’s very confusing when I try to find why something’s not working right. I’m still really excited about it though.

I think one main thing I need to do (besides actually publically releasing it) is get a little text interface going, similar to nuvexport. That way you won’t have to do something like bend --archive --title "Malcolm in the Middle" --rip --encode. I’ve also thought about rewriting it in bash, but it’d be a pain the arse right now, since I don’t know any bash programming. It would cut down on the very strict level of dependencies though — right now it requires PHP 5.1.0 and PostgreSQL. Ah well. Someday. :)

Leave a comment

Filed under bend / dvd2mkv, Computers

dvd2mkv magic

My little dvd2mkv script is coming along. You can actually pop in a DVD, run the script and come back a few hours later and you’ll have a nice shiny Matroska file complete with chapters and all. I’m actually pretty proud of it, even though there is still a lot of bugs, and you can’t do the main feature I wanted yet, which is to queue movies.

The good thing though is that it’s down to mostly fixing bugs and fixing code far more than it is adding features and just plain getting it to work. That’s a good milestone, I’d say.

One thing I like a lot about it is I’m just plain learning to write some better code. This is my first really interactive php shell script, and writing the backend, I keep finding better ways to clean it up and make the code tighter.

Just running an interactive script by itself is very cool. I was really surprised when I found out how easy it was.

The hardest part in all of this has been the transcode arguments. Actually, the first 85% or so of it was really simple, using dvd::rip as a reference and then reading up on the excellent transcode man pages. Transcode comes with some really good tools, and I still prefer it over MEncoder even though it (mplayer) would make things generally *so* much simpler. For instance, I already prefer tcprobe to midentify as getting me some really good valid data. That’s not a fair comparison, I know, since they both return different types of data. I’ll probably end up using them both. Right now I rely heavily on them both. Mplayer to rip the VOB, transcode to encode it to an XviD, and in the future tcprobe to make sure I’m doing things right. :)

Good stuff.

Leave a comment

Filed under bend / dvd2mkv, Computers, Multimedia, Transcode

bend and dvd2mkv

I’ve been working on bend a lot lately (my PHP script to rip DVDs), and am taking a break to work on a different script — dvd2mkv.

dvd2mkv will basically be a somewhat interactive PHP script to rip a DVD, do a two-pass encode and dump the whole thing into a Matroska file.

Anyway, working on it the other day I got some code working so I could have a .bendrc file in normal rc file fashion, that is param=value, and wrote a function parse it too. Here’s that:

function parseConfigFile($file) {
$readfile = file($file);
$readfile = preg_grep('/^\w+=(\w|\/)+$/', $readfile);

foreach($readfile as $key => $value) {
$arr_split = preg_split('/\s*=\s*/', $value);
$arr_config[trim($arr_split[0])] = trim($arr_split[1]);

return $arr_config;

Leave a comment

Filed under bend / dvd2mkv, Computers