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

av_interleaved_write_frame() error -22 while writing interleaved video frame #40

Closed
shuky19 opened this issue Oct 15, 2014 · 9 comments
Closed
Labels

Comments

@shuky19
Copy link

shuky19 commented Oct 15, 2014

What steps will reproduce the problem?

  1. Running the code at the end of the question

What is the expected output?
All frame to be recorded

What do you see instead?
Every few frames I get this exception:

org.bytedeco.javacv.FrameRecorder$Exception: av_interleaved_write_frame() error -22 while writing interleaved video frame.
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:720)
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:624)
at org.bytedeco.javacv.FrameRecorder.record(FrameRecorder.java:290)

What version of the product are you using? On what operating system?
Android 4.4.4, Nexus 5, JavaCV 0.8

Please provide any additional information below.
Hi,

I am initializing FFmpegFrameGrabber to read from a video file, recorded in the past using FFmpegFrameRecorder,
and I want to send this video to an rtmp server using FFmpegFrameRecorder.

So far, I was able to do it, however I do have one problem, not all of the frames are delivered
from the file to the server, one in a few frames cause the FFmpegFrameRecorder to throw the exception mentioned above.

FYI, I am rotating the video since android preview frame is 90 degrees rotated, using the method below.

// Reader initilization part:
FFmpegFrameGrabber mGrabber = new FFmpegFrameGrabber("path-to-file recorded from camera using FFMpegFrameRecorder in the past");
mGrabber.start();

// Writer initilization part:
FFmpegFrameRecorder mFrameRecorder = new FFmpegFrameRecorder("/sdcard/Movies/Camra/final.flv", height, width, 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();

// Actual reading-writing:
Frame frame;
while ((frame = getFrame()) != null) {
mFrameRecorder.setTimestamp(timestamp);

if (frame.image != null) {
    frame.image = rotateImage(frame.image);
}

mFrameRecorder.record(frame);

}

// Rotate function:
private opencv_core.IplImage rotateImage(opencv_core.IplImage frame) {
if (mRotation != 0) {
opencv_core.IplImage destination;
if (mRotation != 180) {
if (mRotatedImage == null) {
mRotatedImage = opencv_core.cvCreateImage(opencv_core.cvSize(frame.height(), frame.width()), frame.depth(), frame.nChannels());
}

        destination = mRotatedImage;
        opencv_core.cvTranspose(frame, destination);
    } else {
        destination = frame;
    }

    if (mRotation == 90)
        opencv_core.cvFlip(destination, destination, 1);
    else if (mRotation == 270)
       opencv_core.cvFlip(destination, destination, 0);
    else if (mRotation == 180)
       opencv_core.cvFlip(destination, destination, -1);

    return destination;

}

return frame;
}

@shuky19
Copy link
Author

shuky19 commented Oct 15, 2014

Just posting comments from https://code.google.com/p/javacv/issues:

Project Member #1 samuel.a...@gmail.com
Could you please try again with JavaCV 0.9?

And please report any additional issues here if possible:
https://github.com/bytedeco/javacv/issues

Thank you

@shuky19
Copy link
Author

shuky19 commented Oct 15, 2014

Hi Samuel,

Thanks for your response, but using JavaCV 0.9 causes me this exception:

java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "av_input_audio_device_next" referenced by "libjniavdevice.so"...
at java.lang.Runtime.loadLibrary(Runtime.java:364)
at java.lang.System.loadLibrary(System.java:526)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:535)
at org.bytedeco.javacpp.Loader.load(Loader.java:410)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avdevice.(avdevice.java:18)
at org.bytedeco.javacv.FFmpegFrameGrabber.(FFmpegFrameGrabber.java:104)

After some searching, I ran into this question on Stackoverflow:
http://stackoverflow.com/questions/25272343/javacv-on-android-unsatisfiedlinkerror-from-libjniavdevice-so-dlopen-failed-c

Therefore, I used 0.9.1 version from this link:
https://oss.sonatype.org/content/repositories/snapshots/org/bytedeco/javacv/0.9.1-SNAPSHOT/

But the original problem still reproduces, Do you know how can I solve it?

Here an updated stacktraces (both existed on the 0.8 version too):

av_interleaved_write_frame() error -22 while writing interleaved video frame.
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:725)
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:629)
at org.bytedeco.javacv.FrameRecorder.record(FrameRecorder.java:290)

av_interleaved_write_frame() error -22 while writing interleaved video frame.
at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:725)
at org.bytedeco.javacv.FFmpegFrameRecorder.stop(FFmpegFrameRecorder.java:611)

Thanks

@saudet
Copy link
Member

saudet commented Oct 15, 2014

It sounds like a permission issue.. Could you try to write to the same file, but using some Android API instead? I would like to know if that works or not, thanks.

@shuky19
Copy link
Author

shuky19 commented Oct 15, 2014

Hi,

I don't believe its a permission issue, since it is writing the file, but with missing frames (due to the exception).

Moreover, the previous version of the app is using MediaRecorder to create the same file with no problems.

Shuky.

@saudet
Copy link
Member

saudet commented Oct 16, 2014

Does the RecordActivity sample as is, unmodified, work correctly? Or does that fail as well?

@saudet
Copy link
Member

saudet commented Oct 19, 2014

It looks like it might have something to do with the timestamp:
http://thompsonng.blogspot.jp/2011/09/ffmpeg-avinterleavedwriteframe-return.html
You should try to use FFmpegFrameRecorder without calling setTimestamp().

@shuky19
Copy link
Author

shuky19 commented Oct 19, 2014

Great I will try, thanks

@shuky19
Copy link
Author

shuky19 commented Oct 20, 2014

Hi,

I added these lines:

if (timestamp > mFrameRecorder.getTimestamp()) {
mFrameRecorder.setTimestamp(timestamp);
} else {
Log.d(TAG, "Incorrect timestamp: " + timestamp + " when Recorder on: " + mFrameRecorder.getTimestamp());
}

and the error stopped, However I'm curious how come the timestamp of the FFmpegFrameRecording is higher than my timestamp.

Do you know what causes this weird behavior?

@saudet
Copy link
Member

saudet commented Oct 20, 2014

Might be because you set the frame rate too low.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants