[FFmpeg-devel] [PATCH] doc/examples/remuxing: switch to codecpar
wm4
nfxjfg at googlemail.com
Tue Mar 28 14:31:43 EEST 2017
On Tue, 28 Mar 2017 13:09:54 +0200
Matthieu Bouron <matthieu.bouron at gmail.com> wrote:
> On Tue, Mar 28, 2017 at 12:48 PM, wm4 <nfxjfg at googlemail.com> wrote:
>
> > On Tue, 28 Mar 2017 12:32:19 +0200
> > Matthieu Bouron <matthieu.bouron at gmail.com> wrote:
> >
> > > Also limits remuxing to audio, video and subtitle streams.
> > > ---
> > > doc/examples/remuxing.c | 48 ++++++++++++++++++++++++++++++
> > +++++++++++-------
> > > 1 file changed, 41 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/doc/examples/remuxing.c b/doc/examples/remuxing.c
> > > index 65437d9abd..8615c73842 100644
> > > --- a/doc/examples/remuxing.c
> > > +++ b/doc/examples/remuxing.c
> > > @@ -50,6 +50,9 @@ int main(int argc, char **argv)
> > > AVPacket pkt;
> > > const char *in_filename, *out_filename;
> > > int ret, i;
> > > + int stream_index = 0;
> > > + int *stream_mapping = NULL;
> > > + int stream_mapping_size = 0;
> > >
> > > if (argc < 3) {
> > > printf("usage: %s input output\n"
> > > @@ -83,25 +86,48 @@ int main(int argc, char **argv)
> > > goto end;
> > > }
> > >
> > > + stream_mapping_size = ifmt_ctx->nb_streams;
> > > + stream_mapping = av_mallocz_array(stream_mapping_size,
> > sizeof(*stream_mapping));
> > > + if (!stream_mapping) {
> > > + ret = AVERROR(ENOMEM);
> > > + goto end;
> > > + }
> > > +
> > > ofmt = ofmt_ctx->oformat;
> > >
> > > for (i = 0; i < ifmt_ctx->nb_streams; i++) {
> > > + AVStream *out_stream;
> > > AVStream *in_stream = ifmt_ctx->streams[i];
> > > - AVStream *out_stream = avformat_new_stream(ofmt_ctx,
> > in_stream->codec->codec);
> > > + AVCodecParameters *in_codecpar = in_stream->codecpar;
> > > +
> > > + if (in_codecpar->codec_type != AVMEDIA_TYPE_AUDIO &&
> > > + in_codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
> > > + in_codecpar->codec_type != AVMEDIA_TYPE_SUBTITLE) {
> > > + stream_mapping[i] = -1;
> > > + continue;
> > > + }
> > > +
> > > + stream_mapping[i] = stream_index++;
> > > +
> > > + out_stream = avformat_new_stream(ofmt_ctx, NULL);
> > > if (!out_stream) {
> > > fprintf(stderr, "Failed allocating output stream\n");
> > > ret = AVERROR_UNKNOWN;
> > > goto end;
> > > }
> > >
> > > - ret = avcodec_copy_context(out_stream->codec,
> > in_stream->codec);
> > > + ret = avcodec_parameters_copy(out_stream->codecpar,
> > in_codecpar);
> > > if (ret < 0) {
> > > - fprintf(stderr, "Failed to copy context from input to
> > output stream codec context\n");
> > > + fprintf(stderr, "Failed to copy copy codec parameters\n");
> > > + goto end;
> > > + }
> > > + out_stream->codecpar->codec_tag = 0;
> > > +
> > > + ret = avformat_transfer_internal_stream_timing_info(ofmt,
> > out_stream, in_stream, AVFMT_TBCF_AUTO);
> > > + if (ret < 0) {
> > > + fprintf(stderr, "Failed to copy stream timing info\n");
> >
> > Remove this call. It was made for obscure corner cases like ffserver,
> > and one avi thing AFAIK?
> >
> >
>
> I just ran fate with ffmpeg.c compiled without the
> avformat_transfer_internal_stream_timing_info call, and it broke in many
> areas.
That doesn't mean anything.
> On the other hand, it only seems to transfer ist->time_base to
> enc_ctx->time_base for the general case, which shouldn't be useful for
> remuxing (i can be missing things though). I removed the call locally.
That should probably be done manually then.
The main purpose of avformat_transfer_internal_stream_timing_info is to
access obscure info that can be retrieved only by accessing the
libavformat internal AVCodecContext, and to make FATE pass.
More information about the ffmpeg-devel
mailing list