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

Could not initialize class org.bytedeco.javacpp.avutil Linux x86_64 #472

Closed
Wangxy013 opened this issue Apr 6, 2021 · 8 comments
Closed

Comments

@Wangxy013
Copy link

Wangxy013 commented Apr 6, 2021

Hello,
I tried to use javaCV to call ffmpeg for audio transcoding, and an error was reported when initializing FFmpegFrameGrabber:
Could not initialize class org.bytedeco.javacpp.avutil.
It is normal for me on the windows10 platform, I have this error when I push my code to the linux server
I understand that this is a relatively common problem, and the answer is generally like https://github.com/bytedeco/javacv/issues/1206#issuecomment-493274635> "You'll need to put all the JAR files in your class path for this to work".
I have repeatedly checked my dependencies and tried to adjust the version, but it has not been resolved.

public class AudioConvert {
	public static Map<String, Object> convert(byte[] inputBytes, int audioCodec, int sampleRate, int audioBitrate,
	                                          int audioChannels) {
		Map<String, Object> resultMap = new HashMap<>();
		byte[] outputBytes = null;
		Frame audioSamples = null;
		FFmpegFrameRecorder recorder = null;
		ByteArrayInputStream inputStream = null;
		String fileFolderPath = "/abc";
		File fileFolder = new File(fileFolderPath);
		if (!fileFolder.exists() && !fileFolder.isDirectory()) {
			fileFolder.mkdirs();
		}
		String outputFile = fileFolderPath + RandomStringUtils.randomAlphanumeric(10);
		//ByteArrayOutputStream outputStream = null;
		inputStream = new ByteArrayInputStream(inputBytes);
		//outputStream = new ByteArrayOutputStream();
		FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputStream);

		if (start(grabber)) {
			recorder = new FFmpegFrameRecorder(outputFile, audioChannels);
			recorder.setAudioOption("crf", "0");
			recorder.setAudioCodec(audioCodec);
			recorder.setAudioBitrate(audioBitrate);
			recorder.setAudioChannels(audioChannels);
			recorder.setSampleRate(sampleRate);
			recorder.setFormat("mp3");
			recorder.setAudioQuality(10);
			recorder.setAudioOption("aq", "10");
			if (start(recorder)) {
				try {
					while ((audioSamples = grabber.grab()) != null) {
						recorder.setTimestamp(grabber.getTimestamp());
						recorder.record(audioSamples);
					}

				} catch (org.bytedeco.javacv.FrameGrabber.Exception e1) {
					System.err.println("抓取失败");
				} catch (Exception e) {
					System.err.println("录制失败");
				}
				stop(grabber);
				stop(recorder);
			}
			try {
				outputBytes = Files.readAllBytes(new File(outputFile).toPath());
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		resultMap.put("outputBytes", outputBytes);
		resultMap.put("outputFilePath", outputFile);
		return resultMap;
	}

I tried to adjust the version of javaCV and ffmpeg, my maven dependency is:
image

The error I get on the linux_x86_64 platform is:

Service Exception:org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.ffmpeg.global.avutil
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1053)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:908)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.session.web.http.SessionRepositoryFilter.doFilterInternal(SessionRepositoryFilter.java:151)
        at org.springframework.session.web.http.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:81)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)

hope to get help, thanks~

@saudet
Copy link
Member

saudet commented Apr 7, 2021

NoClassDefFoundError means that some other class could not load. The cause of the error is going to be logged with that other exception, so please look for other errors in your logs, and that should tell you why it's failing.

@saudet
Copy link
Member

saudet commented Apr 7, 2021

Also, to get more information, make sure that the "org.bytedeco.javacpp.logger.debug" system property is set to "true" or that "org.bytedeco.javacpp.logger" is set to "slf4j" with your logger set to its debug level.

@saudet
Copy link
Member

saudet commented Dec 2, 2021

Please try again with JavaCV 1.5.6!

@harshitagrawal23
Copy link

harshitagrawal23 commented May 14, 2024

             <dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>javacv-platform</artifactId>
		<version>1.5.10</version>
	</dependency>

	<dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>javacv</artifactId>
		<version>1.5.10</version>
	</dependency>

	<dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>ffmpeg-platform</artifactId>
		<version>6.1.1-1.5.10</version>
	</dependency>

I am getting the same issue on my kubernets pod-
java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.ffmpeg.global.avutil
at java.base/java.lang.Class.forName0(Native Method) ~[na:na]
at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]

@jzw-1989
Copy link

             <dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>javacv-platform</artifactId>
		<version>1.5.10</version>
	</dependency>

	<dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>javacv</artifactId>
		<version>1.5.10</version>
	</dependency>

	<dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>ffmpeg-platform</artifactId>
		<version>6.1.1-1.5.10</version>
	</dependency>

I am getting the same issue on my kubernets pod- java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.ffmpeg.global.avutil at java.base/java.lang.Class.forName0(Native Method) ~[na:na] at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]

I had the same problem with 1.5.10,Did you solve?

@3-8UUID
Copy link

3-8UUID commented Aug 28, 2024

             <dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>javacv-platform</artifactId>
		<version>1.5.10</version>
	</dependency>

	<dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>javacv</artifactId>
		<version>1.5.10</version>
	</dependency>

	<dependency>
		<groupId>org.bytedeco</groupId>
		<artifactId>ffmpeg-platform</artifactId>
		<version>6.1.1-1.5.10</version>
	</dependency>

I am getting the same issue on my kubernets pod- java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.ffmpeg.global.avutil at java.base/java.lang.Class.forName0(Native Method) ~[na:na] at java.base/java.lang.Class.forName(Class.java:467) ~[na:na]

I had the same problem with 1.5.10,Did you solve?

me too .please help us

@saudet
Copy link
Member

saudet commented Aug 28, 2024

Please try again with Ubuntu

@saudet
Copy link
Member

saudet commented Aug 28, 2024

Duplicate of bytedeco/javacpp-presets#1379

@saudet saudet marked this as a duplicate of bytedeco/javacpp-presets#1379 Aug 28, 2024
@saudet saudet closed this as completed Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants