core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2016-08-19 12:19:46 +00:00
|
|
|
#include <math.h>
|
2016-11-10 10:44:20 +00:00
|
|
|
#include <limits.h>
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
|
2013-02-14 13:02:47 +00:00
|
|
|
#include <libavutil/common.h>
|
2013-12-21 17:43:45 +00:00
|
|
|
#include <libavutil/log.h>
|
2014-07-29 23:15:42 +00:00
|
|
|
#include <libavutil/dict.h>
|
2014-08-02 01:12:09 +00:00
|
|
|
#include <libavutil/opt.h>
|
|
|
|
#include <libavutil/error.h>
|
2015-01-05 11:34:34 +00:00
|
|
|
#include <libavutil/cpu.h>
|
2013-06-02 23:55:48 +00:00
|
|
|
#include <libavcodec/avcodec.h>
|
2018-01-02 20:46:58 +00:00
|
|
|
#include <libavformat/avformat.h>
|
2013-02-14 13:02:47 +00:00
|
|
|
|
2016-03-31 20:00:45 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2022-06-01 20:57:56 +00:00
|
|
|
#include "audio/chmap_avchannel.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "common/msg.h"
|
2013-11-18 17:46:44 +00:00
|
|
|
#include "demux/packet.h"
|
2016-03-31 20:00:45 +00:00
|
|
|
#include "demux/stheader.h"
|
2018-01-02 20:46:58 +00:00
|
|
|
#include "misc/bstr.h"
|
2017-01-25 07:24:19 +00:00
|
|
|
#include "video/fmt-conversion.h"
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
#include "av_common.h"
|
|
|
|
#include "codecs.h"
|
|
|
|
|
2014-01-11 00:25:49 +00:00
|
|
|
int mp_lavc_set_extradata(AVCodecContext *avctx, void *ptr, int size)
|
|
|
|
{
|
|
|
|
if (size) {
|
|
|
|
av_free(avctx->extradata);
|
|
|
|
avctx->extradata_size = 0;
|
2017-02-08 14:08:49 +00:00
|
|
|
avctx->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2014-01-11 00:25:49 +00:00
|
|
|
if (!avctx->extradata)
|
|
|
|
return -1;
|
|
|
|
avctx->extradata_size = size;
|
|
|
|
memcpy(avctx->extradata, ptr, size);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
|
2017-01-25 07:24:19 +00:00
|
|
|
enum AVMediaType mp_to_av_stream_type(int type)
|
2016-03-31 20:00:45 +00:00
|
|
|
{
|
2017-01-25 07:24:19 +00:00
|
|
|
switch (type) {
|
|
|
|
case STREAM_VIDEO: return AVMEDIA_TYPE_VIDEO;
|
|
|
|
case STREAM_AUDIO: return AVMEDIA_TYPE_AUDIO;
|
|
|
|
case STREAM_SUB: return AVMEDIA_TYPE_SUBTITLE;
|
|
|
|
default: return AVMEDIA_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AVCodecParameters *mp_codec_params_to_av(struct mp_codec_params *c)
|
|
|
|
{
|
|
|
|
AVCodecParameters *avp = avcodec_parameters_alloc();
|
|
|
|
if (!avp)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
// If we have lavf demuxer params, they overwrite by definition any others.
|
|
|
|
if (c->lav_codecpar) {
|
|
|
|
if (avcodec_parameters_copy(avp, c->lav_codecpar) < 0)
|
|
|
|
goto error;
|
|
|
|
return avp;
|
|
|
|
}
|
|
|
|
|
|
|
|
avp->codec_type = mp_to_av_stream_type(c->type);
|
|
|
|
avp->codec_id = mp_codec_to_av_codec_id(c->codec);
|
|
|
|
avp->codec_tag = c->codec_tag;
|
|
|
|
if (c->extradata_size) {
|
av_common: trim FLAC extradata when copying codec params
For muxing, FFmpeg expects the FLAC extradata to be just the bare STREAMINFO,
and passing the full FLAC extradata (fLaC header and block size, with any
additional channel layout metadata) will result in malformed output, as
ffmpeg will simply prefix another fLaC header in front.
This can be considered to be a bug.
FFmpeg's own demuxers only store the STREAMINFO, hence the naivety, while
our common source of FLAC streams, the matroska demuxer, holds onto the
full extradata. It has been deemed preferable to adjust the extradata upon
muxing, instead of in the demuxer (ffmpeg's FLAC decoder knows to read
the full fLaC extradata).
This fixes muxing FLAC streams, meaning recorder.c or dump-cache.
2021-07-05 21:30:18 +00:00
|
|
|
uint8_t *extradata = c->extradata;
|
|
|
|
int size = c->extradata_size;
|
|
|
|
|
|
|
|
if (avp->codec_id == AV_CODEC_ID_FLAC) {
|
|
|
|
// ffmpeg expects FLAC extradata to be just the STREAMINFO,
|
|
|
|
// so grab only that (and assume it'll be the first block)
|
|
|
|
if (size >= 8 && !memcmp(c->extradata, "fLaC", 4)) {
|
|
|
|
extradata += 8;
|
|
|
|
size = MPMIN(34, size - 8); // FLAC_STREAMINFO_SIZE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
avp->extradata = av_mallocz(size + AV_INPUT_BUFFER_PADDING_SIZE);
|
2017-01-25 07:24:19 +00:00
|
|
|
if (!avp->extradata)
|
|
|
|
goto error;
|
av_common: trim FLAC extradata when copying codec params
For muxing, FFmpeg expects the FLAC extradata to be just the bare STREAMINFO,
and passing the full FLAC extradata (fLaC header and block size, with any
additional channel layout metadata) will result in malformed output, as
ffmpeg will simply prefix another fLaC header in front.
This can be considered to be a bug.
FFmpeg's own demuxers only store the STREAMINFO, hence the naivety, while
our common source of FLAC streams, the matroska demuxer, holds onto the
full extradata. It has been deemed preferable to adjust the extradata upon
muxing, instead of in the demuxer (ffmpeg's FLAC decoder knows to read
the full fLaC extradata).
This fixes muxing FLAC streams, meaning recorder.c or dump-cache.
2021-07-05 21:30:18 +00:00
|
|
|
avp->extradata_size = size;
|
|
|
|
memcpy(avp->extradata, extradata, size);
|
2017-01-25 07:24:19 +00:00
|
|
|
}
|
|
|
|
avp->bits_per_coded_sample = c->bits_per_coded_sample;
|
|
|
|
|
|
|
|
// Video only
|
|
|
|
avp->width = c->disp_w;
|
|
|
|
avp->height = c->disp_h;
|
|
|
|
|
|
|
|
// Audio only
|
|
|
|
avp->sample_rate = c->samplerate;
|
|
|
|
avp->bit_rate = c->bitrate;
|
|
|
|
avp->block_align = c->block_align;
|
2022-06-01 20:57:56 +00:00
|
|
|
|
|
|
|
#if !HAVE_AV_CHANNEL_LAYOUT
|
2017-01-25 07:24:19 +00:00
|
|
|
avp->channels = c->channels.num;
|
|
|
|
if (!mp_chmap_is_unknown(&c->channels))
|
|
|
|
avp->channel_layout = mp_chmap_to_lavc(&c->channels);
|
2022-06-01 20:57:56 +00:00
|
|
|
#else
|
|
|
|
mp_chmap_to_av_layout(&avp->ch_layout, &c->channels);
|
|
|
|
#endif
|
2017-01-25 07:24:19 +00:00
|
|
|
|
|
|
|
return avp;
|
|
|
|
error:
|
|
|
|
avcodec_parameters_free(&avp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set avctx codec headers for decoding. Returns <0 on failure.
|
|
|
|
int mp_set_avctx_codec_headers(AVCodecContext *avctx, struct mp_codec_params *c)
|
|
|
|
{
|
2017-01-25 07:30:14 +00:00
|
|
|
enum AVMediaType codec_type = avctx->codec_type;
|
|
|
|
enum AVCodecID codec_id = avctx->codec_id;
|
2017-01-25 07:24:19 +00:00
|
|
|
AVCodecParameters *avp = mp_codec_params_to_av(c);
|
|
|
|
if (!avp)
|
|
|
|
return -1;
|
2017-01-25 07:30:14 +00:00
|
|
|
|
2017-01-25 07:24:19 +00:00
|
|
|
int r = avcodec_parameters_to_context(avctx, avp) < 0 ? -1 : 0;
|
|
|
|
avcodec_parameters_free(&avp);
|
2017-01-25 07:30:14 +00:00
|
|
|
|
|
|
|
if (avctx->codec_type != AVMEDIA_TYPE_UNKNOWN)
|
|
|
|
avctx->codec_type = codec_type;
|
|
|
|
if (avctx->codec_id != AV_CODEC_ID_NONE)
|
|
|
|
avctx->codec_id = codec_id;
|
2017-01-25 07:24:19 +00:00
|
|
|
return r;
|
2016-03-31 20:00:45 +00:00
|
|
|
}
|
|
|
|
|
2016-08-19 12:19:46 +00:00
|
|
|
// Pick a "good" timebase, which will be used to convert double timestamps
|
|
|
|
// back to fractions for passing them through libavcodec.
|
|
|
|
AVRational mp_get_codec_timebase(struct mp_codec_params *c)
|
|
|
|
{
|
|
|
|
AVRational tb = {c->native_tb_num, c->native_tb_den};
|
|
|
|
if (tb.num < 1 || tb.den < 1) {
|
|
|
|
if (c->reliable_fps)
|
|
|
|
tb = av_inv_q(av_d2q(c->fps, 1000000));
|
|
|
|
if (tb.num < 1 || tb.den < 1)
|
|
|
|
tb = AV_TIME_BASE_Q;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the timebase is too coarse, raise its precision, or small adjustments
|
|
|
|
// to timestamps done between decoder and demuxer could be lost.
|
|
|
|
if (av_q2d(tb) > 0.001) {
|
|
|
|
AVRational r = av_div_q(tb, (AVRational){1, 1000});
|
|
|
|
tb.den *= (r.num + r.den - 1) / r.den;
|
|
|
|
}
|
|
|
|
|
2016-11-10 10:44:20 +00:00
|
|
|
av_reduce(&tb.num, &tb.den, tb.num, tb.den, INT_MAX);
|
|
|
|
|
|
|
|
if (tb.num < 1 || tb.den < 1)
|
|
|
|
tb = AV_TIME_BASE_Q;
|
2016-08-19 12:19:46 +00:00
|
|
|
|
|
|
|
return tb;
|
|
|
|
}
|
|
|
|
|
2017-01-24 07:36:40 +00:00
|
|
|
static AVRational get_def_tb(AVRational *tb)
|
|
|
|
{
|
|
|
|
return tb && tb->num > 0 && tb->den > 0 ? *tb : AV_TIME_BASE_Q;
|
|
|
|
}
|
2013-11-25 22:13:01 +00:00
|
|
|
|
av_common: add timebase parameter to mp_set_av_packet()
If the timebase is set, it's used for converting the packet timestamps.
Otherwise, the previous method of reinterpret-casting the mpv style
double timestamps to libavcodec style int64_t timestamps is used.
Also replace the kind of awkward mp_get_av_frame_pkt_ts() function by
mp_pts_from_av(), which simply converts timestamps in a way the old
function did. (Plus it takes a timebase parameter, similar to the
addition to mp_set_av_packet().)
Note that this should not change anything yet. The code in ad_lavc.c and
vd_lavc.c passes NULL for the timebase parameters. We could set
AVCodecContext.pkt_timebase and use that if we want to give libavcodec
"proper" timestamps.
This could be important for ad_lavc.c: some codecs (opus, probably mp3
and aac too) have weird requirements about doing decoding preroll on the
container level, and thus require adjusting the audio start timestamps
in some cases. libavcodec doesn't tell us how much was skipped, so we
either get shifted timestamps (by the length of the skipped data), or we
give it proper timestamps. (Note: libavcodec interprets or changes
timestamps only if pkt_timebase is set, which by default it is not.)
This would require selecting a timebase though, so I feel uncomfortable
with the idea. At least this change paves the way, and will allow some
testing.
2013-12-04 19:12:14 +00:00
|
|
|
// Convert the mpv style timestamp (seconds as double) to a libavcodec style
|
|
|
|
// timestamp (integer units in a given timebase).
|
|
|
|
int64_t mp_pts_to_av(double mp_pts, AVRational *tb)
|
2013-06-02 23:55:48 +00:00
|
|
|
{
|
2017-01-24 07:36:40 +00:00
|
|
|
AVRational b = get_def_tb(tb);
|
|
|
|
return mp_pts == MP_NOPTS_VALUE ? AV_NOPTS_VALUE : llrint(mp_pts / av_q2d(b));
|
av_common: add timebase parameter to mp_set_av_packet()
If the timebase is set, it's used for converting the packet timestamps.
Otherwise, the previous method of reinterpret-casting the mpv style
double timestamps to libavcodec style int64_t timestamps is used.
Also replace the kind of awkward mp_get_av_frame_pkt_ts() function by
mp_pts_from_av(), which simply converts timestamps in a way the old
function did. (Plus it takes a timebase parameter, similar to the
addition to mp_set_av_packet().)
Note that this should not change anything yet. The code in ad_lavc.c and
vd_lavc.c passes NULL for the timebase parameters. We could set
AVCodecContext.pkt_timebase and use that if we want to give libavcodec
"proper" timestamps.
This could be important for ad_lavc.c: some codecs (opus, probably mp3
and aac too) have weird requirements about doing decoding preroll on the
container level, and thus require adjusting the audio start timestamps
in some cases. libavcodec doesn't tell us how much was skipped, so we
either get shifted timestamps (by the length of the skipped data), or we
give it proper timestamps. (Note: libavcodec interprets or changes
timestamps only if pkt_timebase is set, which by default it is not.)
This would require selecting a timebase though, so I feel uncomfortable
with the idea. At least this change paves the way, and will allow some
testing.
2013-12-04 19:12:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Inverse of mp_pts_to_av(). (The timebases must be exactly the same.)
|
|
|
|
double mp_pts_from_av(int64_t av_pts, AVRational *tb)
|
|
|
|
{
|
2017-01-24 07:36:40 +00:00
|
|
|
AVRational b = get_def_tb(tb);
|
|
|
|
return av_pts == AV_NOPTS_VALUE ? MP_NOPTS_VALUE : av_pts * av_q2d(b);
|
av_common: add timebase parameter to mp_set_av_packet()
If the timebase is set, it's used for converting the packet timestamps.
Otherwise, the previous method of reinterpret-casting the mpv style
double timestamps to libavcodec style int64_t timestamps is used.
Also replace the kind of awkward mp_get_av_frame_pkt_ts() function by
mp_pts_from_av(), which simply converts timestamps in a way the old
function did. (Plus it takes a timebase parameter, similar to the
addition to mp_set_av_packet().)
Note that this should not change anything yet. The code in ad_lavc.c and
vd_lavc.c passes NULL for the timebase parameters. We could set
AVCodecContext.pkt_timebase and use that if we want to give libavcodec
"proper" timestamps.
This could be important for ad_lavc.c: some codecs (opus, probably mp3
and aac too) have weird requirements about doing decoding preroll on the
container level, and thus require adjusting the audio start timestamps
in some cases. libavcodec doesn't tell us how much was skipped, so we
either get shifted timestamps (by the length of the skipped data), or we
give it proper timestamps. (Note: libavcodec interprets or changes
timestamps only if pkt_timebase is set, which by default it is not.)
This would require selecting a timebase though, so I feel uncomfortable
with the idea. At least this change paves the way, and will allow some
testing.
2013-12-04 19:12:14 +00:00
|
|
|
}
|
2013-11-25 22:13:01 +00:00
|
|
|
|
av_common: add timebase parameter to mp_set_av_packet()
If the timebase is set, it's used for converting the packet timestamps.
Otherwise, the previous method of reinterpret-casting the mpv style
double timestamps to libavcodec style int64_t timestamps is used.
Also replace the kind of awkward mp_get_av_frame_pkt_ts() function by
mp_pts_from_av(), which simply converts timestamps in a way the old
function did. (Plus it takes a timebase parameter, similar to the
addition to mp_set_av_packet().)
Note that this should not change anything yet. The code in ad_lavc.c and
vd_lavc.c passes NULL for the timebase parameters. We could set
AVCodecContext.pkt_timebase and use that if we want to give libavcodec
"proper" timestamps.
This could be important for ad_lavc.c: some codecs (opus, probably mp3
and aac too) have weird requirements about doing decoding preroll on the
container level, and thus require adjusting the audio start timestamps
in some cases. libavcodec doesn't tell us how much was skipped, so we
either get shifted timestamps (by the length of the skipped data), or we
give it proper timestamps. (Note: libavcodec interprets or changes
timestamps only if pkt_timebase is set, which by default it is not.)
This would require selecting a timebase though, so I feel uncomfortable
with the idea. At least this change paves the way, and will allow some
testing.
2013-12-04 19:12:14 +00:00
|
|
|
// Set dst from mpkt. Note that dst is not refcountable.
|
|
|
|
// mpkt can be NULL to generate empty packets (used to flush delayed data).
|
|
|
|
// Sets pts/dts using mp_pts_to_av(ts, tb). (Be aware of the implications.)
|
|
|
|
// Set duration field only if tb is set.
|
|
|
|
void mp_set_av_packet(AVPacket *dst, struct demux_packet *mpkt, AVRational *tb)
|
|
|
|
{
|
ffmpeg: update to handle deprecation of `av_init_packet`
This has been a long standing annoyance - ffmpeg is removing
sizeof(AVPacket) from the API which means you cannot stack-allocate
AVPacket anymore. However, that is something we take advantage of
because we use short-lived AVPackets to bridge from native mpv packets
in our main decoding paths.
We don't think that switching these to `av_packet_alloc` is desirable,
given the cost of heap allocation, so this change takes a different
approach - allocating a single packet in the relevant context and
reusing it over and over.
That's fairly straight-forward, with the main caveat being that
re-initialising the packet is unintuitive. There is no function that
does exactly what we need (what `av_init_packet` did). The closest is
`av_packet_unref`, which additionally frees buffers and side-data.
However, we don't copy those things - we just assign them in from our
own packet, so we have to explicitly clear the pointers before calling
`av_packet_unref`. But at least we can make a wrapper function for
that.
The weirdest part of the change is the handling of the vtt subtitle
conversion. This requires two packets, so I had to pre-allocate two in
the context struct. That sounds excessive, but if allocating the
primary packet is too expensive, then allocating the secondary one for
vtt subtitles must also be too expensive.
This change is not conditional as heap allocated AVPackets were
available for years and years before the deprecation.
2022-11-29 19:15:16 +00:00
|
|
|
dst->side_data = NULL;
|
|
|
|
dst->side_data_elems = 0;
|
|
|
|
dst->buf = NULL;
|
|
|
|
av_packet_unref(dst);
|
|
|
|
|
2013-06-02 23:55:48 +00:00
|
|
|
dst->data = mpkt ? mpkt->buffer : NULL;
|
|
|
|
dst->size = mpkt ? mpkt->len : 0;
|
|
|
|
/* Some codecs (ZeroCodec, some cases of PNG) may want keyframe info
|
|
|
|
* from demuxer. */
|
|
|
|
if (mpkt && mpkt->keyframe)
|
|
|
|
dst->flags |= AV_PKT_FLAG_KEY;
|
|
|
|
if (mpkt && mpkt->avpacket) {
|
|
|
|
dst->side_data = mpkt->avpacket->side_data;
|
|
|
|
dst->side_data_elems = mpkt->avpacket->side_data_elems;
|
2014-08-24 15:45:28 +00:00
|
|
|
if (dst->data == mpkt->avpacket->data)
|
|
|
|
dst->buf = mpkt->avpacket->buf;
|
2016-10-18 14:56:50 +00:00
|
|
|
dst->flags |= mpkt->avpacket->flags;
|
2013-06-02 23:55:48 +00:00
|
|
|
}
|
av_common: add timebase parameter to mp_set_av_packet()
If the timebase is set, it's used for converting the packet timestamps.
Otherwise, the previous method of reinterpret-casting the mpv style
double timestamps to libavcodec style int64_t timestamps is used.
Also replace the kind of awkward mp_get_av_frame_pkt_ts() function by
mp_pts_from_av(), which simply converts timestamps in a way the old
function did. (Plus it takes a timebase parameter, similar to the
addition to mp_set_av_packet().)
Note that this should not change anything yet. The code in ad_lavc.c and
vd_lavc.c passes NULL for the timebase parameters. We could set
AVCodecContext.pkt_timebase and use that if we want to give libavcodec
"proper" timestamps.
This could be important for ad_lavc.c: some codecs (opus, probably mp3
and aac too) have weird requirements about doing decoding preroll on the
container level, and thus require adjusting the audio start timestamps
in some cases. libavcodec doesn't tell us how much was skipped, so we
either get shifted timestamps (by the length of the skipped data), or we
give it proper timestamps. (Note: libavcodec interprets or changes
timestamps only if pkt_timebase is set, which by default it is not.)
This would require selecting a timebase though, so I feel uncomfortable
with the idea. At least this change paves the way, and will allow some
testing.
2013-12-04 19:12:14 +00:00
|
|
|
if (mpkt && tb && tb->num > 0 && tb->den > 0)
|
|
|
|
dst->duration = mpkt->duration / av_q2d(*tb);
|
|
|
|
dst->pts = mp_pts_to_av(mpkt ? mpkt->pts : MP_NOPTS_VALUE, tb);
|
|
|
|
dst->dts = mp_pts_to_av(mpkt ? mpkt->dts : MP_NOPTS_VALUE, tb);
|
2013-06-02 23:55:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-05 11:17:55 +00:00
|
|
|
void mp_set_avcodec_threads(struct mp_log *l, AVCodecContext *avctx, int threads)
|
2013-12-04 19:58:19 +00:00
|
|
|
{
|
|
|
|
if (threads == 0) {
|
2015-01-05 11:34:34 +00:00
|
|
|
threads = av_cpu_count();
|
2013-12-04 19:58:19 +00:00
|
|
|
if (threads < 1) {
|
2015-01-05 11:17:55 +00:00
|
|
|
mp_warn(l, "Could not determine thread count to use, defaulting to 1.\n");
|
2013-12-04 19:58:19 +00:00
|
|
|
threads = 1;
|
2015-01-05 11:17:55 +00:00
|
|
|
} else {
|
|
|
|
mp_verbose(l, "Detected %d logical cores.\n", threads);
|
2015-03-05 11:55:36 +00:00
|
|
|
if (threads > 1)
|
|
|
|
threads += 1; // extra thread for better load balancing
|
2013-12-04 19:58:19 +00:00
|
|
|
}
|
|
|
|
// Apparently some libavcodec versions have or had trouble with more
|
|
|
|
// than 16 threads, and/or print a warning when using > 16.
|
|
|
|
threads = MPMIN(threads, 16);
|
|
|
|
}
|
2015-01-05 11:17:55 +00:00
|
|
|
mp_verbose(l, "Requesting %d threads for decoding.\n", threads);
|
2013-12-04 19:58:19 +00:00
|
|
|
avctx->thread_count = threads;
|
|
|
|
}
|
|
|
|
|
2018-02-12 18:28:30 +00:00
|
|
|
static void add_codecs(struct mp_decoder_list *list, enum AVMediaType type,
|
|
|
|
bool decoders)
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
{
|
2018-02-12 18:28:30 +00:00
|
|
|
void *iter = NULL;
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
for (;;) {
|
2018-04-03 16:06:23 +00:00
|
|
|
const AVCodec *cur = av_codec_iterate(&iter);
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
if (!cur)
|
|
|
|
break;
|
2018-02-12 18:28:30 +00:00
|
|
|
if (av_codec_is_decoder(cur) == decoders &&
|
|
|
|
(type == AVMEDIA_TYPE_UNKNOWN || cur->type == type))
|
|
|
|
{
|
2018-01-31 03:21:02 +00:00
|
|
|
mp_add_decoder(list, mp_codec_from_av_codec_id(cur->id),
|
2013-04-04 12:11:07 +00:00
|
|
|
cur->name, cur->long_name);
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-12 18:28:30 +00:00
|
|
|
void mp_add_lavc_decoders(struct mp_decoder_list *list, enum AVMediaType type)
|
|
|
|
{
|
|
|
|
add_codecs(list, type, true);
|
|
|
|
}
|
|
|
|
|
2016-03-01 20:46:49 +00:00
|
|
|
// (Abuses the decoder list data structures.)
|
|
|
|
void mp_add_lavc_encoders(struct mp_decoder_list *list)
|
|
|
|
{
|
2018-02-12 18:28:30 +00:00
|
|
|
add_codecs(list, AVMEDIA_TYPE_UNKNOWN, false);
|
2016-03-01 20:46:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-02 20:46:58 +00:00
|
|
|
char **mp_get_lavf_demuxers(void)
|
|
|
|
{
|
|
|
|
char **list = NULL;
|
2018-02-12 18:28:30 +00:00
|
|
|
void *iter = NULL;
|
2018-01-02 20:46:58 +00:00
|
|
|
int num = 0;
|
|
|
|
for (;;) {
|
2018-04-03 16:06:23 +00:00
|
|
|
const AVInputFormat *cur = av_demuxer_iterate(&iter);
|
2018-01-02 20:46:58 +00:00
|
|
|
if (!cur)
|
|
|
|
break;
|
|
|
|
MP_TARRAY_APPEND(NULL, list, num, talloc_strdup(NULL, cur->name));
|
|
|
|
}
|
|
|
|
MP_TARRAY_APPEND(NULL, list, num, NULL);
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
int mp_codec_to_av_codec_id(const char *codec)
|
|
|
|
{
|
2013-03-09 07:49:56 +00:00
|
|
|
int id = AV_CODEC_ID_NONE;
|
2013-04-15 19:22:58 +00:00
|
|
|
if (codec) {
|
|
|
|
const AVCodecDescriptor *desc = avcodec_descriptor_get_by_name(codec);
|
|
|
|
if (desc)
|
|
|
|
id = desc->id;
|
|
|
|
if (id == AV_CODEC_ID_NONE) {
|
2021-05-01 19:53:56 +00:00
|
|
|
const AVCodec *avcodec = avcodec_find_decoder_by_name(codec);
|
2013-04-15 19:22:58 +00:00
|
|
|
if (avcodec)
|
|
|
|
id = avcodec->id;
|
|
|
|
}
|
2013-03-07 22:37:06 +00:00
|
|
|
}
|
|
|
|
return id;
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *mp_codec_from_av_codec_id(int codec_id)
|
|
|
|
{
|
2013-03-07 22:37:06 +00:00
|
|
|
const char *name = NULL;
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
|
2013-03-07 22:37:06 +00:00
|
|
|
if (desc)
|
|
|
|
name = desc->name;
|
|
|
|
if (!name) {
|
2021-05-01 19:53:56 +00:00
|
|
|
const AVCodec *avcodec = avcodec_find_decoder(codec_id);
|
2013-03-07 22:37:06 +00:00
|
|
|
if (avcodec)
|
|
|
|
name = avcodec->name;
|
|
|
|
}
|
|
|
|
return name;
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
}
|
2014-07-29 23:15:42 +00:00
|
|
|
|
2019-05-24 18:12:26 +00:00
|
|
|
bool mp_codec_is_lossless(const char *codec)
|
|
|
|
{
|
|
|
|
const AVCodecDescriptor *desc =
|
|
|
|
avcodec_descriptor_get(mp_codec_to_av_codec_id(codec));
|
|
|
|
return desc && (desc->props & AV_CODEC_PROP_LOSSLESS);
|
|
|
|
}
|
|
|
|
|
2014-07-29 23:15:42 +00:00
|
|
|
// kv is in the format as by OPT_KEYVALUELIST(): kv[0]=key0, kv[1]=val0, ...
|
|
|
|
// Copy them to the dict.
|
|
|
|
void mp_set_avdict(AVDictionary **dict, char **kv)
|
|
|
|
{
|
|
|
|
for (int n = 0; kv && kv[n * 2]; n++)
|
|
|
|
av_dict_set(dict, kv[n * 2 + 0], kv[n * 2 + 1], 0);
|
|
|
|
}
|
2014-08-02 01:12:09 +00:00
|
|
|
|
|
|
|
// For use with libav* APIs that take AVDictionaries of options.
|
|
|
|
// Print options remaining in the dict as unset.
|
|
|
|
void mp_avdict_print_unset(struct mp_log *log, int msgl, AVDictionary *dict)
|
|
|
|
{
|
|
|
|
AVDictionaryEntry *t = NULL;
|
|
|
|
while ((t = av_dict_get(dict, "", t, AV_DICT_IGNORE_SUFFIX)))
|
|
|
|
mp_msg(log, msgl, "Could not set AVOption %s='%s'\n", t->key, t->value);
|
|
|
|
}
|
|
|
|
|
2017-04-03 16:04:18 +00:00
|
|
|
// If the name starts with "@", try to interpret it as a number, and set *name
|
|
|
|
// to the name of the n-th parameter.
|
|
|
|
static void resolve_positional_arg(void *avobj, char **name)
|
|
|
|
{
|
2018-04-27 13:55:53 +00:00
|
|
|
if (!*name || (*name)[0] != '@' || !avobj)
|
2017-04-03 16:04:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
char *end = NULL;
|
|
|
|
int pos = strtol(*name + 1, &end, 10);
|
|
|
|
if (!end || *end)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const AVOption *opt = NULL;
|
|
|
|
int offset = -1;
|
|
|
|
while (1) {
|
|
|
|
opt = av_opt_next(avobj, opt);
|
|
|
|
if (!opt)
|
|
|
|
return;
|
|
|
|
// This is what libavfilter's parser does to skip aliases.
|
|
|
|
if (opt->offset != offset && opt->type != AV_OPT_TYPE_CONST)
|
|
|
|
pos--;
|
|
|
|
if (pos < 0) {
|
|
|
|
*name = (char *)opt->name;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
offset = opt->offset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-02 01:12:09 +00:00
|
|
|
// kv is in the format as by OPT_KEYVALUELIST(): kv[0]=key0, kv[1]=val0, ...
|
|
|
|
// Set these options on given avobj (using av_opt_set..., meaning avobj must
|
|
|
|
// point to a struct that has AVClass as first member).
|
|
|
|
// Options which fail to set (error or not found) are printed to log.
|
|
|
|
// Returns: >=0 success, <0 failed to set an option
|
|
|
|
int mp_set_avopts(struct mp_log *log, void *avobj, char **kv)
|
2018-04-27 13:55:53 +00:00
|
|
|
{
|
|
|
|
return mp_set_avopts_pos(log, avobj, avobj, kv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Like mp_set_avopts(), but the posargs argument is used to resolve positional
|
|
|
|
// arguments. If posargs==NULL, positional args are disabled.
|
|
|
|
int mp_set_avopts_pos(struct mp_log *log, void *avobj, void *posargs, char **kv)
|
2014-08-02 01:12:09 +00:00
|
|
|
{
|
|
|
|
int success = 0;
|
|
|
|
for (int n = 0; kv && kv[n * 2]; n++) {
|
|
|
|
char *k = kv[n * 2 + 0];
|
|
|
|
char *v = kv[n * 2 + 1];
|
2018-04-27 13:55:53 +00:00
|
|
|
resolve_positional_arg(posargs, &k);
|
2014-08-02 01:12:09 +00:00
|
|
|
int r = av_opt_set(avobj, k, v, AV_OPT_SEARCH_CHILDREN);
|
|
|
|
if (r == AVERROR_OPTION_NOT_FOUND) {
|
|
|
|
mp_err(log, "AVOption '%s' not found.\n", k);
|
|
|
|
success = -1;
|
|
|
|
} else if (r < 0) {
|
|
|
|
char errstr[80];
|
|
|
|
av_strerror(r, errstr, sizeof(errstr));
|
|
|
|
mp_err(log, "Could not set AVOption %s='%s' (%s)\n", k, v, errstr);
|
|
|
|
success = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return success;
|
|
|
|
}
|
ffmpeg: update to handle deprecation of `av_init_packet`
This has been a long standing annoyance - ffmpeg is removing
sizeof(AVPacket) from the API which means you cannot stack-allocate
AVPacket anymore. However, that is something we take advantage of
because we use short-lived AVPackets to bridge from native mpv packets
in our main decoding paths.
We don't think that switching these to `av_packet_alloc` is desirable,
given the cost of heap allocation, so this change takes a different
approach - allocating a single packet in the relevant context and
reusing it over and over.
That's fairly straight-forward, with the main caveat being that
re-initialising the packet is unintuitive. There is no function that
does exactly what we need (what `av_init_packet` did). The closest is
`av_packet_unref`, which additionally frees buffers and side-data.
However, we don't copy those things - we just assign them in from our
own packet, so we have to explicitly clear the pointers before calling
`av_packet_unref`. But at least we can make a wrapper function for
that.
The weirdest part of the change is the handling of the vtt subtitle
conversion. This requires two packets, so I had to pre-allocate two in
the context struct. That sounds excessive, but if allocating the
primary packet is too expensive, then allocating the secondary one for
vtt subtitles must also be too expensive.
This change is not conditional as heap allocated AVPackets were
available for years and years before the deprecation.
2022-11-29 19:15:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must be used to free an AVPacket that was used with mp_set_av_packet().
|
|
|
|
*
|
|
|
|
* We have a particular pattern where we "borrow" buffers and set them
|
|
|
|
* into an AVPacket to pass data to ffmpeg without extra copies.
|
|
|
|
* This applies to buf and side_data, so this function clears them before
|
|
|
|
* freeing.
|
|
|
|
*/
|
|
|
|
void mp_free_av_packet(AVPacket **pkt)
|
|
|
|
{
|
|
|
|
if (*pkt) {
|
|
|
|
(*pkt)->side_data = NULL;
|
|
|
|
(*pkt)->side_data_elems = 0;
|
|
|
|
(*pkt)->buf = NULL;
|
|
|
|
}
|
|
|
|
av_packet_free(pkt);
|
|
|
|
}
|