diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/av_log.c | 12 | ||||
-rw-r--r-- | core/encode.h | 2 | ||||
-rw-r--r-- | core/encode_lavc.c | 20 | ||||
-rw-r--r-- | core/encode_lavc.h | 1 | ||||
-rw-r--r-- | core/mp_core.h | 2 | ||||
-rw-r--r-- | core/mplayer.c | 45 |
6 files changed, 51 insertions, 31 deletions
diff --git a/core/av_log.c b/core/av_log.c index 37c308be7a..b6cae6f8f8 100644 --- a/core/av_log.c +++ b/core/av_log.c @@ -97,10 +97,15 @@ static int extract_msg_type_from_ctx(void *ptr) return MSGT_FIXME; } +#if LIBAVCODEC_VERSION_MICRO >= 100 +#define LIB_PREFIX "ffmpeg" +#else +#define LIB_PREFIX "libav" +#endif + static void mp_msg_av_log_callback(void *ptr, int level, const char *fmt, va_list vl) { - static bool print_prefix = 1; AVClass *avc = ptr ? *(AVClass **)ptr : NULL; int mp_level = av_log_level_to_mp_level(level); int type = extract_msg_type_from_ctx(ptr); @@ -108,9 +113,8 @@ static void mp_msg_av_log_callback(void *ptr, int level, const char *fmt, if (!mp_msg_test(type, mp_level)) return; - if (print_prefix && avc) - mp_msg(type, mp_level, "[%s @ %p]", avc->item_name(ptr), avc); - print_prefix = fmt[strlen(fmt) - 1] == '\n'; + mp_msg(type, mp_level, "[%s/%s] ", LIB_PREFIX, + avc ? avc->item_name(ptr) : "?"); mp_msg_va(type, mp_level, fmt, vl); } diff --git a/core/encode.h b/core/encode.h index fdeb273f34..acdb75c5a3 100644 --- a/core/encode.h +++ b/core/encode.h @@ -14,7 +14,7 @@ void encode_lavc_finish(struct encode_lavc_context *ctx); void encode_lavc_free(struct encode_lavc_context *ctx); void encode_lavc_discontinuity(struct encode_lavc_context *ctx); bool encode_lavc_showhelp(struct MPOpts *opts); -int encode_lavc_getstatus(struct encode_lavc_context *ctx, char *buf, int bufsize, float relative_position, float playback_time); +int encode_lavc_getstatus(struct encode_lavc_context *ctx, char *buf, int bufsize, float relative_position); void encode_lavc_expect_stream(struct encode_lavc_context *ctx, enum AVMediaType mt); void encode_lavc_set_video_fps(struct encode_lavc_context *ctx, float fps); bool encode_lavc_didfail(struct encode_lavc_context *ctx); // check if encoding failed diff --git a/core/encode_lavc.c b/core/encode_lavc.c index 747e3e67df..9fada7de58 100644 --- a/core/encode_lavc.c +++ b/core/encode_lavc.c @@ -739,6 +739,9 @@ int encode_lavc_write_frame(struct encode_lavc_context *ctx, AVPacket *packet) break; case AVMEDIA_TYPE_AUDIO: ctx->abytes += packet->size; + ctx->audioseconds += packet->duration + * (double)ctx->avc->streams[packet->stream_index]->time_base.num + / (double)ctx->avc->streams[packet->stream_index]->time_base.den; break; default: break; @@ -1003,7 +1006,7 @@ double encode_lavc_getoffset(struct encode_lavc_context *ctx, AVStream *stream) int encode_lavc_getstatus(struct encode_lavc_context *ctx, char *buf, int bufsize, - float relative_position, float playback_time) + float relative_position) { double now = mp_time_sec(); float minutes, megabytes, fps, x; @@ -1015,14 +1018,17 @@ int encode_lavc_getstatus(struct encode_lavc_context *ctx, minutes = (now - ctx->t0) / 60.0 * (1 - f) / f; megabytes = ctx->avc->pb ? (avio_size(ctx->avc->pb) / 1048576.0 / f) : 0; - fps = ctx->frames / ((now - ctx->t0)); - x = playback_time / ((now - ctx->t0)); + fps = ctx->frames / (now - ctx->t0); + x = ctx->audioseconds / (now - ctx->t0); if (ctx->frames) - snprintf(buf, bufsize, "{%.1f%% %.1fmin %.1ffps %.1fMB}", - relative_position * 100.0, minutes, fps, megabytes); + snprintf(buf, bufsize, "{%.1fmin %.1ffps %.1fMB}", + minutes, fps, megabytes); + else if (ctx->audioseconds) + snprintf(buf, bufsize, "{%.1fmin %.2fx %.1fMB}", + minutes, x, megabytes); else - snprintf(buf, bufsize, "{%.1f%% %.1fmin %.2fx %.1fMB}", - relative_position * 100.0, minutes, x, megabytes); + snprintf(buf, bufsize, "{%.1fmin %.1fMB}", + minutes, megabytes); buf[bufsize - 1] = 0; return 0; } diff --git a/core/encode_lavc.h b/core/encode_lavc.h index 7e53ae6a1d..f47825e1d7 100644 --- a/core/encode_lavc.h +++ b/core/encode_lavc.h @@ -63,6 +63,7 @@ struct encode_lavc_context { struct stream *twopass_bytebuffer_v; double t0; unsigned int frames; + double audioseconds; bool expect_video; bool expect_audio; diff --git a/core/mp_core.h b/core/mp_core.h index c958132700..0bd6ecda15 100644 --- a/core/mp_core.h +++ b/core/mp_core.h @@ -303,7 +303,7 @@ double get_time_length(struct MPContext *mpctx); double get_start_time(struct MPContext *mpctx); double get_current_time(struct MPContext *mpctx); int get_percent_pos(struct MPContext *mpctx); -double get_current_pos_ratio(struct MPContext *mpctx); +double get_current_pos_ratio(struct MPContext *mpctx, bool use_range); int get_current_chapter(struct MPContext *mpctx); char *chapter_display_name(struct MPContext *mpctx, int chapter); char *chapter_name(struct MPContext *mpctx, int chapter); diff --git a/core/mplayer.c b/core/mplayer.c index 6e453278f0..3cdd83021d 100644 --- a/core/mplayer.c +++ b/core/mplayer.c @@ -1165,19 +1165,10 @@ static void print_status(struct MPContext *mpctx) } #ifdef CONFIG_ENCODING - double startpos = rel_time_to_abs(mpctx, opts->play_start, 0); - double endpos = rel_time_to_abs(mpctx, opts->play_end, -1); - float position = (get_current_time(mpctx) - startpos) / - (get_time_length(mpctx) - startpos); - if (endpos != -1) - position = max(position, (get_current_time(mpctx) - startpos) - / (endpos - startpos)); - if (opts->play_frames > 0) - position = max(position, - 1.0 - mpctx->max_frames / (double) opts->play_frames); + double position = get_current_pos_ratio(mpctx, true); char lavcbuf[80]; if (encode_lavc_getstatus(mpctx->encode_lavc_ctx, lavcbuf, sizeof(lavcbuf), - position, get_current_time(mpctx) - startpos) >= 0) + position) >= 0) { // encoding stats saddf(&line, " %s", lavcbuf); @@ -1512,7 +1503,7 @@ static void add_seek_osd_messages(struct MPContext *mpctx) { if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_BAR) { set_osd_bar(mpctx, OSD_BAR_SEEK, "Position", 0, 1, - av_clipf(get_current_pos_ratio(mpctx), 0, 1)); + av_clipf(get_current_pos_ratio(mpctx, false), 0, 1)); set_osd_bar_chapters(mpctx, OSD_BAR_SEEK); } if (mpctx->add_osd_seek_info & OSD_SEEK_INFO_TEXT) { @@ -1553,7 +1544,7 @@ static void update_osd_msg(struct MPContext *mpctx) add_seek_osd_messages(mpctx); update_osd_bar(mpctx, OSD_BAR_SEEK, 0, 1, - av_clipf(get_current_pos_ratio(mpctx), 0, 1)); + av_clipf(get_current_pos_ratio(mpctx, false), 0, 1)); // Look if we have a msg mp_osd_msg_t *msg = get_osd_msg(mpctx); @@ -3092,7 +3083,7 @@ double get_start_time(struct MPContext *mpctx) } // Return playback position in 0.0-1.0 ratio, or -1 if unknown. -double get_current_pos_ratio(struct MPContext *mpctx) +double get_current_pos_ratio(struct MPContext *mpctx, bool use_range) { struct demuxer *demuxer = mpctx->demuxer; if (!demuxer) @@ -3100,6 +3091,19 @@ double get_current_pos_ratio(struct MPContext *mpctx) double ans = -1; double start = get_start_time(mpctx); double len = get_time_length(mpctx); + if (use_range) { + double startpos = rel_time_to_abs(mpctx, mpctx->opts.play_start, + MP_NOPTS_VALUE); + double endpos = get_play_end_pts(mpctx); + if (endpos == MP_NOPTS_VALUE || endpos > start + len) + endpos = start + len; + if (startpos == MP_NOPTS_VALUE || startpos < start) + startpos = start; + if (endpos < startpos) + endpos = startpos; + start = startpos; + len = endpos - startpos; + } double pos = get_current_time(mpctx); if (len > 0 && !demuxer->ts_resets_possible) { ans = av_clipf((pos - start) / len, 0, 1); @@ -3110,12 +3114,17 @@ double get_current_pos_ratio(struct MPContext *mpctx) if (len > 0) ans = av_clipf((double)(pos - demuxer->movi_start) / len, 0, 1); } + if (use_range) { + if (mpctx->opts.play_frames > 0) + ans = max(ans, 1.0 - + mpctx->max_frames / (double) mpctx->opts.play_frames); + } return ans; } int get_percent_pos(struct MPContext *mpctx) { - return av_clip(get_current_pos_ratio(mpctx) * 100, 0, 100); + return av_clip(get_current_pos_ratio(mpctx, false) * 100, 0, 100); } // -2 is no chapters, -1 is before first chapter @@ -4646,12 +4655,12 @@ static int mpv_main(int argc, char *argv[]) #endif #ifdef CONFIG_ENCODING - if (opts->encode_output.file) { + if (opts->encode_output.file && *opts->encode_output.file) { mpctx->encode_lavc_ctx = encode_lavc_init(&opts->encode_output); - if(!mpctx->encode_lavc_ctx) { + if(!mpctx->encode_lavc_ctx) { mp_msg(MSGT_VO, MSGL_INFO, "Encoding initialization failed."); exit_player(mpctx, EXIT_ERROR, 1); - } + } m_config_set_option0(mpctx->mconfig, "vo", "lavc"); m_config_set_option0(mpctx->mconfig, "ao", "lavc"); m_config_set_option0(mpctx->mconfig, "fixed-vo", "yes"); |