soantrinh / javacv

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

[Android + FFMpeg] Encoding error while using FFMpegRecorder in RecordActivity.java #313

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Just run the sample FFmpeg recording activity and start recording

What is the expected output? What do you see instead?
if h264 codec is used, you will occasionally get 
"com.googlecode.javacv.FrameRecorder$Exception: av_interleaved_write_frame() 
error -22 while writing interleaved video frame.
E/Playback -ProcessorRunnable(30169):   at 
com.googlecode.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:683) 
If h264 is not used, you will sometimes get a "error -1" during the encoding 
phase as well. 
This will result the frames to be dropped. 

What version of the product are you using? On what operating system?
April 7th build in downloads on Android 4.2 /Nexus 4.

Original issue reported on code.google.com by wzsddtc on 1 May 2013 at 8:00

GoogleCodeExporter commented 9 years ago
Seems to be related to the way the PTS is calculated:
http://thompsonng.blogspot.jp/2011/09/ffmpeg-avinterleavedwriteframe-return.html

I think I remember this error could happen if we try to write two frames with 
the same timestamp. Can you check and see if all the calls to 
recorder.setTimestamp() end up with unique monotonically increasing values?

Original comment by samuel.a...@gmail.com on 2 May 2013 at 2:36

GoogleCodeExporter commented 9 years ago
Thanks for the response Samuel. Yea, it is definitely related with PTS 
calculation. I saw that post and try to "retry" it to use it as a "later" frame 
but then it may cause the frame to be "overlapped" by the frame that happens 
after. I tried to look at multiple frames at a time and use a heuristic 
function to queue up the recording (audio have to be recorded in real time in a 
separate recorder and use ffmpeg to combine them together later)...anyways, 
long story short. Using the retry method reduce the error rate from about 15% 
to about 1% but frames may still be overlapped and lost.

Also tried to use setFrame, but the way PTS gets calculated is weird and does 
not produce the same results as expected as setTimestamp()

Anyone have better suggestions?  :) 

Original comment by wzsddtc on 2 May 2013 at 2:56

GoogleCodeExporter commented 9 years ago
FFmpegFrameRecorder automatically bumps up the timestamp according to the frame 
rate, so maybe you could to not call setTimestamp() at all if you are about to 
call it with a value <= getTimestamp() ?

Original comment by samuel.a...@gmail.com on 2 May 2013 at 3:00

GoogleCodeExporter commented 9 years ago
I created a patch for the sample file here:
http://code.google.com/p/javacv/source/detail?r=c514ee108a3e158e0fbf920f939403e9
28f7119d
Please let me know that it does the trick, thanks!

Original comment by samuel.a...@gmail.com on 11 May 2013 at 5:41

GoogleCodeExporter commented 9 years ago
Fix included in JavaCV 0.6!

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

GoogleCodeExporter commented 9 years ago
I created an app which converts images to video using ffmpeg recorder but I am 
facing distortion issue . As I have number of images and each image has 
different sizes so when I produce video from those images, video get distorted .
Please help me. 

Original comment by sumedhav...@gmail.com on 21 May 2015 at 3:57