Hacked Audacious Audio Player to play Video!

My favorite (audio) player that I use all the time for music, online radio stations, and even listening to “videos” of someone standing at a pulpit delivering a sermon is “Audacious“, an advanced, free and open-source audio player with both a GTK, QT, and beautiful Winamp skin interface that can play the audio part of nearly anything thrown at it! Over the years I’ve hacked on it a bit to add a few features that make my own use of it a bit easier.  It also has many plug-ins, including “visualization” plug-ins that can pop up a window and display cool visual effects as the music plays.  One day recently, I was listening to a streaming mp4 video sermon and started wondering “why couldn’t there be a visualization plug-in that would simply display the video portion in the visualization window?” I googled around for such a plug-in and found none.  I decided to post on the Audacious plug-in forum (my actual thread) inquiring as to whether anyone else was working on something like this or for advice on how to go about doing one myself.  I got a response back fairly quickly from John Lindgren, the main author of Audacious suggesting that it was probably not worth my time and doubting my ability to create anything comparable to top-flight video players.  I too doubt my abilities to create a top-flight video player but I’m not really interested in doing that, rather my desire is to just create something simple that works reasonably well.  Besides, I’m a retired software developer, have plenty of spare time, and need an occasional programming challenge to keep my mind and skills sharp! Anyway, I took John’s reply as a challenge and now, I’m happy to report that I have a working video option patch to Audacious! To quote the famous words of Buggs Bunny – “He don’t know me vewy well, do he :D!” (Remember – I’M Jim POSSIBLE!)
Jim PossibleI ended up eschewing the “Visual Plug-in” option since those can be turned on and off on the fly and I quickly realized that we needed this either on or off BEFORE the stream is opened, so I ended up zeroing in the “ffaudio” plug-in, which already processes all the formats that have video that I want to play (mp4, avi, flv, swf, etc.) It looks for the audio packets and discards all the rest.  My initial thought for something quick and dirty was to try simply piping the output as it came in to an external program, such as “ffplay.” I quickly got this working pretty well such that I could pause and stop the audio playback in Audacious and the video would pause and play pretty much in sync with the audio! Perfect for streaming, but I wanted MORE!
When playing a downloaded file Audacious has a slider that lets you seek within the audio, which with the video being piped, naturally craters! Therefore, if I wanted a plug-in option worthy of Audacious, I needed to actually process the video within Audacious itself.  I began looking at the ffplay source code and searching around for how to process video streams with ffmpeg and with much trial and error, got it working somewhat.  The controls in Audacious worked, including seeking for the most part (but randomly cratered on some seeks), and the video was often a bit “jerky.” Still not satisfied, I looked at my code closer and found that the problem was that the video and audio packets, which are processed in the order they are received, are often clustered together in bunches.  Therefore, some way was needed to “interlace” them together as much as possible.  Since Audacious is an audio player and does a beautiful job of processing the audio, I wanted to leave this alone as much as possible and let the audio drive the processing, so I decided to try queuing the video packets until an audio packet is read, then processing the next video packet in the queue before processing the audio packet.  This greatly improved things!
Still not happy, I played around some more and realized that while my methodology assumed that the number of audio and video packets would be roughly the same, the reality is that most videos I tested seem to have roughly twice the number of audio packets as video.  I tried one more thing:  only popping a video packet off the queue every OTHER audio packet and suddenly, much to my surprise, the “jitter” was all but GONE! I also got the seek failures all but eliminated by changing the seek mechanism from AVSEEK_FLAG_ANY to AVSEEK_FLAG_BACKWARD to force the seek to the nearest “key” packet after doing some more research.  Anyway, I now have a working patched “ffaudio” plug-in that will, if the user sets the new “play_video” option to TRUE, will pop up a video “visualization” window when playing a stream that contains video! Obviously, it’s not “perfect” like a true video-player such as VLC or mplayer, but tweaking the new queue size (“video_qsize”) and pixel scaling algorithm options (“video_sws_scale”) in the config file, most videos play nearly perfect for me (usually the more noticeable “imperfections” are due to my internet connection and affect all video players!) I’ve submitted my hacked plug-in to the Audacious team for possible inclusion, but based on previous experience, I have some doubts as to when (or whether) they will actually accept it, so if you want to use it now, I’ve included the source here!  (it’s a single file:  ffaudio-core.cc).  To build, download the source for Audacious and Audacious-Plugins, and all the necessary development packages, save and replace the file:  audacious-plugins/src/ffaudio/ffaudio-core.cc with the code included here, rebuild, add the following to your ~/.config/audacious/config file, and give it a try (The last four are commented out with their default values, but you probably don’t need to uncomment or change them.
[ffaudio]
play_video=TRUE
video_windowtitle=Audacious Video
#video_qsize=16
#video_sws_scale=4
#video_xsize=800
#video_ysize=600
You will also need to tweak the Makefile in audacious-plugins/src/ffaudio/ to look like this:
PLUGIN = ffaudio${PLUGIN_SUFFIX}

SRCS = ffaudio-core.cc ffaudio-io.cc itunes-cover.cc

include ../../buildsys.mk
include ../../extra.mk

plugindir := ${plugindir}/${INPUT_PLUGIN_DIR}

LD = ${CXX}

CFLAGS += ${PLUGIN_CFLAGS}
CPPFLAGS += ${PLUGIN_CPPFLAGS} ${GLIB_CFLAGS} ${GTK_CFLAGS} ${FFMPEG_CFLAGS} -I/usr/include/SDL -I../.. -D_GNU_SOURCE=1 -D_REENTRANT
LIBS += ${GTK_LIBS} ${FFMPEG_LIBS} -lswscale -lavcodec -laudtag -lX11 -lSDL -lz -lm

And the audacious-plugins/extras.mk file to include these two lines to use the SDL library:
SDL_CFLAGS ?= -D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/SDL
SDL_LIBS ?= -lSDL
Also, if using a version of Audacious higher that v3.6.0, edit ffaudio-core.cc looking for comments containing “BUILD NOTE” as they will direct you to tweak other things for newer versions of Audacious!
You can find some other instructions for building Audacious from scratch here:  http://redmine.audacious-media-player.org/boards/1/topics/788.
Now I’m enjoying streaming youtube video using youtube-dl with one click of a mouse button through my Awesomely-hacked “Fauxdacious” version of Audacious using the following script file on Linux (you’ll need to change “fauxdacious” to “audacious” and most likely:  “stdin://-.mp4” to “-“):
/usr/local/bin/youtube-dl --youtube-skip-dash-manifest -f mp4 --no-part $1 -o - 2>/dev/null | fauxdacious -Dc stdin://-.mp4

Image:  Me watching my alter-ego “Derick Wildstar” gettin’ the girl in The Starblazers Movie:
Space Battleship Yamato 2010” in “Fauxdacious” – YEAH! 😀
Advertisements

One Trackback

  1. […] « Hacked Audacious Audio Player to play Video! […]

Feel Free to Comment (Name/Email/Website optional):

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: