[Libav-user] Muxing settings for h264 + mp4

ALESSANDRO PAGANELLI 83670 at studenti.unimore.it
Thu Feb 23 12:37:32 CET 2012

The stream I'm using is coded with h264 without mpegts.

However, I'm following a sort of "low level" approach, since my goal is to
read frames from the file, move their content into a RTP packet and, at the
receiver side, rebuild the set of sent packets (regardless if this has an
actual sense for the file I consider).
I supposed that a simple copy of the packet's payload could be enough to
rebuild the stream at the receiver side, but I guess that I'm missing
something important.

Another weird thing: if I make a raw copy of the following AVStream's
parameters (m_copyStream is the original sender-side stream,
while outputStream is the one at the receiver side)

        outputStream->r_frame_rate = m_copyStream.r_frame_rate;
        outputStream->first_dts = m_copyStream.first_dts;
        outputStream->pts = m_copyStream.pts;
        outputStream->time_base = m_copyStream.time_base;
        outputStream->pts_wrap_bits = m_copyStream.pts_wrap_bits;
        outputStream->start_time = AV_NOPTS_VALUE;
        outputStream->sample_aspect_ratio =
        outputStream->avg_frame_rate = m_copyStream.avg_frame_rate;

which I assume should replicate the sender AVStream at the receiver, the
program stops for an arithmetic exception caused by the pts, whose
denominator is 0. However, it's not clear how the original file could play
perfectly without these information...


Il giorno 23 febbraio 2012 04:24, Kalileo <kalileo at universalx.net> ha

> On Feb 23, 2012, at 00:59 , ALESSANDRO PAGANELLI wrote:
> > I'm working on a project (which uses Libav/Ffmpeg) in which I have to
> transmit an h264 encoded file (with Mp4 file format) over a simulated
> network (I'm using network simulator 3 for this), to "emulate" a real video
> streaming.
> >
> > Now, I'm facing the problem regarding how to "rebuild" the transmitted
> file at the receiver side. More in details, this issue regards the settings
> needed to replicate the configurations for AVFormatContext, AVStream and
> AVCodecContext, starting from the same structures I have at the transmitter.
> > As for now, I just copied the content of the sender's AVCodecContext
> structure to the receiver's one, but the resulting file is broken. I
> suspect that other settings have to be replicated too, but it's not clear
> which ones are those required by h264 and Mp4.
> >
> > Is there any document/tutorial about the required settings for each
> specific codec or format?
> If your source file is mp4 and your stream is mpegts then you might need
> to add the h264_mp4toannexb filter. This filter is available as an option
> for ffmpeg and you can also use it between av_read_frame and av_write_frame.
> > More in general, do you have suggestions about how to approach this
> problem for a generic combination of codec and format? I planned to
> implement different possible combinations of them, so it would be great if
> there is a "smart" way to copy these contexts without doing it "by hand" :)
> .
> If you scan through this list you'll note a lot of questions which
> basically come back to the same problem you see here  (and yes, one of them
> I had been asking).
> As far as I understood this problem the reason is that h264 (and I think
> also aac) are packed differently depending of if they are to be saved to a
> file or if they are to be streamed. h264 frames in a mpegts stream require
> a specific header for each frame, which is this "annex B".
> This h264_mp4toannexb filter will take the required information from the
> file header and put it in the annex B frame header. This  is meant to work
> if you have a mp4 file to begin with. (There is a similar filter for aac.)
> If your source file is not in the mp4 format which this filter expects
> then you're out of luck (this is where I'm stuck too :( ). I have source
> files which are h264+aac in mpegts format, and there these filters do not
> work.
> Unfortunately there seems to be no other documentation about how to build
> a correct annex B header manually except what's in the source code (if
> there is, please point me to it!).
> _______________________________________________
> Libav-user mailing list
> Libav-user at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/libav-user


Ing. Alessandro Paganelli, Ph. D. Student, 25th Cycle

Department of Information Engineering
University of Modena and Reggio Emilia
via Vignolese 905, 41125 Modena (MO), ITALY

E-mail: alessandro.paganelli at unimore.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20120223/ac9fe14b/attachment.html>

More information about the Libav-user mailing list