update videoencoder, add scale option, remove motion-blur hack
Change-Id: Ib80852d20384688a161b0f63593debbd7cdb3b42
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/241760
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
diff --git a/experimental/ffmpeg/SkVideoEncoder.cpp b/experimental/ffmpeg/SkVideoEncoder.cpp
index 7a50ffa..84c465b 100644
--- a/experimental/ffmpeg/SkVideoEncoder.cpp
+++ b/experimental/ffmpeg/SkVideoEncoder.cpp
@@ -30,7 +30,7 @@
size_t len = fStorage.size();
SkASSERT(fPos <= len);
- size_t overwrite = std::min(len - fPos, bytes);
+ size_t overwrite = SkTMin(len - fPos, bytes);
if (overwrite) {
SkDebugf("overwrite %zu bytes at %zu offset with %zu remaining\n", overwrite, fPos, bytes - overwrite);
memcpy(&fStorage[fPos], src, overwrite);
diff --git a/tools/skottie2movie.cpp b/tools/skottie2movie.cpp
index 35c1352..049f588 100644
--- a/tools/skottie2movie.cpp
+++ b/tools/skottie2movie.cpp
@@ -21,9 +21,7 @@
static DEFINE_int_2(fps, f, 25, "fps");
static DEFINE_bool2(verbose, v, false, "verbose mode");
static DEFINE_bool2(loop, l, false, "loop mode for profiling");
-static DEFINE_double(motion_angle, 180, "motion blur angle");
-static DEFINE_double(motion_slope, 0, "motion blur slope");
-static DEFINE_int(motion_samples, 1, "motion blur samples");
+static DEFINE_int(set_dst_width, 0, "set destination width (height will be computed)");
static void produce_frame(SkSurface* surf, skottie::Animation* anim, double frame_time) {
anim->seekFrameTime(frame_time);
@@ -31,28 +29,6 @@
anim->render(surf->getCanvas());
}
-static void produce_frame(SkSurface* surf, SkSurface* tmp, skottie::Animation* anim,
- double frame_time, double frame_duration, double motion_radius,
- int motion_samples) {
- double samples_duration = frame_duration * motion_radius * 2;
- double dt = samples_duration / (motion_samples - 1);
- double t = frame_time - samples_duration / 2;
-
- SkPaint paint;
- paint.setAlphaf(1.0f / motion_samples);
- paint.setBlendMode(SkBlendMode::kPlus);
- surf->getCanvas()->clear(0);
-
- for (int i = 0; i < motion_samples; ++i) {
- if (FLAGS_verbose) {
- SkDebugf("time %g sample_time %g\n", frame_time, t);
- }
- produce_frame(tmp, anim, t);
- t += dt;
- tmp->draw(surf->getCanvas(), 0, 0, &paint);
- }
-}
-
int main(int argc, char** argv) {
CommandLineFlags::SetUsage("Converts skottie to a mp4");
CommandLineFlags::Parse(argc, argv);
@@ -62,25 +38,6 @@
return -1;
}
- if (FLAGS_motion_angle < 0 || FLAGS_motion_angle > 360) {
- SkDebugf("--motion_angle must be [0...360]\n");
- return -1;
- }
- if (FLAGS_motion_slope < -1 || FLAGS_motion_slope > 1) {
- SkDebugf("--motion_slope must be [-1...1]\n");
- return -1;
- }
- if (FLAGS_motion_samples < 1) {
- SkDebugf("--motion_samples must be >= 1\n");
- return -1;
- }
-
- // map angle=180 to radius=1/4 (of a frame duration)
- double motion_radius = FLAGS_motion_angle * 0.25 / 180.0;
- if (FLAGS_motion_samples == 1) {
- motion_radius = 0; // no blur if we're only 1 sample
- }
-
SkString assetPath;
if (FLAGS_assetPath.count() > 0) {
assetPath.set(FLAGS_assetPath[0]);
@@ -106,11 +63,17 @@
fps = 240;
}
+ float scale = 1;
+ if (FLAGS_set_dst_width > 0) {
+ scale = FLAGS_set_dst_width / (float)dim.width();
+ dim = { FLAGS_set_dst_width, SkScalarRoundToInt(scale * dim.height()) };
+ }
+
const int frames = SkScalarRoundToInt(duration * fps);
const double frame_duration = 1.0 / fps;
if (FLAGS_verbose) {
- SkDebugf("size %dx%d duration %g, fps %d, frame_duration %g\n",
+ SkDebugf("Size %dx%d duration %g, fps %d, frame_duration %g\n",
dim.width(), dim.height(), duration, fps, frame_duration);
}
@@ -127,6 +90,9 @@
if (!surf) {
surf = SkSurface::MakeRaster(encoder.preferredInfo());
tmp_surf = surf->makeSurface(surf->width(), surf->height());
+
+ surf->getCanvas()->scale(scale, scale);
+ tmp_surf->getCanvas()->scale(scale, scale);
}
for (int i = 0; i <= frames; ++i) {
@@ -138,12 +104,7 @@
double normal_time = i * 1.0 / frames;
double frame_time = normal_time * duration;
- if (motion_radius > 0) {
- produce_frame(surf.get(), tmp_surf.get(), animation.get(), frame_time, frame_duration,
- motion_radius, FLAGS_motion_samples);
- } else {
- produce_frame(surf.get(), animation.get(), frame_time);
- }
+ produce_frame(surf.get(), animation.get(), frame_time);
SkPixmap pm;
SkAssertResult(surf->peekPixels(&pm));