bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.55k stars 1.58k forks source link

Filter frame timestamp starts from 0 when dynamically changing the filter #1950

Open libenli opened 1 year ago

libenli commented 1 year ago
  1. I want to modify the filter dynamically. I find that the timestamp of the filter frame starts from 0 through the log;
  2. In addition, if a new rtmp input stream is dynamically added, the timestamp of this new input stream will also start from 0; What should I do to ensure that the timestamps of all frames are close to one second? Are there examples to provide ideas? thank you
libenli commented 1 year ago
1111111111t0=19443000  t1=19477000  filter=18440000  recorder=18400000  type0=VIDEO  type1=VIDEO
1111111111------t0=19562000  t1=19584000  filter=19434666  recorder=18466667  type0=AUDIO  type1=AUDIO
1111111111------t0=19605000  t1=19626000  filter=19477333  recorder=18466667  type0=AUDIO  type1=AUDIO
1111111111t0=19510000  t1=19543000  filter=18520000  recorder=18466667  type0=VIDEO  type1=VIDEO
1111111111------t0=19626000  t1=19648000  filter=19498666  recorder=18566667  type0=AUDIO  type1=AUDIO
1111111111------t0=19669000  t1=19690000  filter=19541333  recorder=18566667  type0=AUDIO  type1=AUDIO
1111111111t0=19577000  t1=19610000  filter=18600000  recorder=18566667  type0=VIDEO  type1=VIDEO
1111111111------t0=19690000  t1=19712000  filter=19562666  recorder=18633333  type0=AUDIO  type1=AUDIO
1111111111------t0=19733000  t1=19754000  filter=19605333  recorder=18633333  type0=AUDIO  type1=AUDIO
1111111111------t0=19776000  t1=19797000  filter=19648000  recorder=18633333  type0=AUDIO  type1=AUDIO
1111111111t0=19677000  t1=19710000  filter=18680000  recorder=18633333  type0=VIDEO  type1=VIDEO
1111111111------t0=19797000  t1=19818000  filter=19669333  recorder=18700000  type0=AUDIO  type1=AUDIO
1111111111------t0=19840000  t1=19861000  filter=19712000  recorder=18700000  type0=AUDIO  type1=AUDIO
1111111111t0=19743000  t1=19777000  filter=18760000  recorder=18700000  type0=VIDEO  type1=VIDEO
1111111111------t0=19861000  t1=19882000  filter=19733333  recorder=18800000  type0=AUDIO  type1=AUDIO
1111111111------t0=19904000  t1=19925000  filter=19776000  recorder=18800000  type0=AUDIO  type1=AUDIO
1111111111------t0=19925000  t1=19946000  filter=19797333  recorder=18800000  type0=AUDIO  type1=AUDIO
1111111111------t0=19968000  t1=19989000  filter=19840000  recorder=18800000  type0=AUDIO  type1=AUDIO
1111111111t0=19877000  t1=19910000  filter=18880000  recorder=18800000  type0=VIDEO  type1=VIDEO
1111111111------t0=19989000  t1=20010000  filter=19861333  recorder=18900000  type0=AUDIO  type1=AUDIO
change filter restart:
------t0=20032000  t1=20053000  filter=0  recorder=18900000  type0=AUDIO  type1=AUDIO
------t0=20074000  t1=20096000  filter=42666  recorder=18900000  type0=AUDIO  type1=AUDIO
------t0=20096000  t1=20117000  filter=64000  recorder=18900000  type0=AUDIO  type1=AUDIO
------t0=20138000  t1=20160000  filter=106666  recorder=18900000  type0=AUDIO  type1=AUDIO
t0=20043000  t1=20077000  filter=80000  recorder=18900000  type0=VIDEO  type1=VIDEO
------t0=20160000  t1=20181000  filter=128000  recorder=20100000  type0=AUDIO  type1=AUDIO
------t0=20202000  t1=20224000  filter=170666  recorder=20100000  type0=AUDIO  type1=AUDIO
t0=20110000  t1=20143000  filter=160000  recorder=20100000  type0=VIDEO  type1=VIDEO
------t0=20224000  t1=20245000  filter=192000  recorder=20166667  type0=AUDIO  type1=AUDIO
------t0=20266000  t1=20288000  filter=234666  recorder=20166667  type0=AUDIO  type1=AUDIO
------t0=20309000  t1=20330000  filter=277333  recorder=20166667  type0=AUDIO  type1=AUDIO
t0=20210000  t1=20243000  filter=240000  recorder=20166667  type0=VIDEO  type1=VIDEO
------t0=20330000  t1=20352000  filter=298666  recorder=20266667  type0=AUDIO  type1=AUDIO
------t0=20373000  t1=20394000  filter=341333  recorder=20266667  type0=AUDIO  type1=AUDIO
t0=20277000  t1=20310000  filter=320000  recorder=20266667  type0=VIDEO  type1=VIDEO
------t0=20394000  t1=20416000  filter=362666  recorder=20333333  type0=AUDIO  type1=AUDIO
------t0=20437000  t1=20458000  filter=405333  recorder=20333333  type0=AUDIO  type1=AUDIO
t0=20343000  t1=20377000  filter=400000  recorder=20333333  type0=VIDEO  type1=VIDEO
------t0=20458000  t1=20480000  filter=426666  recorder=20400000  type0=AUDIO  type1=AUDIO
------t0=20501000  t1=20522000  filter=469333  recorder=20400000  type0=AUDIO  type1=AUDIO
t0=20410000  t1=20443000  filter=440000  recorder=20400000  type0=VIDEO  type1=VIDEO
------t0=20522000  t1=20544000  filter=490666  recorder=20466667  type0=AUDIO  type1=AUDIO
------t0=20565000  t1=20586000  filter=533333  recorder=20466667  type0=AUDIO  type1=AUDIO
------t0=20608000  t1=20629000  filter=576000  recorder=20466667  type0=AUDIO  type1=AUDIO
t0=20510000  t1=20543000  filter=560000  recorder=20466667  type0=VIDEO  type1=VIDEO``
saudet commented 1 year ago

We need to set those timestamps manually, but it shouldn't be too hard.

libenli commented 1 year ago

We need to set those timestamps manually, but it shouldn't be too hard.

Manually set the timestamp, as long as it is last set to the timestamp of the recorder frame, while the input frame and filtered frame do not need to set the timestamp. Am I correct in this understanding?

libenli commented 1 year ago

In this case, the audio also needs to calculate the timestamp, which is separated from the video, right?

saudet commented 1 year ago

FFmpegFrameFilter does use Frame.timestamp because it's needed by some filters, so if you use filters like that, you'll need to set it on the frames as well, either audio or video frames. For FFmpegFrameRecorder, it's going to calculate it based the sample rate and the video frame rate by default, but you can use setTimestamp() to change it for video streams that support it, but audio streams don't support it.