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

Setting audio frame rate to FFmpegFrameGrabber #1177

Closed
ZeroOneZeroR opened this issue Apr 8, 2019 · 22 comments
Closed

Setting audio frame rate to FFmpegFrameGrabber #1177

ZeroOneZeroR opened this issue Apr 8, 2019 · 22 comments
Labels

Comments

@ZeroOneZeroR
Copy link

Why does getAudioFrameRate() of FFmpegFrameGrabber always gives 38.28125 for all type of audios? How can we grab audio frame with different frame rate???

@saudet
Copy link
Member

saudet commented Apr 8, 2019

It's probably not returning anything useful, would need to be enhanced.

/cc @anotherche

@saudet
Copy link
Member

saudet commented Apr 8, 2019

BTW, we don't need to know the frame rate just to grab the frames.

@anotherche
Copy link
Contributor

mpeg1 audio frame contains 1152 samples.
link
more
38.28125=44100/1152
44100 is the sample rate (one of the standard)
and, yes, "we don't need to know the frame rate just to grab the frames"

@saudet
Copy link
Member

saudet commented Apr 9, 2019

@anotherche Thanks for confirming that this is working properly!

@rajib3hasan For audio streams, the sample rate is what is typically most useful. Call getSampleRate() to get that value and use that in your application. Other than that, I don't believe FFmpeg supports audio streams with variable sample rate or frame rate, but if you have such a file that is working with the ffmpeg program, please send me that file so we can check it out and fix JavaCV. Thanks!

@saudet saudet closed this as completed Apr 9, 2019
@ZeroOneZeroR
Copy link
Author

okay i am clear now...thanks a lot ....

@ZeroOneZeroR
Copy link
Author

hey now i am getting audioFrameRate 375.0 for one audio... i am shocked....

@ZeroOneZeroR
Copy link
Author

i am getting different audio frame rate for different audio with frame grabber

@anotherche
Copy link
Contributor

anotherche commented Apr 9, 2019

192000/512=375
this is only a guess
You can find out the sound format in the file using any suitable program. e.g. mediainfo (on Windows)

@ZeroOneZeroR
Copy link
Author

ZeroOneZeroR commented Apr 9, 2019

here what is 192000 and 512???

@ZeroOneZeroR
Copy link
Author

how time stamp is related with frame rate or sample rate??? how can i calculate progressive time stamp???

@saudet
Copy link
Member

saudet commented Apr 9, 2019

It's basic signal processing. Read this, for example:
https://en.wikipedia.org/wiki/Sampling_(signal_processing)#Sampling_rate

@anotherche
Copy link
Contributor

They are not related. Timestamp is the position of a frame in the stream (a time moment at which this frame should appear at normal playback). Frame rate and sample rate are defined by the sound format/encoder. If you transcode a video or audio (the content and duration/play rate remain the same) the position of a scene remain the same, but frame rate or sample rate may change if you use different formats/encoders.
Why do you need "calculate" timestamp? You simply set it (to seek to an approximate position)

@saudet
Copy link
Member

saudet commented Apr 9, 2019

@anotherche Some codecs are buggy though and do not provide a timestamp, see issue #1035.

@ZeroOneZeroR
Copy link
Author

ZeroOneZeroR commented Apr 9, 2019

I got you. How can i calculate what will be the time-stamp for next grab before grabbing? I don't wanna add that frame if it exceeds certain positions. And you know there is a little chance that time-stamp will be same as expected time position. I could do this checking after grabbing frame... but sometimes i get time-stamp 0,0 after two grab(); Could you please suggest some solution???

@ZeroOneZeroR
Copy link
Author

actually is there any audio stream when we get timestamp 0 ??? Can we skip the frame???

@anotherche
Copy link
Contributor

" here what is 192000 and 512???"
192000 is the one of standard sample rates (that used in high definition audio), 512 is the number of samples in one frame. The frame size depends on the format defined by an encoder.
"How can i calculate what will be the time-stamp for next grab before grabbing? "
The question is why do you need to know the time stamp of the next grab before grabbing. You do not need the time stamp to do next grab. Then you can get the time stamp of the grabbed frame. But if the encoder is that buggy which doesn't provide correct time stamps the only way will be an estimation based on the frame rate

@ZeroOneZeroR
Copy link
Author

ZeroOneZeroR commented Apr 10, 2019

Thank you...

@ZeroOneZeroR
Copy link
Author

But i am getting wrong video time still now. I check audioTimeStamp from grabber is greater than my expected time or not. If audioStamp is greater than expected time then i stop recording audio frame. After that, i get recorder timestamp exactly equal to my expected time but somehow video length is slightly greater than expected time and video in additional time is black. But when i add only bitmap , everything is okay... i can't figure out the problem.....

@anotherche
Copy link
Contributor

I'm not sure if this is related to your question, but here are some general thoughts.
Basically, video and audio streams are completely independent of each other. Each has its own characteristics, formats, and even hardware, through which they are eventually reproduced. The only thing that is true for them is that they are reproduced simultaneously, in parallel. Historically, the problem of desynchronization has often been encountered (this happens even nowadays). Digital video and audio are always presented in the form of discrete blocks (frames), but their duration generally does not match. The video uses its own standards (24, 25, 29.97, 30, 50, 60 frames per second), audio uses its own (FPS = sample rate / number of samples in the frame). Video fps is not equal to audio fps. In general, they are related as rational numbers. This means that an audio stamp may coincide with a video stamp after a certain number of frames, but in intermediate cases they will always be slightly different.

@saudet
Copy link
Member

saudet commented Apr 10, 2019 via email

@ZeroOneZeroR
Copy link
Author

Okay. But before pushing a frame to filter i get frame.sampleRate is equal to 48000, but after pulling it is 41000 and time stamp is zero for some frames. It causes problem. So i again set the sample rate and timestamp of frame after pulling from filter which i get before pushing. It solves some of my problems. I also skip the frame which for which i get timestamp 0 from grabber at the beginning of grabbing. It Some how solves my problem for now.

@saudet
Copy link
Member

saudet commented Apr 12, 2019

Ah, you were using FFmpegFrameFilter.
It didn't support timestamps, but I've just added that in commit 0bd6dc7. Enjoy!

yinmingjun pushed a commit to yinmingjun/javacv that referenced this issue May 24, 2019
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

3 participants