GemmyZero / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

FFmpegFrameRecorder has no support for audio #160

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
hi, samuel, 
    I am new to Android, android I want to use javacv/ffmpeg to encode camera data into .flv(h.264/aac), can javacv/ffmpeg be used in this way?
    Thank you very much!
What steps will reproduce the problem?
1.I have got data from Android camera(in onPreviewFrame(byte[] data, Camera 
camera))
2.I want to use JavaCV/FFmpeg to encode the data into flv(h.264/aac)
3.Can javacv/ffmpeg be used in this way?

What is the expected output? What do you see instead?
I just want to know that can javacv/ffmpeg be used in this way? And it would be 
better there is a demo, ha.

What version of the product are you using? On what operating system?
andriod 2.3, lenovo S2005A

Please provide any additional information below.
I would very much appreciate if you help me, thank you.

Original issue reported on code.google.com by zhangqia...@gmail.com on 27 Feb 2012 at 3:22

GoogleCodeExporter commented 8 years ago
The error that I receive with the updated JavaCV 0.3 is that the video codec 
H.264 cant be found. I have a similar situation.

Original comment by guar...@gmail.com on 24 Nov 2012 at 4:06

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi Zhag, 

I have tried to create a video with the audio . i have just used your code 
which is provided by you. But i am getting Strange Video . its full of Green 
color. So please advice me. 

Original comment by Rajeshan...@gmail.com on 8 Dec 2012 at 11:08

GoogleCodeExporter commented 8 years ago
Hi,Everyone,

I am using the FFmpegFrameRecorder class final updated upload by samuel.I need 
to merge a mp3 to images for creating a video.I convert the mp3 to raw PCM 
audio buffer(buffer[] in code given below) which is successfully playing in 
AudioTrack.But when i use this buffer to write in FFmpegFrameRecorder for 
creating a .mp4 file then its sound getting distorted and freaky.Where i am 
going wrong .Please someone help me.

FFmpegFrameRecorder recorder = new 
FFmpegFrameRecorder("/sdcard/test.mp4",320,214);
        try {
            recorder.setAudioCodec(AV_CODEC_ID_AAC);            
            recorder.setAudioBitrate(32000);
            recorder.setAudioChannels(1);
            recorder.setVideoCodec(AV_CODEC_ID_MPEG4);          
            recorder.setFrameRate(10);                  
            recorder.setPixelFormat(PIX_FMT_YUV420P);
            recorder.setFormat("mp4");          
            recorder.start();           
            recorder.record(ByteBuffer.wrap(buffer));
            recorder.stop();    
            Log.d("Recorder","Stopped");
            recorder.release();
           }
        catch (Exception e){
            e.printStackTrace();
          } 

Original comment by himjssmc...@gmail.com on 14 Dec 2012 at 2:56

GoogleCodeExporter commented 8 years ago
Hi Hjmjss ,i am also searching the solution to overcome this issue. right my 
sample works with the audio record + camera images. or (SDCARD images ) . but 
needs the solution like what you are expecting . 

Original comment by Rajeshan...@gmail.com on 17 Dec 2012 at 11:48

GoogleCodeExporter commented 8 years ago
Hi Rajeshan,

Is your sound recorded by the Audio Record is playing fine in file created by 
FFmpegFrameRecorder class.Let me know.Also tell me asap find solution to record 
mp3 using FFmpegFrameRecorder

Original comment by himjssmc...@gmail.com on 18 Dec 2012 at 9:25

GoogleCodeExporter commented 8 years ago
Hi Samuel,

Please look out my problem.I am getting stucked in this issue.

I am using the FFmpegFrameRecorder class final updated upload by you.I need to 
merge a mp3 to images for creating a video.
I convert the mp3 to raw PCM audio buffer(buffer[] in code given below) which 
is successfully playing in AudioTrack.

But when i use this buffer to write in FFmpegFrameRecorder for creating a .mp4 
file then its sound getting distorted and freaky.
Where i am going wrong .Please help me.I am too much confused about this issue 
and totally fed up from last two weeks.I have attached the file 

Outputted by FFmpegFrameRecorder which is giving distorted and freaky noise 
only.

FFmpegFrameRecorder recorder = new 
FFmpegFrameRecorder("/sdcard/test.mp4",320,214);
        try {
            recorder.setAudioCodec(AV_CODEC_ID_AAC);            
            recorder.setAudioBitrate(32000);
        recorder.setAudioChannels(2);
        recorder.setVideoCodec(AV_CODEC_ID_MPEG4);          
        recorder.setFrameRate(10);                  
        recorder.setPixelFormat(PIX_FMT_YUV420P);
        recorder.setFormat("mp4");          
            recorder.start();           
            recorder.record(ByteBuffer.wrap(buffer));
            recorder.stop();    
            Log.d("Recorder","Stopped");
            recorder.release();
           }
        catch (Exception e){
            e.printStackTrace();
          } 

Original comment by himjssmc...@gmail.com on 18 Dec 2012 at 9:28

Attachments:

GoogleCodeExporter commented 8 years ago
@himjssmca2007 If you're trying to write 16-bit little endian data, you need to 
use a ShortBuffer. In that case, this should work:
    recorder.record(ByteBuffer.wrap(buffer).order(LITTLE_ENDIAN).asShortBuffer());

And please post your questions on the mailing list next time if possible, thank 
you.

Original comment by samuel.a...@gmail.com on 22 Dec 2012 at 2:33

GoogleCodeExporter commented 8 years ago
Hi, anybody, I find something interesting, 
see"http://code.google.com/p/mp4parser/".

Original comment by zhangqia...@gmail.com on 8 Jan 2013 at 2:27

GoogleCodeExporter commented 8 years ago
this is for Android , i want for any webcam except android webcam  help me 
please

Original comment by isak...@gmail.com on 27 Jan 2013 at 4:27

GoogleCodeExporter commented 8 years ago
Hi,

So I understood that ffmpeg-1.0-android-arm.zip hasn't got support for h264.
Reading all the comments I found out that user zhangqia manage to compile 
ffmpeg and x264 and use them with your openCV.

I also tried that, but the symbolic links for the .so files of ffmpeg are not 
recognized by android.

How do you suggest this issue should be overcomed. How zhanggia managed to run 
livavcodec.so from openCV?

Tahnks,
Adrian

Original comment by adrian.d...@gmail.com on 5 Feb 2013 at 8:53

GoogleCodeExporter commented 8 years ago
Please continue the discussion about x264 at issue #259

Original comment by samuel.a...@gmail.com on 5 Feb 2013 at 8:55

GoogleCodeExporter commented 8 years ago
Hi samuel,

  Its all working fine.the only thing i want to know is that how to set audio bitrate for diffrent devices.As florin told us to use sampleAudioBitRate = 44100;
but it is fine for some devices.So plz tell me how can i set audio bitrate for 
all devices .

Thanx

Arun Goyal

Original comment by goyal.ar...@gmail.com on 14 Feb 2013 at 6:03

GoogleCodeExporter commented 8 years ago
Hello Guys,

I am still having issue with the audio codec. I have used the latest "extended" 
version from Sam for audio support but I always get the following error: "Could 
not open audio codec"...

I have tried almost everything but nothing would work. Any suggestions ? 

Here is my code:

 FrameGrabber grabber1 = new FFmpegFrameGrabber("output.mp4");
        FrameGrabber grabber2 = new FFmpegFrameGrabber("test.mp3"); 
        grabber1.start(); 
        grabber2.start(); 
        FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("outputFinal.mp4", 
                grabber1.getImageWidth(), grabber1.getImageHeight(), 
                grabber2.getAudioChannels()); 
        recorder.setFrameRate(grabber1.getFrameRate()); 
        recorder.setSampleFormat(grabber2.getSampleFormat()); 
        recorder.setSampleRate(grabber2.getSampleRate()); 

        recorder.start(); 
        com.googlecode.javacv.Frame frame1;
        com.googlecode.javacv.Frame  frame2 = null; 
        while ((frame1 = grabber1.grabFrame()) != null || 
               (frame2 = grabber2.grabFrame()) != null) { 
            recorder.record(frame1); 
            recorder.record(frame2); 
        } 
        recorder.stop(); 
        grabber1.stop(); 
        grabber2.stop(); 

Original comment by ifunf...@gmail.com on 19 Feb 2013 at 1:24

GoogleCodeExporter commented 8 years ago
@ifunface You should try without calling setSampleFormat() with newer versions 
of FFmpeg and FFmpegFrameRecorder with AAC/MP4 audio.

Original comment by samuel.a...@gmail.com on 21 Feb 2013 at 11:08

GoogleCodeExporter commented 8 years ago
Hi,
I am trying to stream video and audio to red5 media server. I use 
FFmpegFrameRecorder with the parameter rtmp://.... Everything works fine except 
that, the stream is only live and cannot be record. Is it possible to change 
publishmode of the stream to record? 

Original comment by piotr.sk...@gmail.com on 23 Jul 2013 at 10:37

GoogleCodeExporter commented 8 years ago
@piotr I can't find any information about whether FFmpeg supports that or not, 
so I don't think it does... If you find information concerning that though, 
please let us know so we can update FFmpegFrameRecorder, thanks!

Original comment by samuel.a...@gmail.com on 27 Jul 2013 at 11:45

GoogleCodeExporter commented 8 years ago
Hi,

I am creating a video by using images and audio file in Android. 
I am using FFmpegFrameRecorder() class
and using FrameGrabber to grab the audio frames form the audio file. 
//feeding image
 recorder.record(IplImage);

//feeding audio frame                    
 recorder.record(audioFrameGrabber.grabFrame());

//and at last i stop both 
grabber.stop();
recorder.stop();

I have put the code of creating video on a service. When i create video first 
time, every thing completes properly and i get proper .mp4 video file with 
sound.

but when i go to start that service again to create a new video.
then audioFrameGrabber doesn't start and i get exception in logcat.

07-27 19:42:53.435: E/cv::error()(15246): OpenCV Error: Bad argument 
(unrecognized or unsupported array type) in void cvReleaseData(CvArr*), file 
/home/saudet/projects/javacv-cppjars/opencv-2.4.5/modules/core/src/array.cpp, 
line 996

07-27 19:42:53.465: I/VideoMakerActivity(15246): Could not start the 
FrameGrabber Exception=java.lang.RuntimeException: 
/home/saudet/projects/javacv-cppjars/opencv-2.4.5/modules/core/src/array.cpp:996
: error: (-5) unrecognized or unsupported array type in function void 
cvReleaseData(CvArr*)
07-27 19:42:53.990: W/System.err(15246): 
com.googlecode.javacv.FrameGrabber$Exception: Could not grab: No 
AVFormatContext. (Has start() been called?)
07-27 19:42:54.000: W/System.err(15246):    at 
com.googlecode.javacv.FFmpegFrameGrabber.grabFrame(FFmpegFrameGrabber.java:520)
07-27 19:42:54.000: W/System.err(15246):    at 
com.googlecode.javacv.FFmpegFrameGrabber.grabFrame(FFmpegFrameGrabber.java:507)
07-27 19:42:54.000: W/System.err(15246):    at 
com.appzcloud.videomaker.CreateVideoService.onHandleIntent(CreateVideoService.ja
va:149)
07-27 19:42:54.000: W/System.err(15246):    at 
android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
07-27 19:42:54.000: W/System.err(15246):    at 
android.os.Handler.dispatchMessage(Handler.java:99)
07-27 19:42:54.000: W/System.err(15246):    at 
android.os.Looper.loop(Looper.java:137)
07-27 19:42:54.000: W/System.err(15246):    at 
android.os.HandlerThread.run(HandlerThread.java:60)

Thanks

Original comment by shivaagr...@gmail.com on 27 Jul 2013 at 2:29

GoogleCodeExporter commented 8 years ago
@shiva Does that issue also happen on the desktop? Or only on Android? 

Original comment by samuel.a...@gmail.com on 15 Aug 2013 at 3:21

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Guys i wonder how to make the  FFmpegFrameRecorder record a widscreen video or 
even HD video without stretching the scene ??? 
i mean what effects this 
is it the pixleformat or the codec or what???

Thanks 

Original comment by faithiol...@gmail.com on 10 Sep 2013 at 11:35

GoogleCodeExporter commented 8 years ago
@faithiology avfilter has some neat functionality for that apparently:
https://trac.ffmpeg.org/wiki/Scaling%20%28resizing%29%20with%20ffmpeg
But this is something we'd need to implement in FFmpegFrameRecorder... Do you 
feel up to the challenge? I'd help you as much as I can. IIRC, there's at least 
one other guy somewhere that also showed interest in avfilter. I can dig his 
name up and you could work together?

Original comment by samuel.a...@gmail.com on 15 Sep 2013 at 4:08

GoogleCodeExporter commented 8 years ago
Hi 

i am implementing live streaming in android javaCV0.3 Stream Test, i get demo 
from here : https://github.com/vanevery/JavaCV_0.3_stream_test, through this i 
am able to stream video from android device's camera to wowza server. and later 
i am able to play on web and in format of flv:

private volatile FFmpegFrameRecorder recorder;
recorder = new FFmpegFrameRecorder(ffmpeg_link, 320,240, 1);
recorder.setFormat("flv");
recorder.setSampleRate(44100);
recorder.setFrameRate(15);

Now my question is that how i can codec video in mp4 and codec into H.264
please give me some reference so i can go in right direction.

Original comment by androidd...@gmail.com on 16 Oct 2013 at 11:15

GoogleCodeExporter commented 8 years ago
Hello ,

I want to have video from the set of images lets say 20 images,
so for that can I use the file FFmpegFrameRecorder and I need the sound to be 
embedded to it.

so please help in this as I am stuck from a week into what to use to make video 
from a set of images I have searched a lot but didnt find a good to go so I am 
asking this question here.

Original comment by meghal.j...@gmail.com on 26 Feb 2014 at 8:15

GoogleCodeExporter commented 8 years ago
@meghal and everyone else: Please ask your questions on the mailing list.
https://groups.google.com/forum/#!forum/javacv
thank you!

Original comment by samuel.a...@gmail.com on 27 Feb 2014 at 1:27

GoogleCodeExporter commented 8 years ago
Hello Samuel,
I want to implement a live video streaming function in my android project, can 
you guide me how this JavaCv will be helpful for me.
Thank you

Original comment by sandy.ip...@gmail.com on 20 May 2014 at 5:18

GoogleCodeExporter commented 8 years ago
From #29 zhangqia...@gmail.com, 
recorder = new 
FFmpegFrameRecorder("rtmp://192.168.1.27:1935/livestream/12070660", width, 
height);

I tried that. The Android app runs, and I can see the video on the Android 
screen. Then on the Ubuntu 12.04 (within the same local network), I type: 
ffplay rtmp://192.168.1.27:1935/livestream/12070660

The output error is:
RTMP_Connect0, failed to connect socket. 113 (No route to host)/0   
rtmp://192.168.1.27:1935/livestream/12070660: Unknown error occurred

Could you tell me where is wrong?

Original comment by CodingPo...@gmail.com on 20 May 2014 at 5:15

GoogleCodeExporter commented 8 years ago
I am facing same issue, running my android code.

manu@ManuLapi:~$ ffplay rtmp://192.168.2.213:1935/live/test.flv
avplay version 0.8.12-4:0.8.12-0ubuntu0.12.04.1, Copyright (c) 2003-2014 the 
Libav developers
  built on Jun 10 2014 15:32:44 with gcc 4.6.3
[tcp @ 0xb0500b00] TCP connection to 192.168.2.213:1935 failed: Connection 
refused
[rtmp @ 0xb0502260] Cannot open connection tcp://192.168.2.213:1935
rtmp://192.168.2.213:1935/live/test.flv: Input/output error

Original comment by manoj.ku...@letsgomo.com on 26 Jun 2014 at 6:57