I\'m trying to copy all streams from several files into one file without transcoding streams. Something you usually do with ffmpeg
utility by ffmpeg -i “f
The reason is because you didn't set the encoder's codec_tag
correctly.
You should set the correct codec_tag
, or set the codec_tag
to 0 and leave the muxer to handle for you.
Following is a sample code how to do.
AVFormatContext *ofmt_ctx; // todo
AVCodec *oc; // todo
AVStream *stream = avformat_new_stream(ofmt_ctx, oc);
if (stream != NULL) {
// ...
unsigned int tag = 0;
// for ffmpeg new api 3.x
AVCodecParameters *parameters = stream->codecpar;
if (av_codec_get_tag2(ofmt_ctx->oformat->codec_tag, oc->id, &tag) == 0) {
av_log(NULL, AV_LOG_ERROR, "could not find codec tag for codec id %d, default to 0.\n", oc->id);
}
parameters->codec_tag = tag;
stream->codec = avcodec_alloc_context3(oc);
// more setting for stream->codec
avcodec_parameters_to_context(stream->codec, parameters);
// for old ffmpeg version
stream->codec->codec_tag = tag;
// ...
}