harrissoerja / javacv

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

can't overrite extradata when using FFmpegFrameRecorder to mux H264 frames #362

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to write H264 encoded frames, which has already been encoded by other 
codec(not ffmpeg/libx264), into MP4 file. Since the encoded frames has 
different Video configuration, such as sps, pps, I need to use the sps/pps info 
to generate new extradata, and overrite the original ffmpeg extradata in 
AVCodecContext.

I did it after I received the SPS/PPS info as following:
        video_c.extradata(new BytePointer(spsPpsBuffer));
        video_c.extradata_size(spsPpsBuffer.length);

I have dumped the extradata after overriting it, and the dump result is 
correct, event before 
        avcodec_close(video_c);

However, after mux process finished, the avcC box info in the mp4 is still the 
original info generated by ffmpeg.

I'm using javacv-0.5 and try to enable MediaCodec on Android for my Glaxy Note2.

Here is the extradata for my encoded h264 frames, which is sps/pps info:
 0 0 0 1 103 66 -128 31 -23 1 64 123 32 0 0 0 1 104 -50 6 -14

Attached is the extradata generated by ffmpeg.

So, my question is, why overriting of extradata does not take effect?

Any feedback is appreciated!

Original issue reported on code.google.com by hone...@gmail.com on 10 Sep 2013 at 3:20

Attachments:

GoogleCodeExporter commented 9 years ago
Is it something that's supposed to work according to the documentation of 
FFmpeg? If it's a documented feature, please attach a code snippet so I can try 
and run here. If it's not documented, please consult with the authors of FFmpeg 
first, thanks!

Original comment by samuel.a...@gmail.com on 15 Sep 2013 at 5:33

GoogleCodeExporter commented 9 years ago
Hi, Samuel:

Thanks for your comments. 

Actually I have solved this issue by disabling the AVFMT_GLOBALHEADER setting 
in FFmpegFrameRecorder.java as following:

            if(true){ //disabling AVFMT_GLOBALHEADER for my private codec
                oformat.flags((oformat.flags()&(~AVFMT_GLOBALHEADER)));
                video_c.flags(video_c.flags() | CODEC_FLAG2_LOCAL_HEADER);
            }else if ((oformat.flags() & AVFMT_GLOBALHEADER) != 0) {
                video_c.flags(video_c.flags() | CODEC_FLAG_GLOBAL_HEADER);
            }

Then, I'm able to override the extradata when I received the Sps/pps from my 
encoder. Hope this change could be added into javacv, which may be needed by 
someone else with same issue.

Thanks for your great work on javacv.

-Martin

Original comment by hone...@gmail.com on 23 Sep 2013 at 7:05

GoogleCodeExporter commented 9 years ago
Good! Would you have a patch to suggest to include that feature in future 
versions of FFmpegFrameRecorder.java? Thanks!

Original comment by samuel.a...@gmail.com on 29 Sep 2013 at 12:11

GoogleCodeExporter commented 9 years ago
Samuel:

This change is only useful for my private codec, but not ffmpeg codec. 

I think if there is a new XXXRecorder.java in JavaCV to support third party 
codec, which will be a very good interface for the ones which do not want to 
use ffmpeg codec, but still need the parser, demuxer etc.

I think my patch could be useful to add into this XXXRecoder.java.

Original comment by hone...@gmail.com on 8 Oct 2013 at 9:56

GoogleCodeExporter commented 9 years ago
It would be helpful to know why you believe that it is not possible to adapt 
FFmpegFrameRecorder in some way... thanks!

Original comment by samuel.a...@gmail.com on 8 Oct 2013 at 10:01

GoogleCodeExporter commented 9 years ago
It is all right if you think it is better to adapt FFmpegFrameRecorder in
some way.

For my decoder, I changed the recording calling from sync and async, which
could improve the recording performance. There might be other different
requirement for different codec api.

Original comment by hone...@gmail.com on 8 Oct 2013 at 11:34

GoogleCodeExporter commented 9 years ago
I'm asking your opinion here: Do you think it's possible to adapt 
FFmpegFrameRecorder? And if so, how?

Original comment by samuel.a...@gmail.com on 13 Oct 2013 at 2:33

GoogleCodeExporter commented 9 years ago
I think what we need to figure out is a way to make it easy to change various 
FFmpeg options, in general. If anyone has any good ideas, please let us know! 
thanks

Original comment by samuel.a...@gmail.com on 4 Jan 2014 at 1:57