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

When I call FFmpegFrameRecorder the start () method error #72

Closed
yesong opened this issue Dec 19, 2014 · 18 comments
Closed

When I call FFmpegFrameRecorder the start () method error #72

yesong opened this issue Dec 19, 2014 · 18 comments

Comments

@yesong
Copy link

yesong commented Dec 19, 2014

org.bytedeco.javacv.FrameRecorder$Exception: Could not open audio codec.
at org.bytedeco.javacv.FFmpegFrameRecorder.startUnsafe(FFmpegFrameRecorder.java:543)
at org.bytedeco.javacv.FFmpegFrameRecorder.start(FFmpegFrameRecorder.java:268)

The following is my code:

FileUtils fileUtils = new FileUtils();
fileUtils.creatSDDir(filePath);

AssetManager am = getAssets();
InputStream inputStream = am.open("music_city.mp3");
File audiofile = createFileFromInputStream(inputStream,0);

InputStream inputStream2 =am.open("tpl_afternoon.mp4");
File videoFile = createFileFromInputStream(inputStream2,1);

//audio grabber
FFmpegFrameGrabber grabberAudio = new FFmpegFrameGrabber(audiofile);
// video grabber
FFmpegFrameGrabber grabberVideo = new FFmpegFrameGrabber(videoFile);

grabberAudio.start();
grabberVideo.start();

int with = grabberVideo.getImageWidth();
int height = grabberVideo.getImageHeight();
int audioChannels = grabberAudio.getAudioChannels();

recorder = new FFmpegFrameRecorder(videoPath , with, height,audioChannels);

double frameRate = grabberVideo.getFrameRate();
int sampleRate = grabberAudio.getSampleRate();
int sampleFormat = grabberAudio.getSampleFormat();

Log.i("yesongsong", "frameRate= "+frameRate +" sampleRate= "+sampleRate +" sampleFormat= "+sampleFormat);

recorder.setFormat("mp4");
recorder.setFrameRate(grabberVideo.getFrameRate());
recorder.setSampleRate(grabberAudio.getSampleRate());
recorder.setSampleFormat(grabberAudio.getSampleFormat());
recorder.setVideoBitrate(videoBitrate);
recorder.setVideoCodec(videoCodec);
recorder.setAudioBitrate(audioBitrate);
//recorder.setAudioCodec(audioCodec);

recorder.start(); // run here Exception occurred

Frame frame1 = grabberVideo.grabFrame();
Frame frame2 = grabberAudio.grabFrame();

while (frame1 != null || frame2 != null) {

recorder.record(frame1);
recorder.record(frame2);
frame1 = grabberVideo.grabFrame();
frame2 = grabberAudio.grabFrame();

}
recorder.release();
recorder.stop();
recorder = null;
grabberAudio.stop();
grabberVideo.stop();
Log.i("yesongsong","Total Time:- "+ recorder.getTimestamp());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}.execute();

@jkolobok
Copy link

can you play those temporary video and audio files in any player?

@yesong
Copy link
Author

yesong commented Dec 19, 2014

Yes, I can play it. Now I have handle this problem, but the video after merge can not be played

@saudet
Copy link
Member

saudet commented Dec 19, 2014

Please try to use the default audio codec by NOT calling setAudioCodec().

@ya2
Copy link

ya2 commented Dec 20, 2014

yesong how did you solve this problem ?

@yesong
Copy link
Author

yesong commented Dec 22, 2014

use the default audio codec by NOT calling setAudioCodec().
recorder.setFormat("mp4");
recorder.setFrameRate(frameRate);
recorder.setSampleRate(sampleRate);
//recorder.setAudioCodec(audioCodec);

@yesong
Copy link
Author

yesong commented Dec 22, 2014

Hey Saudet

Now this problem has been solved, But now I encountered a new problem, I use an MP3 audio files and an MP4 video files composite a new MP4 file, but the composite video files can not be played, is that my code problem? Please help me, thank you !

this is my code:

//audio grabber
FFmpegFrameGrabber grabberAudio = new FFmpegFrameGrabber(audiofile);
// video grabber
FFmpegFrameGrabber grabberVideo = new FFmpegFrameGrabber(videoFile);

grabberVideo.start();
grabberAudio.start();

int with = grabberVideo.getImageWidth();
int height = grabberVideo.getImageHeight();
int audioChannels = grabberAudio.getAudioChannels();

String videoPath = fileUtils.getSDCardRoot() + filePath + File.separator + fileName;
recorder = new FFmpegFrameRecorder(videoPath , with, height,audioChannels);

double frameRate = grabberVideo.getFrameRate();
int sampleRate = grabberAudio.getSampleRate();

Log.i("yesongsong", "frameRate= "+frameRate +" sampleRate= "+sampleRate +" audioChannels= "+audioChannels);

recorder.setFormat("mp4");
recorder.setFrameRate(frameRate);
recorder.setSampleRate(sampleRate);

recorder.start();

Frame frame1 = grabberVideo.grabFrame();
Frame frame2 = grabberAudio.grabFrame();

while (frame1 != null || frame2 != null) {

recorder.record(frame1);
recorder.record(frame2);
frame1 = grabberVideo.grabFrame();
frame2 = grabberAudio.grabFrame();

}

recorder.release();
recorder.stop();
recorder = null;
grabberAudio.stop();
grabberVideo.stop();

@saudet
Copy link
Member

saudet commented Dec 23, 2014

@yesong Could you provide the messages that FFmpeg outputs to the console? Thanks!

@yesong
Copy link
Author

yesong commented Dec 23, 2014

@saudet Program at run time without any errors or warnings about the ffmpeg Tips

Is this my code problem? I've paid a lot of time, but it has not work.
if possible, can you give me a simple demo, thank you very much !

@yesong
Copy link
Author

yesong commented Dec 24, 2014

@saudet
Now I have solved the problem of the video can not be played, so happy, thank you!

@yesong yesong closed this as completed Dec 24, 2014
@saudet
Copy link
Member

saudet commented Dec 27, 2014

Ok, great to hear that! Could you please let us know how you fixed your problem, so that it may help others in the future with the same issue. Thank you!

@kostyaev
Copy link

After I call start() on a recorder, I get the following error:
org.bytedeco.javacv.FrameRecorder$Exception: avcodec_open2() error -22: Could not open audio codec.
This happens with a video having the following info:
Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 9732 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
Stream #0:1: Audio: pcm_u8 ([1][0][0][0] / 0x0001), 11024 Hz, 1 channels, u8, 88 kb/s
Other media content was processed normally so far.
I've tried to not set audio codec as was suggested above, unfortunately this didn't help. Could you give me any idea on how to fix it? Thank you in advance.

@saudet
Copy link
Member

saudet commented Dec 22, 2015 via email

@kostyaev
Copy link

Thanks for your advice, not the case though where I could ignore an audio track. It's appeared that a video codec also couldn't be opened.

@quinnxiao
Copy link

org.bytedeco.javacv.FrameRecorder$Exception: avio_open2 error() error -13: Could not open 'null'

but the file is :
String ffmpeg_link = "/sdcard/stream.mp4";
Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link);
recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 1);
recorder.setFormat("mp4");

why?
thank you!

@saudet
Copy link
Member

saudet commented Aug 25, 2017

@quinnxiao Errno 13 is "Permission denied": Your application doesn't have write access.

@ayeletc
Copy link

ayeletc commented Aug 5, 2018

I am trying the RecordActivity sample and I am getting the same error (13).

I have these in the manifest (before the application):
uses-permission android:name="android.permission.CAMERA" />
uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
uses-permission android:name="android.permission.INTERNET"/>
uses-permission android:name="android.permission.RECORD_AUDIO" />
uses-feature android:name="android.hardware.camera" />

Also when I open the app's permissions in my device it says that I have these permissions.
I use Sony D2303 (API 22).:

08-05 11:00:48.630 15147-15147/com.example.ayele.myapplication I/MainActivity: recorder initialize success
08-05 11:00:48.971 15147-15147/com.example.ayele.myapplication W/System.err: org.bytedeco.javacv.FrameRecorder$Exception: avio_open error() error -13: Could not open '/storage/emulated/0stream.flv'
at org.bytedeco.javacv.FFmpegFrameRecorder.startUnsafe(FFmpegFrameRecorder.java:639)
at org.bytedeco.javacv.FFmpegFrameRecorder.start(FFmpegFrameRecorder.java:288)
at com.example.ayele.myapplication.MainActivity.startRecording(MainActivity.java:224)
at com.example.ayele.myapplication.MainActivity.onClick(MainActivity.java:534)
at android.view.View.performClick(View.java:4856)
at android.view.View$PerformClick.run(View.java:19956)
at android.os.Handler.handleCallback(Handler.java:739)
08-05 11:00:48.972 15147-15147/com.example.ayele.myapplication W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
08-05 11:00:48.972 15147-15147/com.example.ayele.myapplication W/MainActivity: Start Button Pushed
08-05 11:00:48.973 15147-15147/com.example.ayele.myapplication I/Choreographer: Skipped 99 frames! The application may be doing too much work on its main thread.
08-05 11:00:53.860 15147-15147/com.example.ayele.myapplication W/MainActivity: init recorder
08-05 11:00:53.860 15147-15147/com.example.ayele.myapplication I/MainActivity: ffmpeg_url: /storage/emulated/0stream.flv
recorder initialize success
08-05 11:00:53.872 15147-15147/com.example.ayele.myapplication W/System.err: org.bytedeco.javacv.FrameRecorder$Exception: avio_open error() error -13: Could not open '/storage/emulated/0stream.flv'
at org.bytedeco.javacv.FFmpegFrameRecorder.startUnsafe(FFmpegFrameRecorder.java:639)
at org.bytedeco.javacv.FFmpegFrameRecorder.start(FFmpegFrameRecorder.java:288)
at com.example.ayele.myapplication.MainActivity.startRecording(MainActivity.java:224)
at com.example.ayele.myapplication.MainActivity.onClick(MainActivity.java:534)
at android.view.View.performClick(View.java:4856)
at android.view.View$PerformClick.run(View.java:19956)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:211)
at android.app.ActivityThread.main(ActivityThread.java:5371)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:945)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:740)
08-05 11:00:53.872 15147-15147/com.example.ayele.myapplication W/MainActivity: Start Button Pushed

What am I missing here? Thank you!

@saudet
Copy link
Member

saudet commented Aug 5, 2018 via email

@ayeletc
Copy link

ayeletc commented Aug 5, 2018

Thank you again!
Could you please tell me if this one too is a result of missing permissions (HAUWEI 9)

06-08 16:30:54.548 31518-31518/? I/art: Late-enabling -Xcheck:jni
Reinit property: dalvik.vm.checkjni= false
06-08 16:30:54.709 31518-31518/com.example.ayele.myapplication W/art: JIT profile information will not be recorded: profile file does not exits.
06-08 16:30:54.715 31518-31518/com.example.ayele.myapplication I/InstantRun: starting instant run server: is main process
06-08 16:30:54.742 31518-31518/com.example.ayele.myapplication I/HwCust: Constructor found for class android.app.HwCustActivityImpl
06-08 16:30:54.749 31518-31518/com.example.ayele.myapplication I/HwCust: Constructor found for class android.app.HwCustHwWallpaperManagerImpl
06-08 16:30:54.902 31518-31518/com.example.ayele.myapplication E/Camera: Camera new cameraInitNormal:0
06-08 16:30:54.902 31518-31518/com.example.ayele.myapplication I/MainActivity: camera open
06-08 16:30:54.911 31518-31518/com.example.ayele.myapplication W/camera: camera view
06-08 16:30:54.911 31518-31518/com.example.ayele.myapplication I/MainActivity: camera preview start: OK
06-08 16:30:54.915 31518-31518/com.example.ayele.myapplication I/HwSecImmHelper: mSecurityInputMethodService is null
06-08 16:30:54.919 31518-31518/com.example.ayele.myapplication I/HwPointEventFilter: support AFT
06-08 16:30:54.965 31518-31567/com.example.ayele.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
06-08 16:30:54.969 31518-31567/com.example.ayele.myapplication W/linker: /vendor/lib/libhwuibp.so: unused DT entry: type 0xf arg 0xeb5
06-08 16:30:55.248 31518-31518/com.example.ayele.myapplication W/Activity: Can reqeust only one set of permissions at a time
06-08 16:30:55.302 31518-31518/com.example.ayele.myapplication E/Camera: Camera new cameraInitNormal:0
06-08 16:30:55.302 31518-31518/com.example.ayele.myapplication I/MainActivity: camera open
06-08 16:30:55.303 31518-31518/com.example.ayele.myapplication W/camera: camera view
06-08 16:30:55.303 31518-31518/com.example.ayele.myapplication I/MainActivity: camera preview start: OK
06-08 16:30:55.306 31518-31518/com.example.ayele.myapplication I/HwPointEventFilter: support AFT
06-08 16:30:57.671 31518-31518/com.example.ayele.myapplication W/MainActivity: init recorder
06-08 16:30:57.678 31518-31518/com.example.ayele.myapplication I/MainActivity: create yuvImage
ffmpeg_url: /mnt/sdcard/stream.flv
06-08 16:30:57.805 31518-31518/com.example.ayele.myapplication W/linker: /data/app/com.example.ayele.myapplication-2/lib/arm/libjniavutil.so: unused DT entry: type 0xf arg 0x1c95f
06-08 16:30:57.835 31518-31518/com.example.ayele.myapplication W/linker: /data/app/com.example.ayele.myapplication-2/lib/arm/libjniswresample.so: unused DT entry: type 0xf arg 0x3458
06-08 16:30:57.857 31518-31518/com.example.ayele.myapplication W/linker: /data/app/com.example.ayele.myapplication-2/lib/arm/libjniavcodec.so: unused DT entry: type 0xf arg 0x1c6ce
06-08 16:30:57.881 31518-31523/com.example.ayele.myapplication I/art: Do partial code cache collection, code=9KB, data=21KB
After code cache collection, code=9KB, data=21KB
Increasing code cache capacity to 128KB
06-08 16:30:57.888 31518-31518/com.example.ayele.myapplication W/linker: /data/app/com.example.ayele.myapplication-2/lib/arm/libjniavformat.so: unused DT entry: type 0xf arg 0x19374
06-08 16:30:57.911 31518-31518/com.example.ayele.myapplication W/linker: /data/app/com.example.ayele.myapplication-2/lib/arm/libjniswscale.so: unused DT entry: type 0xf arg 0x4468
06-08 16:30:57.934 31518-31518/com.example.ayele.myapplication W/linker: /data/app/com.example.ayele.myapplication-2/lib/arm/libjnipostproc.so: unused DT entry: type 0xf arg 0x2ee6
06-08 16:30:57.955 31518-31518/com.example.ayele.myapplication W/linker: /data/app/com.example.ayele.myapplication-2/lib/arm/libjniavfilter.so: unused DT entry: type 0xf arg 0xad4b
06-08 16:30:57.980 31518-31518/com.example.ayele.myapplication W/linker: /data/app/com.example.ayele.myapplication-2/lib/arm/libjniavdevice.so: unused DT entry: type 0xf arg 0x4d58
06-08 16:30:58.086 31518-31518/com.example.ayele.myapplication I/MainActivity: recorder initialize success
06-08 16:30:58.197 31518-31690/com.example.ayele.myapplication I/AudioRecordPermission: remindWithResult:false
06-08 16:30:58.197 31518-31690/com.example.ayele.myapplication I/HwAudioRecordImpl: HwAudioRecordImpl
checkRecordActive
06-08 16:30:58.203 31518-31690/com.example.ayele.myapplication I/HwAudioRecordImpl: sendStateChangedIntent, state=3
06-08 16:30:58.254 31518-31518/com.example.ayele.myapplication W/MainActivity: Start Button Pushed
06-08 16:30:58.254 31518-31518/com.example.ayele.myapplication I/Choreographer: Skipped 35 frames! The application may be doing too much work on its main thread.
06-08 16:30:59.617 31518-31523/com.example.ayele.myapplication I/art: Do partial code cache collection, code=31KB, data=58KB
After code cache collection, code=31KB, data=58KB
Increasing code cache capacity to 256KB
06-08 16:31:00.143 31518-31690/com.example.ayele.myapplication I/HwAudioRecordImpl: sendStateChangedIntent, state=1
06-08 16:31:00.144 31518-31690/com.example.ayele.myapplication I/HwAudioRecordImpl: sendStateChangedIntent, state=1
06-08 16:31:00.164 31518-31518/com.example.ayele.myapplication W/MainActivity: Stop Button Pushed
06-08 16:34:42.619 31518-31518/com.example.ayele.myapplication W/IInputConnectionWrapper: reportFullscreenMode on inexistent InputConnection

EDIT
My mistake! I found the file in another dir!

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

No branches or pull requests

7 participants