0

How can i convert export and save a path animation as video /mp4 file? I use this library to create animation https://github.com/totond/TextPathView/blob/master/README-en.md . I want to record the animation without screen casting.

 <?xml version="1.0" encoding="utf-8"?>
 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TestActivity">



<yanzhikai.textpath.SyncTextPathView
    android:id="@+id/test2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    app:duration="6000"

    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/spv"
    app:paintStrokeColor="#F44336"
    app:pathStrokeColor="#F44336"
    app:showPainter="true"
    app:text="Android"
    app:textInCenter="true"
    app:textSize="75sp" />



<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:text="Start"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

activity code

class TestActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_test)

    spv.setPath(yanzhikai.textpathview.path.TestPath())
    spv.setPathPainter(FireworksPainter())
    test.setPathPainter(FireworksPainter())
    test2.setPathPainter(FireworksPainter())
    button.setOnClickListener {
        test.startAnimation(0f, 1f)
        test2.startAnimation(0f, 1f)
        spv.startAnimation(0f, 1f)

    }
}

}

path animation

Masum
  • 85
  • 3
  • 8
  • Find a way to grab each frame from the animation as Bitmap. Then you can use Android's MediaRecorder to encode the bitte asafmaps as video frames (end the encoding session after enough frames are sent, to finalise the video into a playable MP4). I think on Android the bitmaps are supposed to be in YUV colorspace to write as video (not RGB colorspace). Capture a screenshot of animation frame as RGB first then convert those numbers from RGB format to YUV format then send to encoder. – VC.One Jan 07 '21 at 01:04
  • @VC.One i search a lot but not find any way to grab each frame from animation – Masum Jan 08 '21 at 05:30
  • Try grabbing a screenshot of the animation container. https://stackoverflow.com/a/3036736/2057709. For multiple frames (_eg:_ 25 per second) try using a timer to grab each one into an array. the harder part is video encoding correctly. Practice with a 640x480 bitmap (_eg:_ filled with one colour) and see if you can make a 5 second MP4 video by code. Use a for-loop to send same bitmap for `25 x 5` times to the encoder as input frame. Some [research for encoding advice](https://www.google.com/search?safe=strict&q=android+encode+bitmap+to+video). – VC.One Jan 08 '21 at 21:44
  • PS: About grabbing each animation frame, the link in your Question gives example of seeking. I suspect it's counting in seconds not frames, but you could try change their 1000 millisec number (1 second) to become even smaller for more precision. anyways you seek, grab image, send to encoder (which is always waiting for more frames) and repeat until you have enough frames for your duration. Closing the encode session then creates the video's metadata and you can save file to disk and test in some media player. – VC.One Jan 08 '21 at 21:52
  • @VC.One perfect. thanks . its work – Masum Jan 10 '21 at 11:35

0 Answers0