Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use FFMPEGExecutor but command not run correctly #169

Closed
naffan2014 opened this issue Sep 14, 2021 · 3 comments
Closed

use FFMPEGExecutor but command not run correctly #169

naffan2014 opened this issue Sep 14, 2021 · 3 comments

Comments

@naffan2014
Copy link

naffan2014 commented Sep 14, 2021

in 2.7.3

code below:

public String annullsrcVideo(Long taskId,
								 Long startTime,
								 Long endTime,
								 DirType targetDir,
								 String targetFormat) {
		String filePath = fileInfra.makeDirPath(taskId, targetDir); //make dir path
		String fileName = "annullsrc_" + taskId + "_" + System.currentTimeMillis() + "_"  + (endTime - startTime) + "." + targetFormat;
		String fileAllPath = filePath + fileName;
		DefaultFFMPEGLocator locator = new DefaultFFMPEGLocator();
		FFMPEGExecutor localFFMPEG = locator.createExecutor();
		localFFMPEG.addArgument("-f");
		localFFMPEG.addArgument("lavfi");
		localFFMPEG.addArgument("-i");
		localFFMPEG.addArgument("color=size=1280x720:rate=25:color=black");
		localFFMPEG.addArgument("-f");
		localFFMPEG.addArgument("lavfi");
		localFFMPEG.addArgument("-i");
		localFFMPEG.addArgument("anullsrc=channel_layout=stereo:sample_rate=44100");
		localFFMPEG.addArgument("-t");
		localFFMPEG.addArgument(String.valueOf(endTime - startTime));
		localFFMPEG.addArgument(fileAllPath);
		try {
			localFFMPEG.execute();
		}catch (Exception e){
			LOGGER.info("空原视频构造失败,原因是:{}",e.getMessage());
		}
		return filePath;
	}


//for example
Long taskId = 20210914L;
		Long startTime = System.currentTimeMillis();
		Long endTime = System.currentTimeMillis() + 5;
		String path = produceInfra.annullsrcVideo(taskId, startTime, endTime, DirType.ANNULL, "ts");

no file created. but after enable log, i can get command this:

About to execute /var/folders/2y/jqhn24qs34sb1699gcdrdr_h0000gn/T/jave/ffmpeg-x86_64-2.7.3-osx -f lavfi -i color=size=1280x720:rate=25:color=black -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -t 5 /var/folders/2y/jqhn24qs34sb1699gcdrdr_h0000gn/T/bk-tv-quality-processor/20210914/ANNULL/annullsrc_20210914_1631601152939_5.ts -hide_banner

i use this command in terminal. it can produce annull video.

i found that if i make a breakpoint at FFMPEGExecutor.java line 119: ffmpeg = runtime.exec(cmd); when runing code and stop at this breakpoint and step over, the annull video can be produced.

it is a little confuzing..

@naffan2014
Copy link
Author

naffan2014 commented Sep 15, 2021

it must be some thread run eariler or later question, in 2.7.3 it must be due to some bug in it , but 2.7.3 is very old one so it not worth sovling.

my method is:

	String cmd = locator.getFFMPEGExecutablePath() +
			" -f lavfi -i color=size=1280x720:rate=25:color=black -f lavfi -i anullsrc=channel_layout=mono:sample_rate=16000 -vcodec h264 -acodec aac -t 30 output.mp4 -hide_banner  -loglevel quiet"
		try {
			Runtime runtime = Runtime.getRuntime();
			Process process = runtime.exec(cmd);
			process.waitFor();
		}catch (IOException ioe){
			LOGGER.info("reason1:{}",ioe.getMessage());
			throw ioe;
		}catch (InterruptedException ie){
			LOGGER.info("reason2:{}",ie.getMessage());
			throw ie;
		}

@shengtu0328
Copy link

I also encountered the same problem.
#220

@shengtu0328
Copy link

it must be some thread run eariler or later question, in 2.7.3 it must be due to some bug in it , but 2.7.3 is very old one so it not worth sovling.

my method is:

	String cmd = locator.getFFMPEGExecutablePath() +
			" -f lavfi -i color=size=1280x720:rate=25:color=black -f lavfi -i anullsrc=channel_layout=mono:sample_rate=16000 -vcodec h264 -acodec aac -t 30 output.mp4 -hide_banner  -loglevel quiet"
		try {
			Runtime runtime = Runtime.getRuntime();
			Process process = runtime.exec(cmd);
			process.waitFor();
		}catch (IOException ioe){
			LOGGER.info("reason1:{}",ioe.getMessage());
			throw ioe;
		}catch (InterruptedException ie){
			LOGGER.info("reason2:{}",ie.getMessage());
			throw ie;
		}

it must be some thread run eariler or later question, in 2.7.3 it must be due to some bug in it , but 2.7.3 is very old one so it not worth sovling.

my method is:

	String cmd = locator.getFFMPEGExecutablePath() +
			" -f lavfi -i color=size=1280x720:rate=25:color=black -f lavfi -i anullsrc=channel_layout=mono:sample_rate=16000 -vcodec h264 -acodec aac -t 30 output.mp4 -hide_banner  -loglevel quiet"
		try {
			Runtime runtime = Runtime.getRuntime();
			Process process = runtime.exec(cmd);
			process.waitFor();
		}catch (IOException ioe){
			LOGGER.info("reason1:{}",ioe.getMessage());
			throw ioe;
		}catch (InterruptedException ie){
			LOGGER.info("reason2:{}",ie.getMessage());
			throw ie;
		}

Your code is indeed a solution,thanks a lot。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants