I had this problem when ferrying my airplane after I bought it (RV9A/IO-320). Started and ran fine at its home airport. My CFI and I were trying to fly it from St. Louis to central Minnesota. We stopped for fuel at Mason City, Iowa (where the music died) and trying to take off after lunch and refueling, we had almost the exact same symptoms that you describe. Long story short, we replaced the engine-driven fuel pump and all was well. We did have to fly it 20 miles on the electric pump to Forest City where the mechanic was.
This may not be germane to your problem since I have fuel injection, but these days...when it's hot out, the engine is hot, and a long taxi, I get variable fuel pressure and the the engine runs rough. But all those issues, including the fuel pressure variability, go away when I push the throttle in for takeoff and when I'm flying. I did wrap the fuel lines and added some exhaust shielding and that improved my situation.