Reputation: 6776
I have been trying to merge (concatenate) two mp4 videos with same height and width but some error occurs. It says the output file doesnot have any stream. Please help. The code is written below :
String[] arg = new String[]{
ActualVideoFile.getAbsolutePath(), path
};
String list = generateList(arg);
String[] command = new String[]{
" -f concat -i " + list + " -c:v copy " + mergedVideo.getAbsolutePath()
};
try {
ffmpeg.execute(command, new FFmpegExecuteResponseHandler() {
@Override
public void onSuccess(String message) {
Log.e("SUCCESS", message);
}
@Override
public void onProgress(String message) {
Log.e("onProgress", message);
}
@Override
public void onFailure(String message) {
Log.e("onFailure", message);
}
@Override
public void onStart() {
Log.e("onStart", "start");
}
@Override
public void onFinish() {
Log.e("FINISH", "FINISHED");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
e.printStackTrace();
}
Logcat:
E/onFailure: ffmpeg version n3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/vagrant/SourceCode/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/vagrant/SourceCode/ffmpeg-android/build/armeabi-v7a --extra-cflags='-I/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all' --extra-ldflags='-L/home/vagrant/SourceCode/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Output #0, mp4, to ' -f concat -i /data/data/com.myapp/cache/ffmpeg-list-768575373.txt -c:v copy /storage/emulated/0/myapp/MergedVideos/1465426928071_Video.mp4':
Output file #0 does not contain any stream
Any help would be appreciated Thanks
Upvotes: 3
Views: 4898
Reputation: 21
Had the same issue. Turns out it's how the command is built.
This is incorrect as you need to divide up each command:
String[] command = new String[]{" -f concat -i " + list + " -c:v copy " + mergedVideo.getAbsolutePath();
Chirag your answer is spot on:
String[] cmd = {"-i",""+f.getPath(),"-i",""+imageFile.getPath(),"-filter_complex","overlay=10:main_h-overlay_h-10",outputDirectory.getPath()};
Hope this helps.
Upvotes: 2
Reputation: 741
This is my complete code snippet.. I am adding image overlay to video. For testing I have kept video and image in assets folder
File myDirectory = new File(Environment.getExternalStorageDirectory() + "/EditedVideo_2/");
File outputDirectory = new File(Environment.getExternalStorageDirectory() + "/EditedVideo_2/video" + System.currentTimeMillis() + ".mp4");
Log.d("directory path",Environment.getExternalStorageDirectory() + "/EditedVideo_2/");
if (!myDirectory.exists())
{
myDirectory.mkdirs();
}
File f = new File(Environment.getExternalStorageDirectory() + "/EditedVideo_2/sample.mp4");
if (!f.exists()) try
{
InputStream is = getAssets().open("sample.mp4");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
FileOutputStream fos = new FileOutputStream(f);
fos.write(buffer);
fos.close();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
Log.d("Path = ",f.getPath());
File imageFile = new File(Environment.getExternalStorageDirectory() + "/EditedVideo_2/ic_launcher.png");
if (!imageFile.exists()) try
{
InputStream is = getAssets().open("ic_launcher.png");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
FileOutputStream fos = new FileOutputStream(imageFile);
fos.write(buffer);
fos.close();
}
catch (Exception e)
{
throw new RuntimeException(e);
}
FFmpeg ffmpeg = FFmpeg.getInstance(this);
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler()
{
@Override
public void onStart()
{
Log.d("Event ","onStart");
}
@Override
public void onFailure()
{
Log.d("Event ","onFailure");
}
@Override
public void onSuccess()
{
Log.d("Event ","onSuccess");
}
@Override
public void onFinish()
{
Log.d("Event ","onFinish");
}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
}
try {
// to execute "ffmpeg -version" command you just need to pass "-version"
//String[] cmd = {"-version"};
String[] cmd = {"-i",""+f.getPath(),"-i",""+imageFile.getPath(),"-filter_complex","overlay=10:main_h-overlay_h-10",outputDirectory.getPath()};
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler()
{
@Override
public void onStart()
{
Log.d("Event ","onStart");
}
@Override
public void onProgress(String message)
{
Log.d("Event ","onProgress - "+message);
}
@Override
public void onFailure(String message)
{
Log.d("Event ","onFailure - "+message);
}
@Override
public void onSuccess(String message)
{
Log.d("Event ","onSuccess - "+message);
}
@Override
public void onFinish()
{
Log.d("Event ","onFinish");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
}
Upvotes: 3