3

私は SVG を使用してビデオ アニメーションを生成し、一連の画像を作成してそれをビデオ ファイルに変換しています。必要な効果の 1 つは、テキストをスムーズにパン/ズームできるようにすることです。テキストを含むグラフィック コンテキストに変換を適用して、これを実行しようとしています。各フレームには、縮尺/平行移動のわずかな変化があります。この手法は、静止画像に適しています。しかし、テキスト用ではありません。私が見ているのは、あなたが期待するような滑らかな効果ではありません。フレームからフレームへのテキストの特定のぎくしゃく/きらめきがあります。これは、フォント レンダリング ルールが変換後に適用されているかのようです (変換前ではありません)。

質問: テキストでスムーズなスケール/パン効果を実現するにはどうすればよいですか?

1 フレームの例:

<svg width='320' height='180'>
<rect x='0' y='0' width='320' height='180' fill='white' />
<g transform='scale(5.999999999999893)'><text x='50' y='50'>Hello World!</text>
</g></svg>

これが私の言いたいことを示すビデオクリップです: http://www.youtube.com/watch?v=TrEjDeGlPhA&list=UUfWuDb3rpD5OInqUpNivjdA&index=1

または、ゼロから作成することもできます。これらのフレームを生成し、デモ用の AVI ファイルを作成する小さな Java プログラムを作成しました (Linux、mencoder、rsvg-convert が利用可能であると仮定します)。

import java.io.File;
import java.io.Writer;
import java.io.FileWriter;
import java.io.IOException;

public class MakeTextScaleAnimation {

public static void main (String[] arg) throws Exception {

    double s;

    int frame = 0;
    for (s=1.0; s < 8.0; s+=0.005) {
        String framePrefix = "frame" + String.format("%04d", frame);
        File frameFile = new File (framePrefix + ".svg");
        FileWriter w = new FileWriter(frameFile);
        writeFrame(w,s);
        w.close();

        frame++;

        System.out.println ("rsvg-convert " + frameFile.getName() + " > " + framePrefix + ".png");
    }
}

private static void writeFrame(Writer w, double s) throws IOException {
    w.write ("<svg width='320' height='180'>\n");
    w.write ("<rect x='0' y='0' width='320' height='180' fill='white' />\n");
    w.write ("<g transform='scale(" + s + ")'>");
    w.write ("<text x='50' y='50'>Hello World!</text>\n");
    w.write ("</g></svg>");
}
}

そして、このスクリプトを実行します:

#!/bin/bash
javac MakeTextScaleAnimation.java 

# Make SVG animation frames and generate script to convert to PNG
java MakeTextScaleAnimation  > svgtopng.sh

# Convert SVG frames into PNG images
. svgtopng.sh

# Convert the PNG images into a movie file
mencoder mf://frame*.png -mf fps=24:type=png \
-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=3200 \
-o output.avi
4

1 に答える 1