Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -62,6 +62,7 @@ typedef struct FadeContext { · 61 unmodified lines | ||
| 62 | 62 | int alpha; |
| 63 | 63 | int is_planar; |
| 64 | 64 | uint64_t start_time, duration; |
| 65 | + uint64_t start_time_pts, duration_pts; | |
| 65 | 66 | enum {VF_FADE_WAITING=0, VF_FADE_FADING, VF_FADE_DONE} fade_state; |
| 66 | 67 | uint8_t color_rgba[4]; ///< fade color |
| 67 | 68 | int black_fade; ///< if color_rgba is black |
| @@ -422,6 +423,11 @@ static int config_props(AVFilterLink *inlink) · 354 unmodified lines | ||
| 422 | 423 | s->is_rgb = pixdesc->flags & AV_PIX_FMT_FLAG_RGB; |
| 423 | 424 | s->is_packed_rgb = !s->is_planar && s->is_rgb; |
| 424 | 425 | |
| 426 | + if (s->duration) | |
| 427 | + s->duration_pts = av_rescale_q(s->duration, AV_TIME_BASE_Q, inlink->time_base); | |
| 428 | + if (s->start_time) | |
| 429 | + s->start_time_pts = av_rescale_q(s->start_time, AV_TIME_BASE_Q, inlink->time_base); | |
| 430 | + | |
| 425 | 431 | /* use CCIR601/709 black level for studio-level pixel non-alpha components */ |
| 426 | 432 | s->black_level = |
| 427 | 433 | ff_fmt_is_in(inlink->format, studio_level_pix_fmts) && !s->alpha ? 16 * (1 << (s->depth - 8)): 0; |
| @@ -440,29 +446,28 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 12 unmodified lines | ||
| 440 | 446 | { |
| 441 | 447 | AVFilterContext *ctx = inlink->dst; |
| 442 | 448 | FadeContext *s = ctx->priv; |
| 443 | − double frame_timestamp = frame->pts == AV_NOPTS_VALUE ? -1 : frame->pts * av_q2d(inlink->time_base); | |
| 444 | 449 | |
| 445 | 450 | // Calculate Fade assuming this is a Fade In |
| 446 | 451 | if (s->fade_state == VF_FADE_WAITING) { |
| 447 | 452 | s->factor=0; |
| 448 | − if (frame_timestamp >= s->start_time/(double)AV_TIME_BASE | |
| 453 | + if (frame->pts >= s->start_time_pts | |
| 449 | 454 | && inlink->frame_count_out >= s->start_frame) { |
| 450 | 455 | // Time to start fading |
| 451 | 456 | s->fade_state = VF_FADE_FADING; |
| 452 | 457 | |
| 453 | 458 | // Save start time in case we are starting based on frames and fading based on time |
| 454 | − if (s->start_time == 0 && s->start_frame != 0) { | |
| 455 | − s->start_time = frame_timestamp*(double)AV_TIME_BASE; | |
| 459 | + if (s->start_time_pts == 0 && s->start_frame != 0) { | |
| 460 | + s->start_time_pts = frame->pts; | |
| 456 | 461 | } |
| 457 | 462 | |
| 458 | 463 | // Save start frame in case we are starting based on time and fading based on frames |
| 459 | − if (s->start_time != 0 && s->start_frame == 0) { | |
| 464 | + if (s->start_time_pts != 0 && s->start_frame == 0) { | |
| 460 | 465 | s->start_frame = inlink->frame_count_out; |
| 461 | 466 | } |
| 462 | 467 | } |
| 463 | 468 | } |
| 464 | 469 | if (s->fade_state == VF_FADE_FADING) { |
| 465 | − if (s->duration == 0) { | |
| 470 | + if (s->duration_pts == 0) { | |
| 466 | 471 | // Fading based on frame count |
| 467 | 472 | s->factor = (inlink->frame_count_out - s->start_frame) * s->fade_per_frame; |
| 468 | 473 | if (inlink->frame_count_out > s->start_frame + s->nb_frames) { |
| @@ -471,10 +476,8 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 2 unmodified lines | ||
| 471 | 476 | |
| 472 | 477 | } else { |
| 473 | 478 | // Fading based on duration |
| 474 | − s->factor = (frame_timestamp - s->start_time/(double)AV_TIME_BASE) | |
| 475 | − * (float) UINT16_MAX / (s->duration/(double)AV_TIME_BASE); | |
| 476 | − if (frame_timestamp > s->start_time/(double)AV_TIME_BASE | |
| 477 | − + s->duration/(double)AV_TIME_BASE) { | |
| 479 | + s->factor = (frame->pts - s->start_time_pts) * UINT16_MAX / s->duration_pts; | |
| 480 | + if (frame->pts > s->start_time_pts + s->duration_pts) { | |
| 478 | 481 | s->fade_state = VF_FADE_DONE; |
| 479 | 482 | } |
| 480 | 483 | } |