Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

129
LINES

< > BotCompany Repo | #1014079 // Concat MP3s using JAVE/ffmpeg Spike [dev.]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 11463K of libraries. Compilation Failed (6709L/45K).

!7

lib 1013798 // jave

import it.sauronsoftware.jave.*;

p {
  L<File> sources = map gudrun_silent(ll("hallo", "du"));
  File target = programFile("hallo-du.mp3");
  mergeMP3s(source, target);
  printFileInfo(target);
}

svoid mergeMP3s(L<File> sources, File out) ctex {
  new DefaultFFMPEGLocator locator;
	FFMPEGExecutor ffmpeg = locator.createExecutor();
	
	ffmpeg.addArgument("-i");
	ffmpeg.addArgument("concat:" + join("|", map f2s(sources)));
	
	if (codec != null) {
		ffmpeg.addArgument("-acodec");
		ffmpeg.addArgument("copy");
	}
	
	ffmpeg.addArgument(f2s(out));
	
	ffmpeg.execute();

	try {
		String lastWarning = null;
		long duration;
		long progress = 0;
		RBufferedReader reader = null;
		reader = new RBufferedReader(new InputStreamReader(ffmpeg
				.getErrorStream()));
		MultimediaInfo info = parseMultimediaInfo(source, reader);
		if (durationAttribute != null) {
			duration = (long) Math
					.round((durationAttribute.floatValue() * 1000L));
		} else {
			duration = info.getDuration();
			if (offsetAttribute != null) {
				duration -= (long) Math
						.round((offsetAttribute.floatValue() * 1000L));
			}
		}
		if (listener != null) {
			listener.sourceInfo(info);
		}
		int step = 0;
		String line;
		while ((line = reader.readLine()) != null) {
			if (step == 0) {
				if (line.startsWith("WARNING: ")) {
					if (listener != null) {
						listener.message(line);
					}
				} else if (!line.startsWith("Output #0")) {
					throw new EncoderException(line);
				} else {
					step++;
				}
			} else if (step == 1) {
				if (!line.startsWith("  ")) {
					step++;
				}
			}
			if (step == 2) {
				if (!line.startsWith("Stream mapping:")) {
					throw new EncoderException(line);
				} else {
					step++;
				}
			} else if (step == 3) {
				if (!line.startsWith("  ")) {
					step++;
				}
			}
			if (step == 4) {
				line = line.trim();
				if (line.length() > 0) {
					Hashtable table = parseProgressInfoLine(line);
					if (table == null) {
						if (listener != null) {
							listener.message(line);
						}
						lastWarning = line;
					} else {
						if (listener != null) {
							String time = (String) table.get("time");
							if (time != null) {
								int dot = time.indexOf('.');
								if (dot > 0 && dot == time.length() - 2
										&& duration > 0) {
									String p1 = time.substring(0, dot);
									String p2 = time.substring(dot + 1);
									try {
										long i1 = Long.parseLong(p1);
										long i2 = Long.parseLong(p2);
										progress = (i1 * 1000L)
												+ (i2 * 100L);
										int perm = (int) Math
												.round((double) (progress * 1000L)
														/ (double) duration);
										if (perm > 1000) {
											perm = 1000;
										}
										listener.progress(perm);
									} catch (NumberFormatException e) {
										;
									}
								}
							}
						}
						lastWarning = null;
					}
				}
			}
		}
		if (lastWarning != null) {
			if (!SUCCESS_PATTERN.matcher(lastWarning).matches()) {
				throw new EncoderException(lastWarning);
			}
		}
	} finally {
		ffmpeg.destroy();
	}
}

Author comment

Began life as a copy of #1013799

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1014079
Snippet name: Concat MP3s using JAVE/ffmpeg Spike [dev.]
Eternal ID of this version: #1014079/1
Text MD5: a83e0f7b2d1ca4a216ea03a14e3fe99f
Transpilation MD5: 2720a24e09c37d216f1c3f9bf2fc6fc4
Author: stefan
Category: javax / audio
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-03-28 17:44:35
Source code size: 3217 bytes / 129 lines
Pitched / IR pitched: No / No
Views / Downloads: 449 / 990
Referenced in: [show references]