APStreamline v2!

The APStreamline project aims to make streaming live video from companion computers as painless as possible. It was first released as the product of my ArduPilot GSoC project back in 2018. Community feedback for APStreamline was very encouraging and that led me to continue development in 2019. However, there was an issue which had been nagging at me from the outset of its v1 release - adding support for new cameras was tricky due to the confusing coupling of some classes in the codebase. In fact, the most requested feature I’ve received for APStreamline has been to make it easier to add support for different types of cameras.

APStreamline has grown to support a wide variety of use cases for network adaptive video streaming

The Linux V4L2 driver helps in making it easier to add support for different cameras. Several cameras have a standard interface for capturing video using GStreamer elements. So why does support for each camera need to be baked into the code? The reason is that some cameras use different GStreamer elements, some only support non-standard resolutions, and some even have onboard ASICs for H.264 compression. For example, in the NVIDIA Jetson line of single-board computers have GStreamer pipelines built specifically for accessing the Jetson’s ISP and hardware encoder for high quality video encoding. To make the most of each camera and companion computer, it is well worth the effort to add specific support for popular camera models.

All this inspired a rewrite of the code, and I am proud to announce that with the release of APStreamline v2, it is now much simpler to add support for your own camera! Let’s first take a look at what devices are already supported:

Cameras Supported

  • Logitech C920 webcam
  • Raspberry Pi Camera (Raspberry Pi only)
  • e-Con AR0521 (requires the Developer Preview version of NVIDIA Jetpack 4.4)
  • ZED2 Depth camera (V4L2 mode)
  • Any camera which support MJPG encoding (fallback when specific support is not detected. The MJPG stream from the camera is then encoded to H264 using a software encoder.)

Devices Tested

  • Raspberry Pi Zero W/2/3B
  • NVIDIA Jetson Xavier NX
  • x86 computer

Adding Your Own Camera

To add specific your own camera, follow these steps!

1) Figure out the optimized GStreamer pipeline used for your camera. You can usually find this in the Linux documentation for your camera or online developer forums. There are differences for each camera but there is a generic template for most GStreamer pipelines: SRC ! CAPSFILTER ! ENCODER ! SINK. There might be more elements or additional capsfilters depending on each camera. In case you aren’t sure what to do, feel free to drop a GitHub issue to ask!

2) Create a configuration file for your camera. There are examples in the config/ folder. The element names must match those in the examples for APStreamline to set references to the GStreamer elements correctly.

3) Subclass the Camera class and override the functions for which you want to add specific support for your camera. To give an example, the ways in which the H264 encoding bitrate is set are different for various cameras and encoder configurations. For instance, pipelines which use the x264enc encoder can change the bitrate by using g_object_set, whereas the Raspberry Pi camera GStreamer pipeline needs an IOCTL to change the bitrate. There is a fair bit of trial and error to discover what the capabilities of a GStreamer pipeline are. Not all pipelines support the dynamic resolution adaptation of APStreamline, so this feature must be disabled if it causes the pipeline to crash in testing.

4) Create a new type for your camera and add it to the CameraType enum class.

5) Add the enum created in the previous step to the CameraFactory class.

6) Add a way of identifying your camera to RTSPStreamServer. A good way of adding a way to identify your camera is by using the Card type property from v4l2-ctl --list-formats-ext --all --device=/dev/videoX. In case your camera is not specifically detected, the fallback is to encode the MJPG stream from your camera using the H264 software encoder, x264enc.

7) File a Pull Request to get your camera added to the master branch!

To Do

APStreamline could use your help! Some of the tasks which I want to complete are:

  • Add support for the tegra-video driver back into the project. Currently this is only supported in APStreamline v1.0, available from the Releases section of the repository
  • Update documentation and add more detailed steps for adding a new camera
  • Update the APWeb interface to list the actual available resolutions of the camera. Currently it just shows 320x240, 640x480, 1280x720 although the actual camera resolutions may be different
  • Switch the APWeb and APStreamline IPC mechanism to using ZeroMQ or rpcgen
  • Improve the installation flow. Currently the user needs to run APStreamline from the same directory as its config files for them to be loaded properly. Maybe the configuration files should be moved to ~/.config/?
  • Improve the JavaScript in the APWeb interface
  • Document the code better!

Cycling in Philadelphia

The repetitive months of quarantine have been exhausting in every single way. One of the sources of light in this unfamiliar tunnel of social isolation has been my new bicycle, on which I have already completed over 1200km in the three odd months of owning it. Philadelphia has relatively flat elevation, good bike lane coverage, and many beautiful trails making it a great city for cycling. There are also good resources on cycling in Philadelphia that may be useful to both the beginner and professional cyclist:

These are some of my favorite spots for cycling in and around Philadelphia. All the places on the below list are easily accessible via dedicated bike lanes from University City and have no entry fees whatsoever.

Ben Franklin Bridge / Penn’s Landing

Making another appearance on my blog, the Ben Franklin Bridge

A Philadelphia landmark, the Ben Franklin bridge links the city to Camden, New Jersey. The bridge is flanked by a shared walkway/bike path on both sides, though only the right walkway is presently open. Getting to the highest point of the middle of the bridge can be a drag (and nearly impossible to do when riding a fixed-gear cycle), but it’s certainly worth it for the sea breeze and views of the Delaware river adorned by Philadelphia’s skyline in the background. One can also hear and feel the periodic vibrations of the NJ Transit train right below the walkway.

Battleship museum at Camden

The Camden Waterfront and the Rutgers Law School are the main attractions on the other side of the bridge. I also stumbled across a floating battleship museum moored on my first trip to the Waterfront.

I personally find Race Street the safest way to go to the Ben Franklin Bridge when starting from the Art Museum. The transition in scenery and smells from the Ben Franklin Parkway to Chinatown is very enjoyable. The Spruce Street corridor makes it easy to go return to University City and it has bollards lining the bike path for additional safety.

Manayunk Trail

Dirt section on the Manayunk Trail

The beginning of this trail is a stone’s throw away from the Trek Manayunk showroom, which itself is a short ride from the East Falls bridge. The initial section of the trail consists of wooden boardwalks and some light gravel, followed by miles upon miles of paved, treelined roads running parallel to the Manayunk canal. The number of walking/running pedestrians thins as one goes further down the trail. The flat surface makes it easy to cover long stretches of the trail in quick time. There are only a few greater pleasures than being able to squeeze out a consistent 30+km/hr in top gear. Though I’ve only made it as far as Bridgeport, the trail goes on till the Valley Forge National Park. A 100km and then a 100 nautical mile round-trip on the Manayunk Trail is currently at the top of my Philadelphia bucket list.

Wissahickon Valley Park

The Wissahickon welcomes one with an amazing view of the Wissahickon Creek

The Wissahickon Valley Park is a short ride away from the East Falls bridge. The park is huge and abundantly green. The first few miles of the trail are on paved roads with small hills. The remainder of the trail is covered with gravel to keep things interesting. I’ve always liked the feeling of riding on gravel since the lack of purchase on the surface forces a more attentive and focussed riding style. Wissahickon also is home to several mountain biking trails of varying levels of difficulty. I tried some of the mountain biking trails on my hybrid bike, but it soon became apparent that the lack of suspension and the (in mountain bike terms) narrow 35mm tyres made the bike ill-equipped to deal with the off-road features that a proper mountain bike would have taken in stride.

Gravel section of the Wissahickon Trail. A mountain bike would be a lot of fun!

UPenn’s Morris Arboretum is only a short ride away from the end of the Wissahickon Park. Entry is free for PennCard holders and the garden has some beautiful sights when the flowers are in season. The entire length of the round-trip when starting from Penn’s campus is about 45km to the Arboretum and back.

Martin Luther King Jr Drive / Kelly Drive

Wide roads make brisk cycling feasible

The MLK drive runs along the Schyukill river and it starts near the Philadelphia Art Museum. Normally opened to regular traffic, MLK drive has been closed to motorized vehicles since the start of the pandemic. While the MLK drive can feel crowded with the sheer number of cyclists and runners in the evening, there’s plenty of room to ride as fast or slow as you want to. The tall slope near the end of the drive leads to the Strawberry Mansion bridge, which connects to the East side of Fairmount Park.

One of my favourite places to sit down after returning from the above Trails

Kelly Drive lies on the other side of the Schyukill. The views are more scenic, but the path is also much narrower. Kelly Drive sees a lot more pedestrians, so it isn’t nearly as smooth as riding on the MLK drive.

Despite the MLK and Kelly Drive often being my first recommendation for new cyclists, I have become disenchanted with going up and down these trails after making several dozen trips to get to Wissahickon and Manayunk.

Cobbs Creek

I have been to Cobbs Creek only once but it’s interesting enough to merit a position on this list. The Creek is located in the West part of Philadelphia and extends near the south-west corner of the city. The trail goes in a loop and I liked the gentle slopes which make fast cycling a breeze. However, as the Creek is in a gritty neighborhood, I would suggest making a trip before it gets dark.

Delayed Gratification

Since my last post on COVID19, much has happened. Vaccine development is a topic which I have been following with great interest and it looks like the frontrunner vaccine candidates mentioned in my previous post are still on track for a rollout later this year. I expect we will have a better idea of how things stand after the official release of the Phase I/II data, promised by some of the vaccine biotech companies to come later this month. I will concede that this is the wrong blog for educated opinions on a vaccine, and that you should really follow this one if you’re interested in learning more. This particular post is about a different topic which has been on mind for a month.

I have experienced a curious change in my relation to work. My attention span is far less than it what it used to be and there is a considerable drop in productivity as well. It isn’t just my work which is affected, for I wasn’t even able to bring myself to type out this blog post for nearly a week after creating an empty file with the title. I have tried making progressive steps, such as cutting off the consumption of mental junk food such as social media, but it seems like idling away time on social media was only a small part of the problem.

Ben Franklin Bridge - a good place to get some thinking done

Of course, the COVID19 pandemic and heightened racial tensions in the background have been detrimental to productivity. With the amount of time devoted to being kept up to date on these pressing issues, it’s hard to mentally stay on top of things. However, I feel another possible reason for this is that it is harder to find gratification in work anymore. Although this isn’t my first remote project, the lack of human contact has made the work feel impersonal and uninspiring. In normal circumstances, a difficult technical problem is an exciting thing to work on, but now it just feels like a mental burden. I have also realized I’m much more willing to work on short term tasks with immediate goals than something which could take weeks to complete. This has made me think that the key issue could be that doing anything which involves delayed gratification is much harder to achieve in these times.

Wikipedia defines delayed gratification as:

Delayed gratification, or deferred gratification, describes the process that the subject undergoes when the subject resists the temptation of an immediate reward in preference for a later reward.

A famous experiment, usually cited in the same breath as this topic, is the Stanford Marshmallow experiment. In this experiment, young children were given the options of 1) receiving one marshmallow immediately 2) receiving two marshmallows if they waited for 15 minutes. This was a long-term study which went on to show that the children who waited longer for two marshmallows had better test scores, social competence, and self-worth as teenagers. Researchers have also found that delayed gratification is a skill well documented in several animals - from chickens to monkeys.

Delayed gratification is a concept which can be applied to work as well - you need to work hard in the moment to experience the satisfaction of seeing a successful project through. However, delayed gratification requires an assurance of stability in the future to be effective. Suppose the children in the marshmallow experiment were told that there was an equal chance of either getting two marshmallows or none at all after waiting for 15 minutes. Would any of them have chosen to wait then?

The main issue which many of us are doubtless experiencing is uncertainty, and with that, any decision making feels uneducated. It’s hard to mentally justify working on long-term problems when the near future itself looks unclear. Self-motivation can keep you going for a while, but it is a resource which needs to be topped up regularly. I can definitely see myself being more willing to take risks and go for things which are gratifying in the short-term after the end of this pandemic.

Fortunately, I’m in the position where I can choose my own hours and how much I want to work for week, so I can scale back if I don’t enjoy what I’m doing. Some other things which I have been trying out is to keep in touch with my groups of friends and cycling every day to bring some change in environment and structure in my day. Still, I am yearning for one of these days to bring some much needed gratisfaction.


The first time I heard of the coronavirus was on Jan 23 2020. A Chinese postdoc at a UPenn robotics lab I was planning to join was telling me about how a mysterious virus had been rapidly spreading through her home country. At the time, I vaguely remembered reading about a new virus originating from Wuhan, China a couple of weeks back, so I made a mental note to check if the two viruses were related after the meeting. I later learned that the coronavirus in question had originated from Wuhan. At the time, it seemed like a disease endemic to China and I put it out of mind till the end of February, when things started to get slightly more serious. Though the US only had a few cases at the time, it was quickly starting to become clear that the disease was a) no longer endemic to China and b) very contagious. I started obsessively checking coronavirus tracking web dashboards, much like how I used to check live cricket scores during the 2019 Cricket World Cup.

Two weeks later, the situation started taking a turn for the worse. We got an email from UPenn on March 12, stating that the campus would be closed for the remainder of the semester. In hindsight, this was a prescient move, though at the time it felt like an overreaction to a disease which wasn’t fully understood.

Things rapidly started spiralling out of control in front of my eyes. Day by day, the confirmed cases in the US kept mounting till it had overtaken Italy as the most infected country in less than ten days since I had received that fateful email from Penn. This was no longer something I could casually regard like cricket match scores or the weather. It had become something very real.

The last six weeks have been the hardest I have experienced in a long time. Graduate courses continued in flow, and although there were some concessions in the workload, the work that was there took much longer to finish. Motivation and productivity plummeted. It was amazing anything got done at all when you factor in the hours spent everyday checking for live updates on the virus. Cutting out my daily half-an-hour walk to campus and back was making me go stir-crazy. That said, I was seldom bored, for it’s hard to be bored when you’re stressed.

On some level, it’s hard to believe that the world is in disarray. With millions of people under lockdown, things are unusually peaceful outside. It feels like the onslaught of data about new infections has come to define the pandemic and how to react to it.

I am glad that I stumbled upon a Harvard Business Review article, That Discomfort You’re Feeling Is Grief as it helped me contextualize feeling something which I never had before. At the moment, I would say that I have reached a kind of wary acceptance with the current situation. However, I am frustrated that several opportunities (including an internship!) and plans are now shuttered because of the virus. Many decisions I made during the start of the semester were not made considering a global pandemic on the horizon. Suffice to say, most of these decisions turned out to be the wrong ones.

I have also been thinking about this virus on a more meta level. In no particular order, some of the things I have been thinking about are:

  • In the last few years, there has been an increase in awareness about the deleterious effects of social media. The post-mortem of the 2016 US presidential election and Brexit highlighted how the terabytes of personal data mined by Facebook and its cronies could be used to manipulate people. Yet, now with life virtually online all the time, we are far more dependent on (and thereby influenced by) social media than ever before. With a particularly crucial US election this year, it is troubling that we could see a repeat of what happened in 2016.
  • The American life could not be worse set up for dealing with a pandemic. In the US, excessive consumption is a way of life and freedom is an uncompromisable right. The pandemic, on the other hand, necessitates frugality and strict impositions on personal movement. It is telling how much at odds this is from typical life in the US from how confused the government’s initial response to the disease was in the beginning.
  • The speed at which awareness about COVID19 has spread is impressive. Yes, the media cherry picks reporting cases of people blatantly defying stay at home orders, but the general compliance of mask wearing and staying at home has been good. Anecdotally, I’ve noticed that mask wearing still hasn’t caught on in Philadelphia even though there are many more people outside these days.
  • The pandemic has resulted in a large drop in vehicular emissions. The air quality in Indian metropolitan areas such as Bangalore and Delhi has never been better. Will this inspire environmentally friendly policies and increased usage of public transport in the long term?
  • “Somebody is to Blame for This”. It is much more satisfying to think that this is the product of some organizational failure than just a freak accident of a nature. Who can one blame? The CCP for suppressing news about the outbreak? The US government for botching the coronavirus response in the crucial first weeks of the pandemic? The WHO for its “noble lie” of suggesting that masks were ineffective in containing transmission? It is exasperating how the issue has been fucking politicized. These failures will be case studies for future generations of what not to do during a health crisis.
  • (More optimistically) As a budding roboticist, will the pandemic kickstart innovation in automation? Could we finally be seeing robots integrated in our daily lives in the next few years?

The only thing worse than the pandemic itself would be if the world goes back to the status quo after it’s over. This is perhaps the only opportunity we will get to reflect on what really matters and how that should define policy-making decisions over the next decade.

Despite how grim things are at the moment, I remain optimistic for the next year. At least in the US, medical facilities are no longer overcrowded with patients. There are thousands of smart people researching possible treatments. Some vaccines have shown promising results in animals and some, such as the Oxford/AstraZeneca’s ChAdOx1 have even started Phase 2 trials in humans. It is expected that we will learn more about the response of the vaccine in the next few months. Until then, we will have to do something we all have become intimately familiar with doing recently, wait.

Masters vs Undergrad

Before starting my master’s degree in robotics at UPenn, I had many unanswered questions about what a master’s degree would be like. I was certain that it would be considerably more difficult than undergrad but inspite of asking many current masters’ students, I didn’t have an idea of what to expect. As with many considering a master’s degree abroad, my main concerns were not knowing how hard the coursework was going to be and adapting to the cultural differences in the US. I was also anxious about not having an exit plan figured out before starting my degree. Fortunately, each of my concerns were unfounded throughout the course of my first semester, and with this blog post, I want to share the key differences I experienced between undergraduate education in India with my first semester at UPenn.


For my first semester, I registered for the three courses - Introduction to Robotics, Computer Vision and Computational Photography, and Machine Learning. Though these courses are considered to be relatively heavy (even by UPenn’s standards), I found it hard to believe that three courses with ten hours of classes a week could be stressful, especially when we were required to handle more than double the number of courses in undergrad.

It didn’t take long to realise why though. Compared to undergrad in India, master’s coursework in the US places a heavy emphasis on homework and assignments. The weekly individual assignments for each course I had in my first semester at UPenn are comparable to the monthly “group” programming assignments we used to have in undergrad. Evaluation policies for assignments are strict and late submissions for two of my courses were penalized at a 25% deduction in the maximum score per late day.

A master’s degree will test the limits of your throughput and the rapid succession of assignment deadlines can easily lead to burnout. With the end of semester final project submissions, the last four weeks of the semester are particularly brutal for everyone. I don’t think I would’ve made it through without compromising on sleep and inadequately compensating for it with the free coffee available at the Grad Students’ Center. That said, the struggle wasn’t for nothing. I feel that the knowledge I’ve gained through this process is much more durable than the kind gained for getting through a couple of semester exams. As an aside, the three courses I took this semester were not math heavy beyond needing to know some linear alegbra properties and solving the occasional differential equation.

The grading itself is not difficult - in most courses, scoring above the median will land you an A and scoring below will give you a B. C’s and D’s are only given if you neglect to turn in multiple assignments. Since the level of competition is high, even crossing the median score can be a challenge!


The atmosphere at UPenn is more collaborative than what I had experienced before. You will frequently need to approach professors, TA’s, and other students for help. Collaboration in projects here goes beyond the division of labour of work as it even involves finding solutions to problems for which there aren’t any right answers. I also found other students to be more competitive and motivated. It’s the norm to spend several hours a day banging one’s head against figurative walls. A master’s degree is also a significant financial commitment and it also comes with the opportunity cost of working for two years. This tradeoff is a good reason to be diligent about the coursework.

The pace of instruction is faster as well and it requires much more attentiveness in class. In the first four weeks of the Machine Learning course at UPenn, I learned more than I had in the entire semester of the Machine Learning course in undergrad.

Free Time

Due to the heavy coursework, household chores (especially cooking!), and part-time TA jobs that most students end up doing, free time ends up becoming quite limited. One of my gripes so far is that I haven’t been able to explore research outside of my coursework despite the ample opportunities for the taking at UPenn’s numerous robotics labs. It is possible to manage three courses with research, but I feel taking an independent study or equivalent course is more sustainable.

Preparation Required

I think it’s a good idea to brush up on the tools you will need before starting a master’s degree in engineering. First year fundamental math courses are important. Gilbert Strang’s textbook and OCW series are good resources for linear algebra. There is a good chance that you will need to use LaTeX for homework and scientific software such as MATLAB and Python with scipy, numpy, sklearn, and pytorch among many others. Learning to use these tools effectively can save you a lot of time later. Though I feel it isn’t required to prepare beforehand, you can find most of the course material of graduate courses online if you wish to preview the course content. However, the best way to know what you’re getting into is by asking a helpful senior at the college you’re planning to attend :-)