Comments (22)
Well, strange enough but changing the Video codec to AV_CODEC_ID_MPEG4 from AV_CODEC_ID_H264 , fixed the problem for now , I'll still keep this issue open for you to look into ! & Thanks a lot for this beautiful library , makes it easier to work with ffmpeg and opencv on android 👍
from javacv.
Most (all?) codecs are going to fail when trying to setTimestamp()
something that is <= getTimestamp()
, so doing something like this should fix the error:
if (recorder.getTimestamp() < frameGrabber.getTimestamp()) {
recorder.setTimestamp(frameGrabber.getTimestamp());
}
Let me know if that doesn't do the trick though, thanks!
from javacv.
Thanks for the code !, Well this doesn't work even after replacing the setTimestamp() code with yours . So, I assume this is a bug in H264 codec implementation , as I am in hurry I'll rather change my codec to MPEG4 for now , till this thing gets fixed !
from javacv.
Well anyway, it's related to the call to setTimestamp()
. If you figure out that this is indeed a problem with FFmpegFrameRecorder
and not something wrong with your code or your data, please let me know so I can fix it, thanks!
from javacv.
Hi,
I am having the same problem with my code, I am recording a movie from the native camera's API on an Android devices, later on I am using JavaCV to upload it to an RTMP server.
I have looked at @saudet comment, and implemented the same, but still the last few seconds in my videos are being trimed.
Here is my code (I have closed issue #47 since after further investigation I understood it is due to this exact problem):
FFmpegFrameRecorder mFrameRecorder = new FFmpegFrameRecorder(urlPath, videoProfile.width, videoProfile.height, 1);
mFrameRecorder.setFormat("flv");
mFrameRecorder.setSampleRate(videoProfile.audioSampleRate);
mFrameRecorder.setFrameRate(videoProfile.frameRate);
mFrameRecorder.setVideoBitrate(videoProfile.bitRate);
mFrameRecorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
mFrameRecorder.setVideoOption("preset", "ultrafast");
mFrameRecorder.start();
FFmpegFrameGrabber mGrabber = new FFmpegFrameGrabber(mFilePath);
mGrabber.setSampleRate(videoProfile.audioSampleRate);
mGrabber.setFrameRate(videoProfile.frameRate);
mGrabber.setVideoBitrate(videoProfile.bitRate);
mGrabber.setVideoCodec(avcodec.AV_CODEC_ID_H264);
mGrabber.start();
Frame frame;
while ((frame = getFrame()) != null) {
if (frame != null) {
// If frame contains image
if (frame.image != null) {
// If need to rotate
if (mRotation != 0) {
frame.image = rotateImage(frame.image);
}
}
if (mGrabber.getTimestamp() > mFrameRecorder.getTimestamp()) {
mFrameRecorder.setTimestamp(mGrabber.getTimestamp());
} else {
Log.w(TAG, "Incorrect timestamp: " + mGrabber.getTimestamp() + " when Recorder on: " + mFrameRecorder.getTimestamp());
}
try {
mFrameRecorder.record(frame);
} catch (FrameRecorder.Exception e) {
Log.e(TAG, e.getMessage());
e.printStackTrace();
}
}
}
Can you take a look? also can you reopen this issue?
thanks,
Shuky
from javacv.
@shuky19 Does the same thing happen with Java SE? Or does this happen only with Android?
from javacv.
I tried it only on android...
from javacv.
So, could you please try it on Java SE as well?
from javacv.
Does this still happen with the latest version of JavaCV? If so, let's reopen this as a bug. Thanks!
from javacv.
I think this commit should fix this: fb2206d
Let me know! Thanks
from javacv.
Hi, guys
When I upload file to RTMP server, I get a fault all the time.
[libx264 @ 00000000266ccc00] non-strictly-monotonic PTS
And when I open rtmp stream in VLC, the video play fast abnormally.
I need some help...
from javacv.
Can anyone confirm if this if this works? I am using 1.3.1 and I am still facing this issue
from javacv.
@kmandayam Please provide a code snippet to reproduce this issue, thank you!
from javacv.
I'm trying to merge audio while video recording. I'm doing it onPreviewFrame:
@Override
public void onPreviewFrame(byte[] data, Camera camera)
{
try
{
if (songPath != null)
{
audioFrame = audioGrabber.grabFrame(true, false, false, false);
}
}
catch (FrameGrabber.Exception e)
{
e.printStackTrace();
}
/* get video data */
if (yuvIplImage != null && isRecording)
{
try
{
((ByteBuffer) yuvIplImage.image[0].position(0)).put(data);
timestamp = 1000 * (System.currentTimeMillis() - startTime);
if (songPath == null)
{
if (timestamp > recorder.getTimestamp())
{
recorder.setTimestamp(timestamp);
}
}
else
{
// Updating timestamp if audio is chosen from the library
if (recorder.getTimestamp() <= audioGrabber.getTimestamp() )
{
recorder.setTimestamp(audioGrabber.getTimestamp());
}
}
if (useFilter)
{
Frame frame2;
if (useNexusFilter())
{
nexusFilter.push(yuvIplImage);
while ((frame2 = nexusFilter.pull()) != null)
{
if (audioFrame != null)
{
recorder.record(audioFrame);
}
recorder.record(frame2);
}
}
else
{
filter.push(yuvIplImage);
while ((frame2 = filter.pull()) != null)
{
if (audioFrame != null)
{
recorder.record(audioFrame);
}
recorder.record(frame2);
}
}
}
else
{
if (audioFrame != null)
{
recorder.record(audioFrame);
}
recorder.record(yuvIplImage);
}
}
catch (NullPointerException e)
{
e.printStackTrace();
}
catch (FFmpegFrameRecorder.Exception | FrameFilter.Exception | BufferOverflowException e)
{
e.printStackTrace();
}
}
}
I'm initializing and updating the FrameGrabber and recorder in surfaceCreated:
@OverRide
public void surfaceCreated(SurfaceHolder holder)
{
try
{
stopPreview();
camera.setPreviewDisplay(holder);
this.camera.setPreviewCallback(CameraView.this);
if (songPath != null)
{
// Initialize audioGrabber
audioGrabber = new FFmpegFrameGrabber(songPath);
audioGrabber.start();
audioGrabber.setFormat("mp3");
audioGrabber.setFrameRate(FRAME_RATE);
audioGrabber.setSampleRate(AUDIO_RATE);
// Update recorder settings
recorder.setSampleRate(audioGrabber.getSampleRate());
recorder.setFrameRate(FRAME_RATE);
recorder.setAudioChannels(audioGrabber.getAudioChannels());
recorder.setSampleRate(AUDIO_RATE);
}
}
catch (FrameGrabber.Exception e)
{
e.printStackTrace();
}
catch (IOException exception)
{
camera.release();
camera = null;
}
}
I'm also losing few seconds of audio before the video ends. Please take a look and let me know if I am going wrong somewhere
from javacv.
from javacv.
@saudet I've only tried it on android. Not sure how to reproduce it with Java SE
from javacv.
@kmandayam Could you elaborate on why you're not sure how to reproduce this issue with Java SE?
from javacv.
@saudet Sorry for the late reply. I don't have a lot of experience working with javacv, so I don't know how to replicate this problem.
from javacv.
It works fine when I don't try to merge a separate audio file with the video (ie using the mic). All the frames are retained.
from javacv.
from javacv.
Well, since I am trying to merge audio while I record video, even if I stop recording mid way through the audio file, it still gets cropped. Could it have to do anything with the sample rate or frame rate?
from javacv.
from javacv.
Related Issues (20)
- How to grab H264 data instead of YUV? HOT 3
- The OpenCV2 source code and some cmake scripts are packaged into arm64-v8a HOT 1
- Audio and Video not syncing properly when combining multiple cut videos HOT 1
- which compiled version support '--enable-filter=gltransition' feature? HOT 1
- JavaFxPlayVideoAndAudio example plays audio out of sync with video HOT 6
- Why filter [wm][maskgif]"overlay=enable='between(t,5,10)'" doesn't work ?
- OpenCVFrameConverter.ToMat or LeptonicaFrameConverter corrupting image HOT 4
- x11grab gpu accelerate HOT 1
- how to save high quality mp4 vedio with FFmpegFrameRecorder
- Slight but noticeable color shift when using FFmpegFrameGrabber HOT 2
- NoClassDefFoundError: Could not initialize class org.bytedeco.javacv.FFmpegFrameGrabber with later version 1.5.9 HOT 7
- Java CV is still adding other plateform jar even classifier is added. HOT 1
- do we need to call frame.close() after calling FFmpegFrameGrabber.grabImage() ? HOT 3
- mvn package fails due to JavaDocs picking up broken source files HOT 2
- Loading of libraries slower after update to 1.5.10 (Windows, no longer cached?) HOT 6
- Some problem with these code, sometime recorder may blocked?
- javacv 1.5.10 FFmpegFrameGrabber init error HOT 6
- why FFmpegFrameRecorder.record() No data was retrieved?
- Problem converting frame to IplImage HOT 5
- JVM crash when calling FFmpegFrameRecorder.stop()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javacv.