Kann mir jemand sagen, wie man Bilder kombinieren und eine MP4-Datei in Android generieren und die Videodatei in SD-Karte speichern? Vielen Dank im VorausWie kombiniere ich Bilder und erstelle eine mp4-Datei?
Antwort
Bitte überprüfen Sie den Code unten
Machen Sie eine Datei 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");
}
}
Machen Sie eine weitere Java-Datei 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();
}
}
andere Stellen Datei CommandH elper.java
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;
}
}
Wenn Sie Code ausführen möchten und machen Bilder auf Video unten Code verwenden, bitte.
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();
}*/
}
};
Bitte beachten Sie:
aufgenommenen Bilder im Format wie sein müssen:
IMG00001, Img00002 .......
erwartet
Da FFMPEG Code es auf diese Weise.
Was ist 'ffmpeg' in' R.raw.ffmpeg'? – Kuls
können Sie diese libray versuchen
https://github.com/sannies/mp4parser
in dieser Bibliothek sie erwähnen, dass Sie Film von Bildern (JPEG-Bild) erstellen.
Diese Bibliotheken erwähnen, dass es keine Bilder in Videos in seinen FAQ kombinieren kann – Oximer
Es gibt eine Vielzahl von Werkzeugen für die Bearbeitung Videos wie INDE, FFMPEG und etc.
INDE so viele Funktionen hat Videos und Bilder zu verbinden.
Wenn Sie sich entscheiden FFMPEG zu verwenden, dann stellt this link Schritte zur Integration dieses Tools
Weitere nützliche Links:
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. Wie kombiniere ich eine negative und eine positive Regex?
- 2. Guava: Wie kombiniere ich Filter und transformiere?
- 3. Wie kombiniere ich Bibliotheken?
- 4. Wie kombiniere ich aes() und aes_string() Optionen
- 5. Wie kombiniere ich angularjs und xhtml?
- 6. Wie kombiniere ich und setze? in .bat
- 7. Wie kombiniere ich Swing und SpringFramework?
- 8. Wie kombiniere ich Find() und AsNoTracking()?
- 9. Skimage: Wie kombiniere ich RGB-Kanäle?
- 10. Wie kombiniere/kombiniere ich Spalten aus zwei SQL-Abfrageergebnissen?
- 11. Wie erstelle ich eine MKMapView?
- 12. Wie erstelle ich eine Mehrfachfrage?
- 13. Wie erstelle ich eine Gemfile?
- 14. Wie kombiniere ich zwei Arrays?
- 15. Wie erstelle ich Bilder Roll über Nav-Schaltflächen in Wordpress
- 16. Wie erstelle ich eine QR-Code-Anwendung?
- 17. Wie erstelle ich eine Transaktionsnummer?
- 18. Wie erstelle ich eine PayPal-Zahlungsanforderung und sende eine Rechnung?
- 19. Was ist eine Binärdatei und wie erstelle ich eine?
- 20. Wie erstelle ich eine Zufallszahl und drucke eine andere Zahl?
- 21. Wie erstelle ich Expires Header für Amazon S3-Bilder?
- 22. Kombiniere Meteor und Express
- 23. Wie erstelle ich eine richtige Website?
- 24. Wie erstelle ich eine WhatsApp wie TextView und EditText?
- 25. Wie kombiniere ich eine Zeile mit einer Bedingung?
- 26. Wie kombiniere ich eine zufällige Anzahl von Listen in Python
- 27. Wie kombiniere ich eine Spalte aus mehreren Textdateien?
- 28. Wie kombiniere ich LINQ-Abfragen und selektiere unterschiedliche Datensätze?
- 29. Wie kombiniere ich Präfixe und Suffixe in EXCEL?
- 30. Wie kombiniere ich Tastendruck und Klickfunktion in JavaScript?
Sie eine Chance ffmpeg – pskink
geben könnte ich eine NDK Bibliothek Aber es wünschen all diese Dinge zu tun sdk mit nur –
Was ist Ihr Mindest API-Ebene Anforderung? –