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

Zero duration on FFmpegFrameRecorder output #1253

Closed
omarzouk opened this issue Jul 17, 2019 · 3 comments
Closed

Zero duration on FFmpegFrameRecorder output #1253

omarzouk opened this issue Jul 17, 2019 · 3 comments

Comments

@omarzouk
Copy link

omarzouk commented Jul 17, 2019

Awesome library! great work!
I'm trying to crop a piece of an audio file and write the output in wavefile format. The following code produces the correct segment and the correct number of frames, but the duration on the output file is always 0. I've tried looking around and I'm aware of #1069 and #1179 which prompted me to use the latest version 1.5.1 but I'm not sure what I'm missing.

            FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(inputStream);
            grabber.setSampleFormat(AV_SAMPLE_FMT_S16);
            grabber.setSampleRate(targetSampleRate);
            grabber.setAudioChannels(1); // 1 channel mono audio
            grabber.setFormat("m4a");
            grabber.start();
            grabber.setAudioTimestamp(startOffset * 1000000L );


            FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(outputStream, grabber.getAudioChannels());
            recorder.setSampleFormat(grabber.getSampleFormat());
            recorder.setAudioChannels(grabber.getAudioChannels());
            recorder.setSampleRate(targetSampleRate);
            recorder.setFormat("wav");
            recorder.setAudioCodec(AV_CODEC_ID_PCM_S16LE);

            recorder.start();

            Frame frame = null;
            while ((frame = grabber.grabFrame()) != null && grabber.getTimestamp() <= endOffset * 1000000L) {
                recorder.record(frame);
            }

            recorder.stop();
            recorder.release();

            grabber.stop();
            grabber.release();
@omarzouk
Copy link
Author

changing from wav to ogg seems to fix the issue. However I would like the audio in wav format

@saudet
Copy link
Member

saudet commented Jul 17, 2019

Duplicate of #645

@saudet saudet marked this as a duplicate of #645 Jul 17, 2019
@saudet
Copy link
Member

saudet commented Jul 17, 2019

OutputStream doesn't support seeking so it won't work for file formats that modify the header on close.
It should be possible to hack something for ByteArrayOutputStream and such though, see issue #645.

@saudet saudet closed this as completed Jul 17, 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

2 participants