views:

107

answers:

2

My C++ application receives a H.264 RTP video stream.

Right now it decodes the stream, saves it into a YUV file and later I use ffmpeg to re-ecode the file into something suitable to watch on a Windows PC (eg. Mpeg4 AVI).

Shouldn't it be possible to save the H.264 stream into a AVI (or similar) container without having to decode and re-encode it ? That would require some H.264 decoder on the PC to watch, but it should be much more efficient.

How could that be done ? Are there any libraries supporting that ?

A: 

Your program could pipe the rtp itself through ffmpeg - even invoking it using popen3().

It seems that you need to use an intermediate SDP file - I speculate that you can specify a file you created as a named pipe or with tmpfile() which your application writes to - using the file as an intermediary.

The command-line would be something like:

int p[3];
const char* const out_fmt = "avi";
const char* cmd[] = {"ffmpeg","-f",,"-i",temp_sdp_filename,"-vcodec","copy","-f",out_fmt,"-",NULL};
if(-1 == popen3(p,cmd)) ...
// write the rtp that you receive to p[STDIN_FILENO]
// read the avi from p[STDOUT_FILENO]
// read any messages and error text from p[STDERR_FILENO] 

I believe that in this circumstance ffmpeg is clever enough to repackage the container (rtp stream vs AVI) without transcoding the video and audio (this is the -vcodec copy switch); therefore, you'd have no loss of quality and it'd be blazingly fast.

Will
My ffmpeg only allows the rtp format for output, but not for input. ALso, I believe to read from stdin, ffmpeg need "-i -", not just "-".
Gene Vincent
@Gene Vincent yeah googling gives little hint
Will
A: 

using ffmpeg is correct but the answers posted so far dont look right to me.

the correct switch should be:

-vcodec copy
Joe Hopfgartner
yeah you reminded me, I've changed my -1 answer
Will