【问题标题】:Convert set of images to a single video file in android将一组图像转换为android中的单个视频文件
【发布时间】:2013-01-25 12:38:30
【问题描述】:

我有一组图像,我希望通过循环运行它们,并将其保存为 sdcard 中的视频文件。 android中是否有我可以使用的默认实用程序。 ?任何可以满足我要求的库。 ?

【问题讨论】:

标签: android image video


【解决方案1】:

您需要一个库来创建这些。这里有一些关于此的帖子:

Java Package to create video

Video Creation with Xuggler

教程:

Tutorial To create Video from Xuggler

【讨论】:

    【解决方案2】:

    没有内置的Android 库支持此功能。 This SO post 建议使用通过 Java 端口用 C/C++ 编写的 ffmpeg 或使用 Android NDK

    【讨论】:

      【解决方案3】:

      在您的 android 项目中使用 Java javacpp.jarjavacv.jar 创建一系列图像到视频

      以下代码用于创建视频

      recorder = new FFmpegFrameRecorder("Videofilename", 480, 480);
      
      try {
          recorder.setVideoCodec(13);
          recorder.setFrameRate(0.4d);
          recorder.setPixelFormat(0);
          recorder.setVideoQuality(1.0d);
          recorder.setVideoBitrate(4000);
      
          startTime = System.currentTimeMillis();
          recorder.start();
      
          int time = Integer.parseInt(params[0]);
          resp = "Slept for " + time + " milliseconds";
      
          for (int i = 0; i < iplimage.length; i++) {
              long t = 1000 * (System.currentTimeMillis() - startTime);
              if (t < recorder.getTimestamp()) {
                  t = recorder.getTimestamp() + 1000;
              }
              recorder.setTimestamp(t);
              recorder.record(iplimage[i]);
          }
      } catch (Exception e) {
          e.printStackTrace();
      }
      

      【讨论】:

      • jar 文件在哪里?没有链接。
      【解决方案4】:

      用于创建逐帧动画的对象,由一系列 Drawable 对象定义,可用作 View 对象的背景。

      创建逐帧动画的最简单方法是在 XML 文件中定义动画,放置在 res/drawable/ 文件夹中,并将其设置为 View 对象的背景。然后,调用 start() 运行动画。

      在 XML 中定义的 AnimationDrawable 由单个元素和一系列嵌套标签组成。每个项目定义动画的一帧。请参阅下面的示例。

      res/drawable/文件夹中的spin_animation.xml文件:

      <!-- Animation frames are wheel0.png -- wheel5.png files inside the
       res/drawable/ folder -->
       <animation-list android:id="@+id/selected" android:oneshot="false">
          <item android:drawable="@drawable/wheel0" android:duration="50" />
          <item android:drawable="@drawable/wheel1" android:duration="50" />
          <item android:drawable="@drawable/wheel2" android:duration="50" />
          <item android:drawable="@drawable/wheel3" android:duration="50" />
          <item android:drawable="@drawable/wheel4" android:duration="50" />
          <item android:drawable="@drawable/wheel5" android:duration="50" />
       </animation-list>
      

      这是加载和播放此动画的代码。

       // Load the ImageView that will host the animation and
       // set its background to our AnimationDrawable XML resource.
       ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
       img.setBackgroundResource(R.drawable.spin_animation);
      
       // Get the background, which has been compiled to an AnimationDrawable object.
       AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
      
       // Start the animation (looped playback by default).
       frameAnimation.start();
      

      【讨论】:

      • 谢谢@Aakash,但您打算如何将其保存为视频文件?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多