Android'de resimlerin nasıl birleştirileceğini ve bir mp4 dosyası oluşturup video dosyasını sdCard'da sakladığını söyleyen var mı? peşin TeşekkürResimler nasıl birleştirilir ve bir mp4 dosyası oluşturulur?
cevap
FfmpegController.java
public class FfmpegController {
private static Context mContext;
private static Utility mUtility;
private static String mFfmpegBinaryPath;
public FfmpegController(Context context) {
mContext = context;
mUtility = new Utility(context);
initFfmpeg();
}
private void initFfmpeg()
{
/*
Save the ffmpeg binary to app internal storage, so we can use it by executing java runtime command.
*/
mFfmpegBinaryPath = mContext.getApplicationContext().getFilesDir().getAbsolutePath() + "/ffmpeg";
if (Utility.isFileExsisted(mFfmpegBinaryPath))
return;
InputStream inputStream = mContext.getResources().openRawResource(R.raw.ffmpeg);
mUtility.saveFileToAppInternalStorage(inputStream, "ffmpeg");
Utility.excuteCommand(CommandHelper.commandChangeFilePermissionForExecuting(mFfmpegBinaryPath));
}
public void convertImageToVideo(String inputImgPath)
{
/*
Delete previous video.
*/
Log.e("Image Parth", "inputImgPath - "+inputImgPath);
if (Utility.isFileExsisted(pathOuputVideo()))
Utility.deleteFileAtPath(pathOuputVideo());
/*
Save the command into a shell script.
*/
saveShellCommandImg2VideoToAppDir(inputImgPath);
Utility.excuteCommand("sh" + " " + pathShellScriptImg2Video());
}
public String pathOuputVideo()
{
return mUtility.getPathOfAppInternalStorage() + "/out.mp4";
}
private String pathShellScriptImg2Video()
{
return mUtility.getPathOfAppInternalStorage() + "/img2video.sh";
}
private void saveShellCommandImg2VideoToAppDir(String inputImgPath)
{
String command = CommandHelper.commandConvertImgToVideo(mFfmpegBinaryPath, inputImgPath, pathOuputVideo());
InputStream is = new ByteArrayInputStream(command.getBytes());
mUtility.saveFileToAppInternalStorage(is, "img2video.sh");
}
}
başka Java dosyasını Utility.java
public class Utility {
private final static String TAG = Utility.class.getName();
private static Context mContext;
public Utility(Context context) {
mContext = context;
}
public static String excuteCommand(String command)
{
try {
Log.d(TAG, "execute command : " + command);
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
process.waitFor();
Log.d(TAG, "command result: " + output.toString());
return output.toString();
} catch (IOException e) {
Log.e(TAG, e.getMessage(), e);
} catch (InterruptedException e) {
Log.e(TAG, e.getMessage(), e);
}
return "";
}
public String getPathOfAppInternalStorage()
{
return mContext.getApplicationContext().getFilesDir().getAbsolutePath();
}
public void saveFileToAppInternalStorage(InputStream inputStream, String fileName)
{
File file = new File(getPathOfAppInternalStorage() + "/" + fileName);
if (file.exists())
{
Log.d(TAG, "SaveRawToAppDir Delete Exsisted File");
file.delete();
}
FileOutputStream outputStream;
try {
outputStream = mContext.openFileOutput(fileName, Context.MODE_PRIVATE);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) > 0)
{
outputStream.write(buffer, 0, length);
}
outputStream.close();
inputStream.close();
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
public static boolean isFileExsisted(String filePath)
{
File file = new File(filePath);
return file.exists();
}
public static void deleteFileAtPath(String filePath)
{
File file = new File(filePath);
file.delete();
}
}
başka Yap olun bir dosya aşağıdaki kodu
kontrol edin dosya Komut
public class CommandHelper {
public static String commandConvertImgToVideo(String ffmpegBinaryPath, String inputImgPath, String outputVideoPath) {
Log.e("ffmpegBinaryPath", "ffmpegBinaryPath - "+ffmpegBinaryPath);
Log.e("inputImgPath", "inputImgPath - "+inputImgPath);
Log.e("outputVideoPath", "outputVideoPath - "+outputVideoPath);
return ffmpegBinaryPath + " -r 1/1 -i " + inputImgPath + " -c:v libx264 -crf 23 -pix_fmt yuv420p -s 640x480 " + outputVideoPath;
}
public static String commandChangeFilePermissionForExecuting(String filePath) {
return "chmod 777 " + filePath;
}
}
Eğer kodu çalıştırmak ve kod aşağıda kullanın lütfen videoya görüntüleri yapmak istiyorum elper.java.
AsyncTask asyncTask = new AsyncTask() {
ProgressDialog mProgressDialog;
@Override
protected void onPreExecute() {
/* mProgressDialog = new ProgressDialog(activity.this);
mProgressDialog.setMessage("Converting...");
mProgressDialog.setCancelable(false);
mProgressDialog.show();*/
Log.e("Video Process Start", "======================== Video Process Start ======================================");
}
@Override
protected Object doInBackground(Object... params) {
saveInputImgToAppInternalStorage();
/* for(int i = 1; i<11 ; i++){
mFfmpegController.convertImageToVideo(mUtility.getPathOfAppInternalStorage() + "/" + "Img"+i+".jpg");
}
*/
mFfmpegController.convertImageToVideo(mUtility.getPathOfAppInternalStorage() + "/" + "img%05d.jpg");
return null;
}
@Override
protected void onPostExecute(Object o) {
// mProgressDialog.dismiss();
Log.e("Video Process Complete", "======================== Video Process Complete ======================================");
Log.e("Video Path", "Path - "+mFfmpegController.pathOuputVideo());
Toast.makeText(activity.this, "Video Process Complete", Toast.LENGTH_LONG).show();
stopSelfResult(lateststartid);
Common.ScreenshotCounter = 0;
Common.ScreenshotTimerCounter = 0;
/*try {
copyFile(new FileInputStream(mFfmpegController.pathOuputVideo()), new FileOutputStream(Common.strPathForVideos));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
}
};
unutmayın:
görüntüleri gibi formatında olmalıdır Yakalanan
: .......Img00001, Img00002
FFMPEG kod beklediği için bu şekilde.
'R.raw.ffmpeg'de' ffmpeg' nedir? – Kuls
Eğer onlar görüntülerden film (JPEG resim) oluşturmak söz bu kütüphanede bu Libray'deki
https://github.com/sannies/mp4parser
deneyebilirsiniz.
Bu kitaplıklar, görüntüleri SSS’indeki videolarda birleştiremeyeceğinden bahsetmektedir. – Oximer
INDE, FFMPEG ve INDE videoları ve görüntüleri katılmak için pek çok özelliğe sahiptir vb
gibi videoları düzenlemek için araçlar yer var.
sonra this link
Diğer yararlı bağlantıları bu aracın entegrasyonu için adımları sağlar FFMPEG kullanmaya karar verirseniz:
FFMPEG:Multiple Image frames + 1 Audio =1 Video
Android make animated video from list of images
Android ffmpeg: create video from sequnce of images using jni
Combine an image into audio file and make a video file in android programmatically
Video creation from series of images?
How to Build Android Applications Based on FFmpeg by An Example
- 1. İki .apk dosyası nasıl birleştirilir ve bir .apk dosyası oluşturulur?
- 2. Android'de ses dosyası nasıl kesilir ve video dosyası ile birleştirilir?
- 3. android mp4 dosyası ile mp3 dosyası birleştirmek için nasıl
- 4. İki grafik dosyası nasıl birleştirilir? (PHP, Imagick)
- 5. .pyd dosyası nasıl oluşturulur?
- 6. Bir CompoundDrawable'da metin ve resimler nasıl ortalanır?
- 7. Lisp'de metin dosyası nasıl oluşturulur ve yazılır
- 8. Bir yapılandırma dosyası nasıl oluşturulur ve Gunicorn'u kullanmayı nasıl anlarsınız?
- 9. JCodec kitaplığını kullanarak Java'daki görüntülerden mp4 video nasıl oluşturulur?
- 10. ggplot ve dplyr'i bir işlevde nasıl birleştirilir?
- 11. DataTrigger ve EventTrigger nasıl birleştirilir?
- 12. Find() ve AsNoTracking() nasıl birleştirilir?
- 13. ListView.itemTemplate ve NativeScript'teki Resimler
- 14. Asp.net'de bir zip dosyası nasıl oluşturulur 5
- 15. Windows'da belirli bir Boyut Dosyası Nasıl Oluşturulur?
- 16. OGRE ile bir .mesh dosyası nasıl oluşturulur?
- 17. MPEG-DASH ve parçalanmış mp4
- 18. Pencerelerde yama dosyası nasıl oluşturulur?
- 19. XmlReader'dan XML dosyası nasıl oluşturulur?
- 20. Jenkins TextParameter bir metin dosyası nasıl oluşturulur
- 21. PHP ile bir PDF dosyası nasıl oluşturulur?
- 22. MSBuild ile bir XML dosyası nasıl oluşturulur?
- 23. OpenCV ffmpeg ile Mac'te bir MP4 dosyası yazma
- 24. R tar.gz dosyası nasıl oluşturulur?
- 25. Başlıksız xml dosyası nasıl oluşturulur
- 26. FFmpeg .3gp Döşeme ve .mp4
- 27. İstisnaların bir listesi nasıl birleştirilir?
- 28. nasıl metin ve resimler ile bir div var bir div
- 29. matlab - 2 matris nasıl birleştirilir/birleştirilir?
- 30. Bir nsstring url'yi nasıl birleştirilir
bir şans – pskink
ffmpeg vermek Ama olabilir o ı sdk kullanarak tüm bunları yapmak isteyen bir ndk kütüphane sadece –
minimum API seviyesi gereksinimi nedir? –