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

How do I implement this command line in JAVACV? #1074

Closed
xiaozhubenben opened this issue Oct 24, 2018 · 18 comments
Closed

How do I implement this command line in JAVACV? #1074

xiaozhubenben opened this issue Oct 24, 2018 · 18 comments

Comments

@xiaozhubenben
Copy link

xiaozhubenben commented Oct 24, 2018

Hi, Ineed send a dtmf wav to callee using rtp, the following command line do this well:
ffmpeg –re -i "+wavFilePath+" -vn -acodec pcm_alaw -ar 8000 -f rtp rtp://aServer:aPort
How can I implement this command line with JAVACV?
Is it the following code? Using the code, on the callee side I can only hear some part of the WAV data content , feeling like some is missing.

	FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(wavFilePath);
		grabber.setAudioCodec(avcodec.AV_CODEC_ID_PCM_U8); 
		grabber.start();
		String outputRtp = "rtp://" + c.getAddress() + ":" + remoteAudioRtpPort;
		FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputRtp, grabber.getAudioChannels());
		recorder.setAudioCodec(avcodec.AV_CODEC_ID_PCM_ALAW); 	
		recorder.setFormat("rtp");
        recorder.setAudioQuality(0); 		
		recorder.setSampleRate(8000);
		recorder.setFrameRate(grabber.getAudioFrameRate());
		recorder.setAudioBitrate(64000); 	 
                recorder.start();
		Frame frame = null;		
		while ((frame = grabber.grabFrame()) != null) {
			recorder.setTimestamp(grabber.getTimestamp());            		
			recorder.record(frame);
		}
		

		grabber.flush();
		grabber.stop();
		
		grabber.close();
		
		recorder.stop();
		recorder.close();
		recorder.release();
@xiaozhubenben
Copy link
Author

My DTMF wav file is a few key sounds that add a lot of empty data before and after the key sounds.
But after sending it with JAVACV, I hear only the key sound on the peer, there is no silence duration.

@saudet
Copy link
Member

saudet commented Oct 25, 2018

It just sounds like you're losing packets on the network. RTP isn't a reliable protocol. Maybe try with HTTP instead.

@xiaozhubenben
Copy link
Author

It just sounds like you're losing packets on the network. RTP isn't a reliable protocol. Maybe try with HTTP instead.

Thanks for reply. Losing package is not the cause,because using command line ,ffmpeg did this well.

@saudet
Copy link
Member

saudet commented Oct 25, 2018

Are you running the ffmpeg program on the same device as JavaCV?

@xiaozhubenben
Copy link
Author

xiaozhubenben commented Oct 25, 2018

yes。javaCV and ffmpeg are runing on my laptop (windows 10 64bits ,jdk 1.8 32bits)
I attached the wav file
dtmf6974344727629505361wav.zip

@saudet
Copy link
Member

saudet commented Oct 27, 2018

Ok, so let's keep debugging this. Does this happen only with RTP? Or does the same thing happen with a file as output?

@xiaozhubenben
Copy link
Author

Sorry for replied so late. I had tried use file as output ,it is good.
ffmpeg –re -i c:\temp\dtmf9014913482394511336.wav -vn -acodec pcm_mulaw -ar 8000 -f wav c:\temp\test.wav

@saudet
Copy link
Member

saudet commented Oct 30, 2018

I mean, does it also work correctly in JavaCV when using a file?

@xiaozhubenben
Copy link
Author

Yes both command line and javacv worked using file as output

@saudet
Copy link
Member

saudet commented Nov 4, 2018

Ok, so it has something to do with the RTP protocol. What's the configuration of that version of ffmpeg? It get displayed when executing ffmpeg alone without any arguments. Thanks!

@xiaozhubenben
Copy link
Author

use cmd line ffmpeg configuration:

ffmpeg version N-92318-g4a976200d7 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 8.2.1 (GCC) 20181017
  configuration: --disable-static --enable-shared --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth
  libavutil      56. 21.100 / 56. 21.100
  libavcodec     58. 34.100 / 58. 34.100
  libavformat    58. 19.102 / 58. 19.102
  libavdevice    58.  4.106 / 58.  4.106
  libavfilter     7. 39.100 /  7. 39.100
  libswscale      5.  2.100 /  5.  2.100
  libswresample   3.  2.100 /  3.  2.100
  libpostproc    55.  2.100 / 55.  2.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

@saudet
Copy link
Member

saudet commented Nov 5, 2018

Hum, doesn't look like there's anything related to RTP in that list, but might be worth investigating.

@xiaozhubenben
Copy link
Author

How JavaCV realize the "–re " Option in ffmpeg command line?

@saudet
Copy link
Member

saudet commented Nov 14, 2018

It doesn't, but we can easily use something like Thread.sleep(10) in a loop and wait after when we're supposed to get a frame before calling grab(). That would probably solve the issue you're having. Something like that could be integrated in JavaCV, so I'll mark this as enhancement.

@xiaozhubenben
Copy link
Author

Thanks, but Thread.sleep() doesn't resovle this problem, the -re option set RTP send frequence ,and not grab speed

@saudet
Copy link
Member

saudet commented Nov 14, 2018 via email

@MCourser
Copy link

I also want to know how to implement the command -re for a record. I send video and audio frames by RTP protocol. And my video conference shows that the video is ok, but the audio is not in a right frame rate.

@saudet
Copy link
Member

saudet commented Mar 24, 2019

Duplicate of #307

With commit bytedeco/javacpp-presets@13ffffd the ffmpeg program itself now gets bundled, so we can use it easily from Java. For this case, we could do something like the following:

   String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);
   ProcessBuilder pb = new ProcessBuilder(ffmpeg, "-re", "-i", "+wavFilePath+", "-vn", "-acodec", "pcm_alaw", "-ar", "8000", "-f", "rtp", "rtp://aServer:aPort");
   pb.inheritIO().start().waitFor();

Please give it a try with 1.5-SNAPSHOT before the release: http://bytedeco.org/builds/

@saudet saudet closed this as completed Mar 24, 2019
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

3 participants