Reputation: 4499
I want to re-mux a incoming h264 stream. But how could I pick the correct AVOutputFormat for the AVFormatContext?
Currently I used:
AVOutputFormat* fmt = av_guess_format(NULL, "xxx.avi", NULL);
// Open the context
//---------------------------------------------------------------------
outFormatCtx = ffmpeg::avformat_alloc_context();
//Set the output format
//----------------------------------------------------------------------
outFormatCtx->oformat = fmt;
And everything works fine. However, if I change the first line to: av_guess_format("h264",NULL, NULL); the recorded stream cannot be played because of bad header/tailer.
Is there a more smart way of picking the correct AVOutputFormat to be used?
Upvotes: 0
Views: 421
Reputation: 11184
What are you using to play it back, and what incoming stream are you remuxing? This is important, because you're trying to write a raw annexb H264 stream.
So, if you're not using a player of which you explicitly know that it supports raw annexb H264, use a different player. If you're remuxing an input of which you're not sure if it's in MP4 or annexb format, try -bsf h264_mp4toannexb.
There is also the possibility that you didn't actually want to write a raw annexb H264 stream. If all the above is cryptic to you and you're thinking I'm talking nonsense, this is probably the case. In that case, don't use "h264" as format (first argument) in your call to av_guess_format()
(since it's primarily a video codec, not a container format), but use "mp4" or "avi" or "matroska" (the container format) instead.
Upvotes: 3