The Drava InterCity train route between Budapest and Sarajevo is pretty quick and comfortable, although this direct service operates only once per day in either direction. First and second class seating is available, with food availble between Budapest and Pecs.
An alternative route is also available between Zagreb and Sarajevo which may be of interest.

