Archive

Posts Tagged ‘gstreamer’

Create a GStreamer powered Java media player

March 14th, 2011 1 comment

For something to do I decided to see if I could create a very simple Java media player. After doing some research, and finding out that the Java Media Framework was no longer in development, I decided to settle on GStreamer to power my media player.

GStreamer for the uninitiated is a very powerful multimedia framework that offers both low-level pipeline building as well as high-level playback abstraction. What’s nice about GStreamer, besides being completely open source, is that it presents a unified API no matter what type of file it is playing. For instance if the user only has the free, high quality GStreamer codecs installed, referred to as the good plugins, then the API will only play those files. If however the user installs the other plugins as well, be it the bad or ugly sets, the API remains the same and thus you don’t need to update your code. Unfortunately being a C library this approach does have some drawbacks, notably the need to include the JNA jar as well as the system specific libraries. This approach can be considered similar to how SWT works.

Setup

Assuming that you already have a Java development environment, the first thing you’ll need is to install GStreamer. On Linux odds are you already have it, unless you are running a rather stripped down distro or don’t have many media players installed (both Rhythmbox and Banshee use GStreamer). If you don’t it should be pretty straight forward to install along with your choice of plugins. On Windows you’ll need to head over to ossbuild where they have downloadable installers.

The second thing you’ll need is gstreamer-java which you can grab over at their website here. You’ll need to download both gstreamer-java-1.4.jar and jna-3.2.4.jar. Both might contain some extra files that you probably don’t need and can prune out later if you’d like. Setup your development environment so that both of these jar files are in your build path.

Simple playback

GStreamer offers highly abstracted playback engines called PlayBins. This is what we will use to actually play our files. Here is a very simple code example that demonstrates how to actually make use of a PlayBin:

public static void main(String[] args) {
     args = Gst.init("MyMediaPlayer", args);

     Playbin playbin = new PlayBin("AudioPlayer");
     playbin.setVideoSink(ElementFactory.make("fakesink", "videosink"));
     playbin.setInputFile("song.mp3");

     playbin.setState(State.PLAYING);
     Gst.main();
     playbin.setState(State.NULL);
}

So what does it all mean?

public static void main(String[] args) {
     args = Gst.init("MyMediaPlayer", args);

The above line takes the incoming command line arguments and passes them to the Gst.init function and returns a new set of arguments. If you have every done any GTK+ programming before this should be instantly recognizable to you. Essentially what GStreamer is doing is grabbing, and removing, any GStreamer specific arguments before your program will actually process them.

     Playbin playbin = new PlayBin("AudioPlayer");
     playbin.setVideoSink(ElementFactory.make("fakesink", "videosink"));
     playbin.setInputFile("song.mp3");

The first line of code requests a standard “AudioPlayer” PlayBin. This PlayBin is built right into GStreamer and automatically sets up a default pipeline for you. Essentially this lets us avoid all of the low-level craziness that we would have to normally deal with if we were starting from scratch.

The next line sets the PlayBin’s VideoSink, think of sinks as output locations, to a “fakesink” or null sink. The reason we do this is because PlayBin’s can play both audio and video. For the purposes of this player we only want audio playback so we automatically redirect all video output to the “fakesink”.

The last line is pretty straight forward and just tells GStreamer what file to play.

     playbin.setState(State.PLAYING);
     Gst.main();
     playbin.setState(State.NULL);

Finally with the above lines of code we tell the PlayBin to actually start playing and then enter the GStreamer main loop. This loop continues for the duration. The last line is used to reset the PlayBin state and do some cleanup.

Bundle it with a quick GUI

To make it a little more friendly I wrote a very quick GUI to wrap all of the functionality with. The download links for that (binary only package), as well as the source (all package) is below. And there you have it: a very simple cross-platform media player that will playback pretty much anything you throw at it.

Please note that I have provided this software purely as a quick example. If you are really interested in developing a GStreamer powered Java application you would do yourself a favor by reading the official documentation.

Binary Only Package All Package
File name: my_media_player_binary.zip my_media_player_all.zip
Screenshots:
Version: March 13, 2011
File size: 1.5MB 1.51MB
File download: Download Here Download Here

Originally posted on my personal website here.




I am currently running a variety of distributions, primarily Linux Mint Debian Edition.
Previously I was running KDE 4.3.3 on top of Fedora 11 (for the first experiment) and KDE 4.6.5 on top of Gentoo (for the second experiment).
Check out my profile for more information.

My Search for the Best Audio Editing Software

October 6th, 2010 7 comments

Lately, I’ve been doing some audio recording. In addition to a couple of podcasts that I work on, I occasionally like to record my own musical compositions. While there seems to be no shortage of high-end audio editing applications on either Windows or Mac, the situation on Linux is a bit more sparse. Faced with some frustration, I went out and downloaded a number of linux-based audio editors. I used Wikipedia to find the software in the tests below, and following are my totally subjective and highly biased reviews of each.

Each piece of software was used to edit some raw recordings from a podcast that I have been involved with lately. This source material is almost 100% spoken word, with some music and sound effects sprinkled throughout. It’s important to note these details, as your needs may vary drastically depending on the type of audio project that you’re working on.

Audacity:

The Audacity Project is kind of the Linux standard for non-professional audio editing. It was the first application that I tried to use, mainly because I was familiar with earlier versions of the program that I had once used back in my Windows days. Audacity includes a great number of features that make it ideal for post-processing of any audio project, including a wide array of effects, some great noise generators, and a few analysis tools that make it perfect for cleaning up your finished file before publication.

Audacity audio editor with a demo project loaded

Audacity audio editor with a demo project loaded

Unfortunately, I found that it lacked a usable GUI for editing podcast material. In particular, it seems to be missing the ability to edit a single track in a multi-track project without unduly affecting the other tracks.By default, if you use the selection tool to grab a portion of audio that ought to be deleted from one track in the project, it seems to delete that portion of audio from all tracks in the project.

I found this out the hard way when I played back the master track that I had assembled my finished podcast on, only to find out that significant portions of the audio had mysteriously gone missing at some point during the editing process.

To make matters worse, I closed the application, lost the undo record for the project, and had to start the editing process from the beginning.

This lack of GUI polish also exhibits itself in the way that you can interact with the audio tracks themselves. Unlike in most DAW solutions, a portion of audio that has been clipped out of a larger track cannot seemingly be moved around in the project by clicking on it and dragging it across the stage with the mouse. At least I couldn’t figure out how to do it, and ended up relying heavily on my cut, copy, and paste functions to edit my project. This is a poor way to work on a project of any kind of complexity, and makes projects that rely on audio loops a pain to assemble.

Ardour:

Where Audacity is suited more towards hobbyist recording setups, Ardour aims to be a professional audio solution that is capable of competing with mainstream software like ProTools. It is a fully featured audio suite that can allegedly do most everything that you may require, but as such, can also confuse the hell out of first-time users with its complicated GUI and lengthy manual.

Granted, this is hardly a slight to the project, because it really isn’t suited to my needs. It is a pro-level audio environment that can be used as the centrepiece to a full recording studio or stage

Ardour wants sole control of my audio interface

Ardour wants sole control of my audio interface

show. If you just want to edit a podcast, it may not be the tool for you. As such, if the GUI seems challenging and you find the documentation to be long-winded, you may just be using the wrong tool for the job.

The biggest issue that I had with this piece of software was getting it to run at all on my machine. It uses JACK to attach itself to your audio interfaces in the name of providing a perfect sampling environment that doesn’t get slowed down by having to share the interface with other pieces of software.

Unfortunately, this means that in order to use it, I had to quit all other processes that are capable of generating sound, including this web browser. This is a pain if you are trying to run Ardour in a multi-application environment, or need to reference the internet for anything while working.

After reading the introductory documentation and adjusting the settings in the startup dialog for about 15 minutes, I simply gave up on Ardour without ever managing to get into a workspace. It seems to be far too complicated for my needs, and doesn’t seem worth my time. Your mileage may vary.

Jokosher:

From the moment that I started reading about this project, I like the sound of it. Jokosher is a multi-track recoding and editing environment built on top of Python and GStreamer that was

Jokosher may look cartoony, but it may be exactly what you need for small projects

Jokosher may look cartoony, but it may be exactly what you need for small projects

created by a podcaster who was unsatisfied with the audio editing tools that were available on Linux. The application focuses on being easy enough to use that non-technical people like musicians can pick it up and get their ideas down with minimal hassle. Think of it as Garage Band for Linux.

Indeed, just as the website promised, I was able to get a working environment set up in a matter of minutes. The editing tools allow for splitting the audio, grabbing it and moving it around, and non-destructively editing multiple tracks at the same time (I’m looking at you, Audacity). The GUI also has a beautiful polish to it that, although a tad cartoony, really makes the program look and feel simple. For editing something like a podcast, I’m not sure that this application can be beat.

The only issue that I encountered in my short time using Jokosher was with its support of LADSPA plugins. These are free audio plugins that can be used to apply effects to the different tracks of your audio project. When I tried to use them from within the application, it instructed me to download some from my repositories. Upon checking Synaptic, I saw that I already had a number of them downloaded. Even after installing more, the program did not seem to pick them up.

All in all, this project lived up to its hype, and I will most certainly take some time to break it in, and may write a more in-depth review once I get used to it. If you’re doing podcasting, you owe it to yourself to check this app out.

In Conclusion:

Each of the three applications that I tried to work with while writing this piece deserve your respect. The underlying audio framework of most Linux systems is a veritable rats’ nest of subsystems, platforms, daemons, plugins and helper applications. I would wager a significant amount of money on this situation as the reason that we don’t have ProTools and its ilk on our platform of choice. I’ve done a little bit of work with GStreamer, and even it, as perhaps the prettiest and best supported of all audio libraries on the platform, left me scratching my head at times.

When choosing audio software, it’s important to keep in mind that you need a tool that’s uniquely suited to your project. Since I’m editing podcasts and fooling around with drum loops and samples of my guitars, Jokosher does just about everything that I need and more. I may use Audacity for post-production, or to record my source audio (simply because I haven’t tried recording in Jokosher yet – I know that Audacity works), because it falls somewhere in between a simple editing tool and an advanced platform. Ardour, meanwhile, is probably suited towards the more hard-core audio engineer slash system administrator types who are so fanatic about recording quality that they are willing to sacrifice an entire box for running their DAW software. It’s simply more power than the majority of hobbyist enthusiasts really needs.




On my Laptop, I am running Linux Mint 12.
On my home media server, I am running Ubuntu 12.04
Check out my profile for more information.

Pulse Audio Nonsense

January 4th, 2010 3 comments

Just a heads up: This isn’t the kind of post that contains answers to your problems. It is, unfortunately, the kind of post that contains a lot of the steps that I took to fix a problem, without much information about the order in which I performed them, why I performed them, or what they did. All that I can tell you is that after doing some or all of these things in an arbitrary order, stuff seemed to work better than it did before.

It’s funny how these posts often seem to come about when trying to get hardware related things working. I distinctly remember writing one of these about getting hardware compositing working on Debian. This one is about getting reliable audio on Kubuntu 9.10.

You see, I have recently been experiencing some odd behaviour from my audio stack in Kubuntu. My machine almost always plays the startup/shutdown noises, Banshee usually provides audio by way of GStreamer, videos playing in VLC are sometimes accompanied by audio, and Flash videos almost never have working sound. Generally speaking, restarting the machine will change one or all of these items, and sometimes none. The system is usuable, but frustrating (although I might be forgiven for saying that having no audio in Flash prevents me from wasting so much time watching youtube videos when I ought to be working).

Tonight, after some time on the #kubuntu IRC channel and the #pulseaudio channel on freenode, I managed to fix all of that, and my system now supports full 5.1 surround audio, at all times, and from all applications. Cool, no? Basically, the fix was to install some PulseAudio apps:

sudo apt-get install pulseaudio pavucontrol padevchooser

Next, go to System Settings > Multimedia, and set PulseAudio as the preferred audio device in each of the categories on the left. Finally, restart the machine a couple of times. If you’re lucky, once you restart and run pavucontrol from the terminal, you’ll see a dialog box called Volume Control. Head over to the Configuration tab, and start choosing different profiles until you can hear some audio from your system. Also, I found that most of these profiles were muted by default – you can change that on the Output Devices tab. If one of the profiles works for  you, congratulations! If not, well, I guess you’re no worse off than you were before. I warned you that this was that kind of post.

Also, while attempting to fix my audio problems, I found some neat sites:

  • Colin Guthrie – I spoke to this guy on IRC, and he was really helpful. He also seems to write a lot of stuff for the PulseAudio/Phonon stack in KDE. His site is a wealth of information about the stack that I really don’t understand, but makes for good reading.
  • Musings on Maintaining Ubuntu – Some guy named Dan who seems to be a lead audio developer for the Ubuntu project. Also a very interesting read, and full of interesting information about audio support in Karmic.
  • A Script that Profiles your Audio Setup – This bash script compiles a readout of what your machine thinks is going on with your audio hardware, and automatically hosts it on the web so that you can share it with people trying to help you out.
  • A Handy Diagram of the Linux Audio Stack – This really explains a lot about what the hell is going on when an application tries to play audio in the Linux.
  • What the Linux Audio Stack Seems Like – This diagram reflects my level of understanding of Linux audio. It also reminds me of XKCD.
  • Ardour – The Digital Audio Workstation – In the classic tradition of running before walking, I just have to try this app out.



On my Laptop, I am running Linux Mint 12.
On my home media server, I am running Ubuntu 12.04
Check out my profile for more information.

Going Linux, Once and for All

December 23rd, 2009 7 comments

With the linux experiment coming to an end, and my Vista PC requiring a reinstall, I decided to take the leap and go all linux all the time. To that end, I’ve installed Kubuntu on my desktop PC.

I would like to be able to report that the Kubuntu install experience was better than the Debian one, or even on par with a Windows install. Unfortunately, that just isn’t the case.

My machine contains three 500GB hard drives. One is used as the system drive, while an integrated hardware RAID controller binds the other two together as a RAID1 array. Under Windows, this setup worked perfectly. Under Kubuntu, it crashed the graphical installer, and threw the text-based installer into fits of rage.

With plenty of help from the #kubuntu IRC channel on freenode, I managed to complete the Kubuntu install by running it with the two RAID drives disconnected from the motherboard. After finishing the install, I shut down, reconnected the RAID drives, and booted back up. At this point, the RAID drives were visible from Dolphin, but appeared as two discrete drives.

It was explained to me via this article that the hardware RAID support that I had always enjoyed under windows was in fact a ‘fake RAID,’ and is not supported on Linux. Instead, I need to reformat the two drives, and then link them together with a software RAID. More on that process in a later post, once I figure out how to actually do it.

At this point, I have my desktop back up and running, reasonably customized, and looking good. After trying KDE’s default Amarok media player and failing to figure out how to properly import an m3u playlist, I opted to use Gnome’s Banshee player for the time being instead. It is a predictable yet stable iTunes clone that has proved more than capable of handling my library for the time being. I will probably look into Amarok and a few other media players in the future. On that note, if you’re having trouble playing your MP3 files on Linux, check out this post on the ubuntu forums for information about a few of the necessary GStreamer plugins.

For now, my main tasks include setting up my RAID array, getting my ergonomic bluetooth wireless mouse working, and working out folder and printer sharing on our local Windows network. In addition, I would like to set up a Windows XP image inside of Sun’s Virtual Box so that I can continue to use Microsoft Visual Studio, the only Windows application that I’ve yet to find a Linux replacement for.

This is just the beginning of the next chapter of my own personal Linux experiment; stay tuned for more excitement.

This post first appeared at Index out of Bounds.




On my Laptop, I am running Linux Mint 12.
On my home media server, I am running Ubuntu 12.04
Check out my profile for more information.