cropsly / ffmpeg-android

FFmpeg for Android compiled with x264, libass, fontconfig, freetype, fribidi and lame (Supports Android 4.1+)
http://writingminds.github.io/ffmpeg-android/
Other
1.63k stars 415 forks source link

what is command for adding text over video and audio in video in android java ffmpeg #114

Open mayursancheti opened 2 years ago

mayursancheti commented 2 years ago

i am using com.writingminds:FFmpegAndroid:0.3.2 this library , please suggest command for adding text and audio to video. i tried below code,

`public class MainActivity extends AppCompatActivity {

FFmpeg ffmpeg;
String TAG;
EditText editTextEmail;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    editTextEmail = findViewById(R.id.editTextEmail);

    loadFFMpegBinary();

   String outputpath = Environment.getExternalStorageDirectory().getAbsolutePath()
           .toString() + File.separator + Environment.DIRECTORY_MOVIES + "/" + "outputvideo.mp4";

   Log.d(TAG,"hhhhh "+outputpath);

    String[] command = {"-y -i "+editTextEmail.getText()+" -vf drawtext=fontsize=50:fontfile=cute.ttf:text='TEST MAYUR':x=w-tw-10:y=h-th-10 -c:v libx264 -preset ultrafast "+outputpath};

    Button loginButtonSignup = findViewById(R.id.buttonSignup);
    loginButtonSignup.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            execFFmpegBinary(command);
        }
    });

}
private void loadFFMpegBinary() {
    try {

        if (ffmpeg == null) {
            Toast.makeText(MainActivity.this, "nulll", Toast.LENGTH_SHORT).show();
            Log.d(TAG, "ffmpeg : null");
            ffmpeg = FFmpeg.getInstance(this);
        }
        ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
            @Override public void onFailure() {
                Toast.makeText(MainActivity.this, "hererer", Toast.LENGTH_SHORT).show();
            }
            @Override public void onSuccess() {

                Log.d(TAG, "fmpeg : correct Loaded");
                Toast.makeText(MainActivity.this, "Correct loaded", Toast.LENGTH_SHORT).show();
            }
        });

    } catch (FFmpegNotSupportedException e) {
        Toast.makeText(MainActivity.this, "hererer", Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Log.d(TAG, "EXception not supported : "  + e); }
}

private void execFFmpegBinary(final String[] command) {
    try {
        ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {
            @Override public void onFailure(String s) {
                Log.d(TAG, "FAILED with output : " + s);
                Toast.makeText(MainActivity.this, "failed output "+s, Toast.LENGTH_SHORT).show();
            }
            @Override
            public void onSuccess(String s) {
                Log.d(TAG, "SUCCESS with output : " + s); //Perform action on success
                Toast.makeText(MainActivity.this, "succcess output "+s, Toast.LENGTH_SHORT).show();
            }
            @Override
            public void onProgress(String s) {
                Log.d(TAG, "progress : " + s);

            }
            @Override public void onStart() {
                Log.d(TAG, "Started command : ffmpeg " + command);
                Toast.makeText(MainActivity.this, "Started command ", Toast.LENGTH_SHORT).show();

            }
            @Override public void onFinish() {
                Log.d(TAG, "Finished command : ffmpeg " + command);
                //Toast.makeText(MainActivity.this, "Finished commeda", Toast.LENGTH_SHORT).show();
            }
        });
    }

    catch (FFmpegCommandAlreadyRunningException e) {
        Toast.makeText(this, ""+e, Toast.LENGTH_SHORT).show();
    }

}

}`