Just received my new Pioneer AVH-P4300DVD from Amazon.com, Itís a good unit although the software isnít all that great but it does want I wanted and thatís watch music videos from inside my car. Now the first thing I wanted to do was encode videos, of course being that this is proprietary firmware on the unit (non-android etc..) We all know the unit will not be forgiving of the type of media files it supports. According to Pioneer the device supports Divx so I needed to re-encode the files to Divx format. My first thought now is to head to master repository for online videos, Youtube! Now what I wanted was an easy and automated way to rip and encode videos. There are a many ways to do this but since I do most of everything on the command line, I looked for command line way to produce the files.

Youtube-dl is a great script built in python that can download from a variety of major video hosting sites, Youtube,Blip.tv,Vimeo etc.. Whatís even better is that it has support for downloading Youtube playlists. To encode on the command line you have the heavy weight programs available ffmpeg or mencoder, I chose ffmpeg since Iím less familiar with it and wanted to get my hands dirty.

Now that I have the tools I came up with the following steps

1) Create a playlist of all the videos you want on the Youtube website itself

2) Download all videos you added earlier from youtube that reside in your playlist by providing the script your youtube playlist link

youtube-dl -i -w -t "Your youtube playlist link"
youtube-dl options:
-i Dont care about dl errors just GO
-w If file already exists do not re-download (useful to only dl latest added vids)
-t Use the title to name the files, if not your filename will be the string provided by youtube ie.. rJOsjP33n34.flv
3) Encode the video to a format that the AVH-P4300DVD likes
Here I use ffmpeg to do the dirty work. I keep things simple and do 1 pass encoding without all the advanced video options that ffmpeg provides. If any ffmpeg gurus are reading and can provide some extra options to increase quality without file size too much please do, but I donít care for 2 pass encoding since Iím always in a hurry and 1 pass is fine for my needs on this small screen. Iím using FFmpeg 0.8.5 as of OCT 11 2011.

ffmpeg -y -i input_video.flv -f avi -s 480x240 -c:v mpeg4 -vtag DX50 -b:v 1000k -ar 44100 -ac 2 -bf 2 -c:a libmp3lame -b:a 192k output_video.flv.avi

ffmpeg Options:
-f avi output format
-s output resolution here we use the native format of the screen 480x240
-c:v mpeg4 video
-b:v video bitrate (higher the better it looks and larger the file )
-c:a audio is mp3 using mp3lame lib
-b:a audio bitrate
-bf 2 add bframes 
-vtag DX50 adds the fourCC divx tag so the media is defined as Divx (The Unit will not be able to read file[s] without this)
4) Now automate the process while you sleep
Youtube videos at the moment are mp4/flv/webm extensions, Bash script skips any .avi extension and files that already have been encoded, files that have been encoded will have the encoded file as JayZ-Song.mp4.avi so JayZ-Song.mp4 will be skipped also.

youtube-dl -i -w -t 'Your youtube playlist link' ; for file in * ; do [[ ${file##*.} == "avi" ]] && continue ; [[ -f ${file}.avi ]] && continue ; ffmpeg -y -i "$file" -f avi -s 480x240 -c:v mpeg4 -vtag DX50 -b:v 1000k -ar 44100 -ac 2 -bf 2 -c:a libmp3lame -b:a 192k "$file".avi
; done
5) Copy files to media of your choice sd/usb/dvd/cd and enjoy!

Note: this can be done in Windows also since Python/ffmpeg are available for windows