I try to merge multiple mp4 files via moviemaker like I saw in one post:
public class Main {
public static void main(String[] args) throws IOException {
MovieCreator mc = new MovieCreator();
Movie movie1 = mc.build("./test1.mp4");
Movie movie2 = mc.build("./test2.mp4");
//Fetching the video tracks from the movies and storing them into an array
Track[] vetTrackVideo = new Track[0];
vetTrackVideo = Stream.of(movie1, movie2)
.flatMap(movie -> movie.getTracks().stream())
.filter(movie -> movie.getHandler().equals("vide"))
.collect(Collectors.toList())
.toArray(vetTrackVideo);
//Fetching the audio tracks from the movies and storing them into an array
Track[] vetTrackAudio = new Track[0];
vetTrackAudio = Stream.of(movie1, movie2)
.flatMap(movie -> movie.getTracks().stream())
.filter(movie -> movie.getHandler().equals("soun"))
.collect(Collectors.toList())
.toArray(vetTrackAudio);
//Creating the output movie by setting a list with both video and audio tracks
Movie movieOutput = new Movie();
List<Track> listTracks = new ArrayList<>(List.of(new AppendTrack(vetTrackVideo), new AppendTrack(vetTrackAudio)));
movieOutput.setTracks(listTracks);
//Building the output movie and storing it into a Container
DefaultMp4Builder mp4Builder = new DefaultMp4Builder();
Container c = mp4Builder.build(movieOutput);
//Writing the output file
FileOutputStream fos = new FileOutputStream("output.mp4");
c.writeContainer(fos.getChannel());
fos.close();
}
}
For two files this works totally fine. But I have more then two files to merge. So I started adding a loop which merged two files and used the merged file to merge with another one. Theoretically it works and I see by the time stamp they are merged. But I cant open the file because its an mp4a with avc1 sound... Has anybody an idea how to solve it? The Code below is my attemp: just choose a directory with some mp4 files, the merged files are named output0, output1, 2, ...
The highest number is the final file. But while output0 works fine, already output1 wont work...
public void Merge(File folder){
File[] liste = folder.listFiles();
String path = jTextField1.getText();
for(int i = 0; i < liste.length-2; i++){
MovieCreator mc = new MovieCreator();
try{
Movie movie1 = mc.build(liste[i].toString());
System.out.println("Film 1: " + liste[i]);
Movie movie2 = mc.build(liste[i+1].toString());
System.out.println("Film 2: " + liste[i+1]);
//Fetching the video tracks from the movies and storing them into an array
Track[] vetTrackVideo = new Track[0];
vetTrackVideo = Stream.of(movie1, movie2)
.flatMap(movie -> movie.getTracks().stream())
.filter(movie -> movie.getHandler().equals("vide"))
.collect(Collectors.toList())
.toArray(vetTrackVideo);
//Fetching the audio tracks from the movies and storing them into an array
Track[] vetTrackAudio = new Track[0];
vetTrackAudio = Stream.of(movie1, movie2)
.flatMap(movie -> movie.getTracks().stream())
.filter(movie -> movie.getHandler().equals("soun"))
.collect(Collectors.toList())
.toArray(vetTrackAudio);
//Creating the output movie by setting a list with both video and audio tracks
Movie movieOutput = new Movie();
List<Track> listTracks = new ArrayList<>(List.of(new AppendTrack(vetTrackVideo), new AppendTrack(vetTrackAudio)));
movieOutput.setTracks(listTracks);
//Building the output movie and storing it into a Container
DefaultMp4Builder mp4Builder = new DefaultMp4Builder();
Container c = (Container) mp4Builder.build(movieOutput);
//Writing the output file
FileOutputStream fos = new FileOutputStream(path + "\\output" + i + ".mp4");
c.writeContainer(fos.getChannel());
fos.close();
File f = new File(path + "\\output" + i + ".mp4");
liste[i+1] = f;
}catch(Exception e2){
e2.printStackTrace();
}
}
}
since i can't comment yet, i'm writing it as an answer. i don't really know about moviemaker, however i've been dealing with media files and thought it could be different perspective to your problem.
you can use ffmpeg to merge media files as answered in here. also if you want to stick with java, here's the java wrapper for ffmpeg command line tool.
Related
I have try to change name from it's absolute path but when i again get the list of apps list is not updated. I want to share apps using udp and tcp socket
list = AppUtils.getAppList(context);
for (int i = 0; i < list.size(); i++) {
AppEntity appEntity = list.get(i);
//TODO Rename File
String filepath = appEntity.getAbsolutePath();
String path = filepath.substring(filepath.lastIndexOf("/") + 1);
File file = new File(filepath);
File from = new File(file.getName());
File to = new File(appEntity.getAppName());
// if (from.exists()) {
from.renameTo(to);
Log.d("FileName", "doInBackground: " + to);
// }
// File file1 = new File(filepath);
// Log.d("FileName", "doInBackground: "+file1.getName());
}
updatedList = AppUtils.getUpdatedAppList(context);
//TODO updated data
public static List<AppEntity> getUpdatedAppList(Context context) {
PackageManager pm = context.getPackageManager();
List<PackageInfo> packageInfos = pm.getInstalledPackages(0);
List<AppEntity> appInfos = new ArrayList<>();
for (PackageInfo packageInfo: packageInfos) {
ApplicationInfo app = packageInfo.applicationInfo;
if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
// Non-system application
File apkfile = new File(app.sourceDir);
PackageStats stats = new PackageStats(packageInfo.packageName);
AppEntity appInfo = new AppEntity(app.sourceDir);
appInfo.setPackageName(packageInfo.packageName);
appInfo.setVersionCode(packageInfo.versionCode);
appInfo.setVersionName(packageInfo.versionName);
appInfo.setUid(app.uid);
appInfo.setIcon(pm.getApplicationIcon(app));
File file = new File(appInfo.getAbsolutePath());
appInfo.setAppName(file.getName());
appInfo.setCacheSize(stats.cacheSize);
appInfo.setDataSize(stats.dataSize);
appInfos.add(appInfo);
}
}
return appInfos;
Log cat
doInBackground: SM Downloader.apk
2022-02-24 12:09:04.386 22246-22296/com.jubilant.tech.share D/FileName: doInBackground: ยท Zero Flow Mutual Assistance Upgrade Application.apk
2022-02-24 12:09:04.386 22246-22296/com.jubilant.tech.share D/FileName: doInBackground: Quiz.apk
2022-02-24 12:09:04.387 22246-22296/com.jubilant.tech.share D/FileName: doInBackground: Six Kalma.apk
Help please how to share installed apps with their original names
i create a new csv file in hdfs using java , and i am trying to append the data to that csv file , but failed to append with error
Failed to replace a bad datanode on the existing pipeline due to no more good datanodes being available to try. (Nodes: current=[DatanodeInfoWithStorage[192.168.1.25:9866,DS-b6d8a63b-357d-4d39-9f27-1ab76b8b6ccc,DISK]], original=[Dat
below is the code
csv file created and uplaoded to HDFS from java code , but not able append data to the existing file . but a newly uploaded csv from ui interface was able to appended data with java code , please help to resolve this issue.
private void appendFileToFile (String fileName) throws Exception{
long testTime1 = System.currentTimeMillis();
String hdfsHostDetails = new String("hdfs://192.168.1.25:9000");
Configuration conf = new Configuration();
conf.setBoolean("dfs.support.append", true);
FileSystem fs = FileSystem.get(URI.create(hdfsHostDetails), conf);
String dirpath = new String(hdfsHostDetails);
String targetfilepath = new String(dirpath+"/"+fileName);
int count = 0;
while (count < 2) {
int offset = 0;
int limit = 10000;
IgniteTable table = new IgniteTable(ignite, "nok_customer_demand");
String query = "SELECT * FROM nok_customer_demand OFFSET "+ offset +" ROWS FETCH NEXT "+ limit +" ROWS ONLY";
List<List<?>> lists = table._select(query);
List<String[]> rows = new ArrayList();
System.out.println(":::::::::::::::::: Data Ready for iteration ::::::::::::::"+ count);
// create a new file on each iteration
File file = new File("/home/tejatest1"+count+".csv");
FileWriter outputfile = new FileWriter(file);
CSVWriter writer = new CSVWriter(outputfile);
for (List eachlist : lists) {
String[] eachRowAsString = new String[eachlist.size()];
;
int i = 0;
for (Object eachcol : eachlist) {
eachRowAsString[i] = String.valueOf(eachcol);
rows.add(eachRowAsString);
i++;
}
writer.writeNext(eachRowAsString);
}
// on each iteration append the data in the file to hdfs
InputStream in = new BufferedInputStream(new FileInputStream(file));
FSDataOutputStream out =null;
if(!fs.exists(new Path(targetfilepath))) {
out = fs.create(new Path(targetfilepath));
} else{
out = fs.append(new Path(targetfilepath));
}
IOUtils.copyBytes(in, out, 4096, true);
writer.close();
out.close();
outputfile.close();
lists.clear();
in.close();
file.delete();
count++;
}
long testTime2 = System.currentTimeMillis();
System.out.println("-----total time taken for data fetch for all records in table using limit and offset:-------" + (testTime2 - testTime1) + " ms");
fs.close();
}
i resolve this issue with the below configuration
Configuration conf = new Configuration();
conf.set("fs.defaultFS",hdfsHostDetails);
conf.setInt("dfs.replication",1);
conf.setBoolean("dfs.client.block.write.replace-datanode-on-failure.enable",false);
conf.setBoolean("dfs.support.append", true);
FileSystem fs = FileSystem.get(URI.create(hdfsHostDetails), conf);
I struggle to find the error in my code.
I've tried several things I found online, but can't get any of them working.
Error
javax.media.NoProcessorException: Cannot find a Processor for: com.ibm.media.protocol.MergingPullDataSource#14514713
That should mean the data type of the merged source cannot be used, but I cannot find out why
I've already tried several formats also converting my audio file to .mov.
If someone could help me I would be very thankful.
Code
public static void main(String args[]){
//Creating the files with my path
File audio = new File("C:\\ffmpeg\\bin\\light.wav");
File video = new File("C:\\ffmpeg\\bin\\output.mov");
try {
//Create the sources
DataSource audioSource = Manager.createDataSource(audio.toURI().toURL());
DataSource videoSource = Manager.createDataSource(video.toURI().toURL());
//Merge them
DataSource[] vidAud = new DataSource[2];
vidAud[0] = videoSource;
vidAud[1] = audioSource;
DataSource finalVideo = Manager.createMergingDataSource(vidAud);
//Choose the destination to put it
MediaLocator dest = new MediaLocator("file:c:\\ffmpeg\\bin\\plsWork.mov");
VideoFormat videoF = new VideoFormat(VideoFormat.INDEO50);
AudioFormat audioF = new AudioFormat(AudioFormat.GSM_MS);
Format outputFormat[] = new Format[2];
outputFormat[0] = videoF;
outputFormat[1] = audioF;
FileTypeDescriptor outputType = new FileTypeDescriptor(FileTypeDescriptor.AIFF);
ProcessorModel procModel = new ProcessorModel(finalVideo, outputFormat, outputType);
Processor proc = null;
proc = Manager.createRealizedProcessor(procModel);
DataSource source = proc.getDataOutput();
DataSink sink = Manager.createDataSink(source, dest);
sink.open();
} catch(Exception e) {
e.printStackTrace();
}
}
Best regards
I have text file that contain 3 columns ID tweet Classification
I want to create a new Directory for each element of Classification
so I have created a Linked List to Get Last index and create a directory but it dosent work can you help me fix it?
thanks
this is my code:
//Create a linked list
LinkedList <String> fileLinkedList = new LinkedList<String>();
fileLinkedList.add(line.toString());//line is a String variable that contains buff.readLine();
System.out.println(fileLinkedList);
for(int i = 0; i < fileLinkedList.size();i++){
File LinkedFile = new File(fileLinkedList.getLast().toString());
fileLinkedList.add(line);
System.out.println(fileLinkedList);
if(LinkedFile.mkdirs()){
System.out.println("make dir");
}else{
System.out.println("doesnt work");
}
}
What I understand is you have a file that contains three columns like this :
ID1 tweet1 Classification1
ID2 tweet2 Classification2
ID3 tweet3 Classification3
ID4 tweet4 Classification4
You want to read lines of this file, get just Classification column and add them to linked list and then create a new directory the name of last element that is Classification
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader("File directory"));
LinkedList<String> fileLinkedList = new LinkedList<String>();
String line;
while ((line = bufferedReader.readLine()) != null) {
fileLinkedList.add(line.split(" ")[2]);
for(int i = 0; i < fileLinkedList.size();i++){
File LinkedFile = new File(fileLinkedList.removeLast());
if(LinkedFile.mkdirs()){
System.out.println("make dir");
}else{
System.out.println("doesnt work");
}
}
}
And be careful, if you five just a name of directory in new File() it creates directories in your project directory of workspace.
I'm using mp4parser to add two videos together in an android app, but the output is a file I can't play with my phone or my computer (Windows Media Player and VLC). This is the function i use
public void MergeVideos(String[] pathsToVideos, String pathToOutput) throws IOException, InterruptedException
{
List<Track> tracks = new LinkedList<Track>();
Movie outputVideo = new Movie();
for (int i = 0; i < pathsToVideos.length; i++)
{
Movie video = MovieCreator.build(pathsToVideos[i]);
List<Track> trackss = video.getTracks();
for (Track track : trackss)
{
if (track.getHandler().equals("vide"))
{
tracks.add(track);
}
}
}
outputVideo.addTrack(new AppendTrack(tracks.toArray(new Track[tracks.size()])));
Container out = new DefaultMp4Builder().build(outputVideo);
File outputFile = new File(pathToOutput);
if(!outputFile.exists())
{
outputFile.createNewFile();
}
//write mp4 file
FileChannel fc = new RandomAccessFile(String.format(pathToOutput), "rw").getChannel();
out.writeContainer(fc);
fc.close();
//Add to the android media gallery so i can see it on my computer
addToGallery(new File(pathToOutput));
}
Since the problem was coming from MP4Parser itself, I stepped over to FFMpeg, from which I can successfully combine videos.
I'm used the demuxer and for later reference; this is the command I used:
"ffmpeg -y -f concat -i temp.txt -c copy output.mp4"