# ohos-ffmpeg-java **Repository Path**: HarmonyOS-tpc/ohos-ffmpeg-java ## Basic Information - **Project Name**: ohos-ffmpeg-java - **Description**: No description available - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-09-17 - **Last Updated**: 2023-04-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ohos-ffmpeg-java ## Introduction This Project is Audio/Video Processor, It is a Java wrapper around an ffmpeg command line binary and sox command line binary for use in openharmony applications. For ease of developer use, we've included the FFMPEG and Sox binaries embedded in the project. ## Usage instructions Sample code on how to Trim video with ffmpeg apis. ```java String input_video_file_path = ResUtil.getMediaInputFilePath(ctx, "samplevideo.mp4"); String output_trimmed_file_path = "/storage/emulated/0/Android/data/org.ffmpeg.ohos.sample/files/Music/trimsamplevideo.mp4"; try { Clip clip_trim = new Clip(input_video_file_path); clip_trim.startTime = "00:00:04"; //Starting time in second clip_trim.duration = 8; //Duration in seconds new FfmpegController(ctx, new File("/tmp")).trim(clip_trim, true, output_trimmed_file_path, new ShellUtils.ShellCallback() { @Override public void shellOut(String shellLine) { Log.d(TAG, " shellOut shellLine=" + shellLine); } @Override public void processComplete(int exitValue) { Log.i(TAG, " processComplete"); } }); return true; //success } catch (Exception e) { Log.e(TAG, " Got Exception=" + e.getMessage()); return false; //failure } ``` Sample code to Mix two audio files with fading effect. ```java String input_audio_file_path1 = ResUtil.getMediaInputFilePath(ctx, "imperialmarch60.wav"); String input_audio_file_path2 = ResUtil.getMediaInputFilePath(ctx, "pinkpanther60.wav"); String output_audio_file_path = "/storage/emulated/0/Android/data/org.ffmpeg.ohos.sample/files/Music/mixedaudio.wav"; try { SoxController soxc = new SoxController(ctx, null, new ShellUtils.ShellCallback() { @Override public void shellOut(String shellLine) { Log.d(TAG, " shellOut shellLine=" + shellLine); } @Override public void processComplete(int exitValue) { Log.i(TAG, " processComplete"); } }); new CrossfadeCat(soxc, input_audio_file_path1, input_audio_file_path2, 20, output_audio_file_path).start(); return true; } catch (Exception e) { Log.e(TAG, " Got Exception=" + e.getMessage()); return false; } ``` for other demo sample codes please refer sample application. ## Installation instruction Solution 1. For using ohos-ffmpeg-java module in sample app, include the below library dependency to generate hap/ohos-ffmpeg-java.har: Add the dependencies in entry/build.gradle as below: dependencies { implementation project(path: ':library') } Solution 2. Using the ohos-ffmpeg-java library har, make sure to add ohos-ffmpeg-java.har file in the entry/libs folder and add the below dependency in build.gradle. Modify the dependencies in the entry/build.gradle file. dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) }