mirror of https://github.com/mpv-player/mpv
demux: put type2format into codec_tags with helper functions
demux_mf has a big const struct which is essentially a nice list handy list of codecs that are considered images. This is generally useful for all demuxers (demux_mkv could use this), so instead of making yet another list, lift it out and put it in a common place. Some things slightly changed so it matches the very similiar mimetype mapping struct below it. demux_mf calls a helper mapping function instead.
This commit is contained in:
parent
1ea106bac0
commit
be0a979a0b
|
@ -180,6 +180,70 @@ void mp_set_pcm_codec(struct mp_codec_params *c, bool sign, bool is_float,
|
|||
c->codec = talloc_strdup(c, codec);
|
||||
}
|
||||
|
||||
// map file extension/type to an image codec name
|
||||
static const char *const type_to_codec[][2] = {
|
||||
{ "bmp", "bmp" },
|
||||
{ "dpx", "dpx" },
|
||||
{ "j2c", "jpeg2000" },
|
||||
{ "j2k", "jpeg2000" },
|
||||
{ "jp2", "jpeg2000" },
|
||||
{ "jpc", "jpeg2000" },
|
||||
{ "jpeg", "mjpeg" },
|
||||
{ "jpg", "mjpeg" },
|
||||
{ "jps", "mjpeg" },
|
||||
{ "jls", "ljpeg" },
|
||||
{ "thm", "mjpeg" },
|
||||
{ "db", "mjpeg" },
|
||||
{ "pcd", "photocd" },
|
||||
{ "pfm", "pfm" },
|
||||
{ "phm", "phm" },
|
||||
{ "hdr", "hdr" },
|
||||
{ "pcx", "pcx" },
|
||||
{ "png", "png" },
|
||||
{ "pns", "png" },
|
||||
{ "ptx", "ptx" },
|
||||
{ "tga", "targa" },
|
||||
{ "tif", "tiff" },
|
||||
{ "tiff", "tiff" },
|
||||
{ "sgi", "sgi" },
|
||||
{ "sun", "sunrast" },
|
||||
{ "ras", "sunrast" },
|
||||
{ "rs", "sunrast" },
|
||||
{ "ra", "sunrast" },
|
||||
{ "im1", "sunrast" },
|
||||
{ "im8", "sunrast" },
|
||||
{ "im24", "sunrast" },
|
||||
{ "im32", "sunrast" },
|
||||
{ "sunras", "sunrast" },
|
||||
{ "xbm", "xbm" },
|
||||
{ "pam", "pam" },
|
||||
{ "pbm", "pbm" },
|
||||
{ "pgm", "pgm" },
|
||||
{ "pgmyuv", "pgmyuv" },
|
||||
{ "ppm", "ppm" },
|
||||
{ "pnm", "ppm" },
|
||||
{ "gif", "gif" },
|
||||
{ "pix", "brender_pix" },
|
||||
{ "exr", "exr" },
|
||||
{ "pic", "pictor" },
|
||||
{ "qoi", "qoi" },
|
||||
{ "xface", "xface" },
|
||||
{ "xwd", "xwd" },
|
||||
{ "svg", "svg" },
|
||||
{0}
|
||||
};
|
||||
|
||||
const char *mp_map_type_to_image_codec(const char *type)
|
||||
{
|
||||
if (type) {
|
||||
for (int n = 0; type_to_codec[n][0]; n++) {
|
||||
if (strcasecmp(type_to_codec[n][0], type) == 0)
|
||||
return type_to_codec[n][1];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
|
||||
static const char *const mimetype_to_codec[][2] = {
|
||||
{"image/apng", "apng"},
|
||||
{"image/avif", "av1"},
|
||||
|
|
|
@ -28,6 +28,7 @@ void mp_set_codec_from_tag(struct mp_codec_params *c);
|
|||
void mp_set_pcm_codec(struct mp_codec_params *c, bool sign, bool is_float,
|
||||
int bits, bool is_be);
|
||||
|
||||
const char *mp_map_type_to_image_codec(const char *type);
|
||||
const char *mp_map_mimetype_to_video_codec(const char *mimetype);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -284,63 +284,6 @@ static bool demux_mf_read_packet(struct demuxer *demuxer,
|
|||
return true;
|
||||
}
|
||||
|
||||
// map file extension/type to a codec name
|
||||
|
||||
static const struct {
|
||||
const char *type;
|
||||
const char *codec;
|
||||
} type2format[] = {
|
||||
{ "bmp", "bmp" },
|
||||
{ "dpx", "dpx" },
|
||||
{ "j2c", "jpeg2000" },
|
||||
{ "j2k", "jpeg2000" },
|
||||
{ "jp2", "jpeg2000" },
|
||||
{ "jpc", "jpeg2000" },
|
||||
{ "jpeg", "mjpeg" },
|
||||
{ "jpg", "mjpeg" },
|
||||
{ "jps", "mjpeg" },
|
||||
{ "jls", "ljpeg" },
|
||||
{ "thm", "mjpeg" },
|
||||
{ "db", "mjpeg" },
|
||||
{ "pcd", "photocd" },
|
||||
{ "pfm", "pfm" },
|
||||
{ "phm", "phm" },
|
||||
{ "hdr", "hdr" },
|
||||
{ "pcx", "pcx" },
|
||||
{ "png", "png" },
|
||||
{ "pns", "png" },
|
||||
{ "ptx", "ptx" },
|
||||
{ "tga", "targa" },
|
||||
{ "tif", "tiff" },
|
||||
{ "tiff", "tiff" },
|
||||
{ "sgi", "sgi" },
|
||||
{ "sun", "sunrast" },
|
||||
{ "ras", "sunrast" },
|
||||
{ "rs", "sunrast" },
|
||||
{ "ra", "sunrast" },
|
||||
{ "im1", "sunrast" },
|
||||
{ "im8", "sunrast" },
|
||||
{ "im24", "sunrast" },
|
||||
{ "im32", "sunrast" },
|
||||
{ "sunras", "sunrast" },
|
||||
{ "xbm", "xbm" },
|
||||
{ "pam", "pam" },
|
||||
{ "pbm", "pbm" },
|
||||
{ "pgm", "pgm" },
|
||||
{ "pgmyuv", "pgmyuv" },
|
||||
{ "ppm", "ppm" },
|
||||
{ "pnm", "ppm" },
|
||||
{ "gif", "gif" }, // usually handled by demux_lavf
|
||||
{ "pix", "brender_pix" },
|
||||
{ "exr", "exr" },
|
||||
{ "pic", "pictor" },
|
||||
{ "qoi", "qoi" },
|
||||
{ "xface", "xface" },
|
||||
{ "xwd", "xwd" },
|
||||
{ "svg", "svg" },
|
||||
{0}
|
||||
};
|
||||
|
||||
static const char *probe_format(mf_t *mf, char *type, enum demux_check check)
|
||||
{
|
||||
if (check > DEMUX_CHECK_REQUEST)
|
||||
|
@ -351,10 +294,9 @@ static const char *probe_format(mf_t *mf, char *type, enum demux_check check)
|
|||
if (p)
|
||||
type = p + 1;
|
||||
}
|
||||
for (int i = 0; type2format[i].type; i++) {
|
||||
if (type && strcasecmp(type, type2format[i].type) == 0)
|
||||
return type2format[i].codec;
|
||||
}
|
||||
const char *codec = mp_map_type_to_image_codec(type);
|
||||
if (codec)
|
||||
return codec;
|
||||
if (check == DEMUX_CHECK_REQUEST) {
|
||||
if (!org_type) {
|
||||
MP_ERR(mf, "file type was not set! (try --mf-type=ext)\n");
|
||||
|
|
Loading…
Reference in New Issue