mirror of https://github.com/mpv-player/mpv
player: change video-bitrate and audio-bitrate properties
Remove the old implementation for these properties. It was never very good, often returned very innaccurate values or just 0, and was static even if the source was variable bitrate. Replace it with the implementation of "packet-video-bitrate". Mark the "packet-..." properties as deprecated. (The effective difference is different formatting, and returning the raw value in bits instead of kilobits.) Also extend the documentation a little. It appears at least some decoders (sipr?) need the AVCodecContext.bit_rate field set, so this one is still passed through.
This commit is contained in:
parent
c5654e4005
commit
c6d046414b
|
@ -1126,9 +1126,6 @@ Property list
|
|||
``audio-codec``
|
||||
Audio codec selected for decoding.
|
||||
|
||||
``audio-bitrate``
|
||||
Audio bitrate. This is probably a very bad guess in most cases.
|
||||
|
||||
``audio-samplerate``
|
||||
Audio samplerate.
|
||||
|
||||
|
@ -1225,9 +1222,6 @@ Property list
|
|||
``video-codec``
|
||||
Video codec selected for decoding.
|
||||
|
||||
``video-bitrate``
|
||||
Video bitrate (a bad guess).
|
||||
|
||||
``width``, ``height``
|
||||
Video size. This uses the size of the video as decoded, or if no video
|
||||
frame has been decoded yet, the (possibly incorrect) container indicated
|
||||
|
@ -1637,7 +1631,7 @@ Property list
|
|||
whether the video window is visible. If the ``--force-window`` option is
|
||||
used, this is usually always returns ``yes``.
|
||||
|
||||
``packet-video-bitrate``, ``packet-audio-bitrate``, ``packet-sub-bitrate``
|
||||
``video-bitrate``, ``audio-bitrate``, ``sub-bitrate``
|
||||
Bitrate values calculated on the packet level. This works by dividing the
|
||||
bit size of all packets between two keyframes by their presentation
|
||||
timestamp distance. (This uses the timestamps are stored in the file, so
|
||||
|
@ -1646,8 +1640,29 @@ Property list
|
|||
bitrate. To make the property more UI friendly, updates to these properties
|
||||
are throttled in a certain way.
|
||||
|
||||
The unit is bits per second. OSD formatting turns these values in kilobits
|
||||
(or megabits, if appropriate), which can be prevented by using the
|
||||
raw property value, e.g. with ``${=video-bitrate}``.
|
||||
|
||||
Note that the accuracy of these properties is influenced by a few factors.
|
||||
If the underlying demuxer rewrites the packets on demuxing (done for some
|
||||
file formats), the bitrate might be slightly off. If timestamps are bad
|
||||
or jittery (like in Matroska), even constant bitrate streams might show
|
||||
fluctuating bitrate.
|
||||
|
||||
How exactly these values are calculated might change in the future.
|
||||
|
||||
In earlier versions of mpv, these properties returned a static (but bad)
|
||||
guess using a completely different method.
|
||||
|
||||
``packet-video-bitrate``, ``packet-audio-bitrate``, ``packet-sub-bitrate``
|
||||
Old and deprecated properties for ``video-bitrate``, ``audio-bitrate``,
|
||||
``sub-bitrate``. They behave exactly the same, but return a value in
|
||||
kilobits. Also, they don't have any OSD formatting, though the same can be
|
||||
achieved with e.g. ``${=video-bitrate}``.
|
||||
|
||||
These properties shouldn't be used anymore.
|
||||
|
||||
``audio-device-list``
|
||||
Return the list of discovered audio devices. This is mostly for use with
|
||||
the client API, and reflects what ``--audio-device=help`` with the command
|
||||
|
|
|
@ -144,9 +144,6 @@ static int init(struct dec_audio *da, const char *decoder)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (lavc_context->bit_rate != 0)
|
||||
da->bitrate = lavc_context->bit_rate;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -545,10 +545,6 @@ static void handle_stream(demuxer_t *demuxer, int i)
|
|||
sh_video->aspect = codec->width * codec->sample_aspect_ratio.num
|
||||
/ (float)(codec->height * codec->sample_aspect_ratio.den);
|
||||
|
||||
sh_video->bitrate = codec->bit_rate;
|
||||
if (sh_video->bitrate == 0)
|
||||
sh_video->bitrate = avfc->bit_rate;
|
||||
|
||||
uint8_t *sd = av_stream_get_side_data(st, AV_PKT_DATA_DISPLAYMATRIX, NULL);
|
||||
if (sd)
|
||||
sh_video->rotate = -av_display_rotation_get((uint32_t *)sd);
|
||||
|
|
|
@ -226,7 +226,6 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check)
|
|||
sh_video->fps = opts->fps;
|
||||
sh_video->disp_w = width;
|
||||
sh_video->disp_h = height;
|
||||
sh_video->bitrate = sh_video->fps * imgsize * 8;
|
||||
|
||||
struct priv *p = talloc_ptrtype(demuxer, p);
|
||||
demuxer->priv = p;
|
||||
|
|
|
@ -82,7 +82,6 @@ typedef struct sh_video {
|
|||
bool avi_dts; // use DTS timing; first frame and DTS is 0
|
||||
float fps; // frames per second (set only if constant fps)
|
||||
float aspect; // aspect ratio stored in the file (for prescaling)
|
||||
int bitrate; // compressed bits/sec
|
||||
int bits_per_coded_sample;
|
||||
unsigned char *extradata;
|
||||
int extradata_len;
|
||||
|
|
|
@ -216,14 +216,6 @@ static void mark_seek(struct MPContext *mpctx)
|
|||
cmd->last_seek_time = now;
|
||||
}
|
||||
|
||||
static char *format_bitrate(int rate)
|
||||
{
|
||||
if (rate < 1024 * 1024)
|
||||
return talloc_asprintf(NULL, "%.3f kbps", rate / 1000.0);
|
||||
|
||||
return talloc_asprintf(NULL, "%.3f mbps", rate / 1000000.0);
|
||||
}
|
||||
|
||||
static char *format_file_size(int64_t size)
|
||||
{
|
||||
double s = size;
|
||||
|
@ -1644,20 +1636,6 @@ static int mp_property_audio_codec(void *ctx, struct m_property *prop,
|
|||
return m_property_strdup_ro(action, arg, c);
|
||||
}
|
||||
|
||||
/// Audio bitrate (RO)
|
||||
static int mp_property_audio_bitrate(void *ctx, struct m_property *prop,
|
||||
int action, void *arg)
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
if (!mpctx->d_audio)
|
||||
return M_PROPERTY_UNAVAILABLE;
|
||||
if (action == M_PROPERTY_PRINT) {
|
||||
*(char **)arg = format_bitrate(mpctx->d_audio->bitrate);
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
return m_property_int_ro(action, arg, mpctx->d_audio->bitrate);
|
||||
}
|
||||
|
||||
/// Samplerate (RO)
|
||||
static int mp_property_samplerate(void *ctx, struct m_property *prop,
|
||||
int action, void *arg)
|
||||
|
@ -2337,21 +2315,6 @@ static int mp_property_video_codec(void *ctx, struct m_property *prop,
|
|||
return m_property_strdup_ro(action, arg, c);
|
||||
}
|
||||
|
||||
|
||||
/// Video bitrate (RO)
|
||||
static int mp_property_video_bitrate(void *ctx, struct m_property *prop,
|
||||
int action, void *arg)
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
if (!mpctx->d_video)
|
||||
return M_PROPERTY_UNAVAILABLE;
|
||||
if (action == M_PROPERTY_PRINT) {
|
||||
*(char **)arg = format_bitrate(mpctx->d_video->bitrate);
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
return m_property_int_ro(action, arg, mpctx->d_video->bitrate);
|
||||
}
|
||||
|
||||
static int property_imgparams(struct mp_image_params p, int action, void *arg)
|
||||
{
|
||||
if (!p.imgfmt)
|
||||
|
@ -3030,7 +2993,8 @@ static int mp_property_packet_bitrate(void *ctx, struct m_property *prop,
|
|||
int action, void *arg)
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
int type = (intptr_t)prop->priv;
|
||||
int type = (uintptr_t)prop->priv & ~0x100;
|
||||
bool old = (uintptr_t)prop->priv & 0x100;
|
||||
|
||||
if (!mpctx->demuxer)
|
||||
return M_PROPERTY_UNAVAILABLE;
|
||||
|
@ -3039,8 +3003,23 @@ static int mp_property_packet_bitrate(void *ctx, struct m_property *prop,
|
|||
if (demux_control(mpctx->demuxer, DEMUXER_CTRL_GET_BITRATE_STATS, &r) < 1)
|
||||
return M_PROPERTY_UNAVAILABLE;
|
||||
|
||||
// r[type] is in bytes/second -> kilobits
|
||||
return m_property_int64_ro(action, arg, r[type] * 8 / 1000.0 + 0.5);
|
||||
// r[type] is in bytes/second -> bits
|
||||
double rate = r[type] * 8;
|
||||
|
||||
// Same story, but used kilobits for some reason.
|
||||
if (old)
|
||||
return m_property_int64_ro(action, arg, rate / 1000.0 + 0.5);
|
||||
|
||||
if (action == M_PROPERTY_PRINT) {
|
||||
rate /= 1000;
|
||||
if (rate < 1000) {
|
||||
*(char **)arg = talloc_asprintf(NULL, "%d kbps", (int)rate);
|
||||
} else {
|
||||
*(char **)arg = talloc_asprintf(NULL, "%.3f mbps", rate / 1000.0);
|
||||
}
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
return m_property_int64_ro(action, arg, rate);
|
||||
}
|
||||
|
||||
static int mp_property_cwd(void *ctx, struct m_property *prop,
|
||||
|
@ -3317,7 +3296,6 @@ static const struct m_property mp_properties[] = {
|
|||
{"audio-delay", mp_property_audio_delay},
|
||||
{"audio-format", mp_property_audio_format},
|
||||
{"audio-codec", mp_property_audio_codec},
|
||||
{"audio-bitrate", mp_property_audio_bitrate},
|
||||
{"audio-samplerate", mp_property_samplerate},
|
||||
{"audio-channels", mp_property_channels},
|
||||
{"aid", mp_property_audio},
|
||||
|
@ -3352,7 +3330,6 @@ static const struct m_property mp_properties[] = {
|
|||
{"video-params", mp_property_vd_imgparams},
|
||||
{"video-format", mp_property_video_format},
|
||||
{"video-codec", mp_property_video_codec},
|
||||
{"video-bitrate", mp_property_video_bitrate},
|
||||
M_PROPERTY_ALIAS("dwidth", "video-out-params/dw"),
|
||||
M_PROPERTY_ALIAS("dheight", "video-out-params/dh"),
|
||||
M_PROPERTY_ALIAS("width", "video-params/w"),
|
||||
|
@ -3399,11 +3376,15 @@ static const struct m_property mp_properties[] = {
|
|||
{"ab-loop-a", mp_property_ab_loop},
|
||||
{"ab-loop-b", mp_property_ab_loop},
|
||||
|
||||
#define PROPERTY_BITRATE(name, type) \
|
||||
{name, mp_property_packet_bitrate, (void *)(intptr_t)type}
|
||||
PROPERTY_BITRATE("packet-video-bitrate", STREAM_VIDEO),
|
||||
PROPERTY_BITRATE("packet-audio-bitrate", STREAM_AUDIO),
|
||||
PROPERTY_BITRATE("packet-sub-bitrate", STREAM_SUB),
|
||||
#define PROPERTY_BITRATE(name, old, type) \
|
||||
{name, mp_property_packet_bitrate, (void *)(uintptr_t)((type)|(old?0x100:0))}
|
||||
PROPERTY_BITRATE("packet-video-bitrate", true, STREAM_VIDEO),
|
||||
PROPERTY_BITRATE("packet-audio-bitrate", true, STREAM_AUDIO),
|
||||
PROPERTY_BITRATE("packet-sub-bitrate", true, STREAM_SUB),
|
||||
|
||||
PROPERTY_BITRATE("video-bitrate", false, STREAM_VIDEO),
|
||||
PROPERTY_BITRATE("audio-bitrate", false, STREAM_AUDIO),
|
||||
PROPERTY_BITRATE("sub-bitrate", false, STREAM_SUB),
|
||||
|
||||
#define PROPERTY_TV_COLOR(name, type) \
|
||||
{name, mp_property_tv_color, (void *)(intptr_t)type}
|
||||
|
|
|
@ -385,9 +385,7 @@ int video_reconfig_filters(struct dec_video *d_video,
|
|||
struct mp_image_params p = *params;
|
||||
struct sh_video *sh = d_video->header->video;
|
||||
|
||||
MP_VERBOSE(d_video, "VIDEO: %dx%d %5.3f fps %5.1f kbps (%4.1f kB/s)\n",
|
||||
p.w, p.h, sh->fps, sh->bitrate / 1000.0,
|
||||
sh->bitrate / 8000.0);
|
||||
MP_VERBOSE(d_video, "VIDEO: %dx%d %5.3f fps\n", p.w, p.h, sh->fps);
|
||||
|
||||
MP_VERBOSE(d_video, "VDec: vo config request - %d x %d (%s)\n",
|
||||
p.w, p.h, vo_format_name(p.imgfmt));
|
||||
|
|
|
@ -71,7 +71,6 @@ struct dec_video {
|
|||
// Final PTS of previously decoded image
|
||||
double decoded_pts;
|
||||
|
||||
int bitrate; // compressed bits/sec
|
||||
float fps; // FPS from demuxer or from user override
|
||||
float initial_decoder_aspect;
|
||||
|
||||
|
|
|
@ -328,9 +328,6 @@ static int init(struct dec_video *vd, const char *decoder)
|
|||
}
|
||||
}
|
||||
|
||||
if (ctx->avctx->bit_rate != 0)
|
||||
vd->bitrate = ctx->avctx->bit_rate;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -362,7 +359,6 @@ static void init_avctx(struct dec_video *vd, const char *decoder,
|
|||
AVCodecContext *avctx = ctx->avctx;
|
||||
if (!ctx->avctx)
|
||||
goto error;
|
||||
avctx->bit_rate = 0;
|
||||
avctx->opaque = vd;
|
||||
avctx->codec_type = AVMEDIA_TYPE_VIDEO;
|
||||
avctx->codec_id = lavc_codec->id;
|
||||
|
|
Loading…
Reference in New Issue