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 can i convert this ffmpeg command line with FFmpegFrameRecorder? #307

Closed
antoniogiordano opened this issue Jan 9, 2016 · 8 comments
Closed

Comments

@antoniogiordano
Copy link

Hi everybody, i have this ffmpeg line command parameters i have to replicate with javacv library.
How can i do?

-strict -2 -c:a aac -b:a 128k -ar 44100 -r 30 -g 60 -keyint_min 60 -b:v 400000 -c:v libx264 -preset medium -bufsize 400k -maxrate 400k -f flv

Actually i have:

        // H264
        recorder.setVideoCodec(28);
        recorder.setFormat("mp4");
        recorder.setFrameRate(frameRate);
        // frameRate * 2; Azure needs GOP or key frame interval of 2 seconds
        recorder.setVideoOption("keyint_min", "60");
        recorder.setSampleRate(sampleAudioRateInHz);

How can i complete?

@Iqra786
Copy link

Iqra786 commented Jan 9, 2016

u can add following lines

recorder.setVideoCodec(org.bytedeco.javacpp.avcodec.AV_CODEC_ID_H264);
recorder.setAudioCodec(org.bytedeco.javacpp.avcodec.AV_CODEC_ID_AAC);
recorder.setVideoOption("preset", "medium");
recorder.setVideoBitrate(400000);

@alicanalbayrak
Copy link
Contributor

I need help with similar issue. I'm trying to implement following command with FFMpegFrameRecorder.

ffmpeg -i rtsp://10.0.5.1:554/live.sdp -vcodec copy ./vid.mp4

And my recorder settings like below:

frameRecorder = new FFmpegFrameRecorder(fout, frameGrabber.getVideoWidth(), frameGrabber.getVideoHeight());
        frameRecorder.setFormat("mp4"); 
        frameRecorder.setFrameRate(frameRate);
//      frameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
        frameRecorder.setVideoCodecName("H264");
        frameRecorder.setVideoQuality(0);

It works when I use frameRecorder.setVideoCodecName("H264"); but fails when frameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264); used. It says:

org.bytedeco.javacv.FrameRecorder$Exception: avcodec_open2() error -22: Could not open video codec.
    at org.bytedeco.javacv.FFmpegFrameRecorder.startUnsafe(FFmpegFrameRecorder.java:529)
    at org.bytedeco.javacv.FFmpegFrameRecorder.start(FFmpegFrameRecorder.java:288)

Also records are not smooth as expected. (Looking like some areas' pixels enlarging and marshalling neighbors pixels) Here is ffprobe output of my stream Could you give me any advice to record the stream (that I share ffprobe result) ?

@saudet
Copy link
Member

saudet commented Jan 16, 2016

@alicanalbayrak Have you tried with the latest code from the repository (1.2-SNAPSHOT)?

@alicanalbayrak
Copy link
Contributor

No Saudet, I did not. I tried it with javacv version 1,1. I could not build javacpp-presets 1.2-SNAPSHOT locally. Because, I'm using CentOS 7 and Flycapture SDK does not support any other linux packages except Ubuntu. Any ways, I tried to pass -vcodec copy parameter to recorder by using frameRecorder.setVideoOption("vcodec", "copy") but still throws avcodec_open2() error -22: Could not open video codec.

@saudet
Copy link
Member

saudet commented Jan 16, 2016

The ffmpeg module doesn't depend on flycapture, so you don't need to build that.

There is no codec named copy. That is just a special name used by the ffmpeg command line program. You're going to need to specify something valid there.

If you're looking for the something equivalent to the copy feature, that's what packets are for (issue #93). Please consider making a contribution. It's a feature requested by a lot of people, so it wouldn't be useful only to you! Thanks

@saudet
Copy link
Member

saudet commented Jan 18, 2018

JavaCV 1.4 has just been released. Is this working any better these days?

saudet added a commit to bytedeco/javacpp-presets that referenced this issue Mar 23, 2019
@saudet
Copy link
Member

saudet commented Mar 24, 2019

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, "-strict", "-2", "-c:a", "aac", "-b:a", "128k", "-ar", "44100", "-r", "30", "-g", "60", "-keyint_min", "60", "-b:v", "400000", "-c:v", "libx264", "-preset", "medium", "-bufsize", "400k", "-maxrate", "400k", "-f", "flv", ...);
   pb.inheritIO().start().waitFor();

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

@saudet
Copy link
Member

saudet commented Apr 11, 2019

The ffmpeg program is now being bundled starting with JavaCV 1.5. Enjoy!

@saudet saudet closed this as completed Apr 11, 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

4 participants