BabitMF / bmf

Cross-platform, customizable multimedia/video processing framework. With strong GPU acceleration, heterogeneous design, multi-language support, easy to use, multi-framework compatible and high performance, the framework is ideal for transcoding, AI inference, algorithm integration, live video streaming, and more.
https://babitmf.github.io/
Apache License 2.0
802 stars 68 forks source link

how to create an audio stream #146

Open x850044053wwt opened 2 days ago

x850044053wwt commented 2 days ago

I want to construct an audio input stream with a sampling rate of 48000,apkt is an audio generator packet with a sampling rate of 44100,how to specify pts? ...... auto aframe = apkt.get<bmf_sdk::AudioFrame>(); bmf_sdk::AudioFrame af(aframe.planes(), aframe.layout(), aframe.planer()); af.set_sample_rate(aframe.sample_rate()); af.set_time_base(aframe.time_base()); af.set_pts(_video_time_stamp); auto pkt_audio = Packet(af); _video_time_stamp += 1024; _main_pipeline->FillPacket(_audio_enc_in_stream->GetName(), pkt_audio); ......

The result of the above operation is wrong

af.set_pts(_video_time_stamp);->af.set_pts(frame.pts()); is ok in single audio stream,but i need to maintain time stamp for multi input audio stream

hulibruce commented 2 days ago

To implement the resample functionality, you can resample the audio stream using FFmpeg's aresample filter, with a command like audio_stream.ff_filter('aresample', '48000').

If you choose not to use this approach, you would need to implement resampling internally. In this case, the AVFrame PTS should be adjusted based on the number of samples in the frame, and the AVPacket PTS is typically calculated as the number of samples divided by the sample rate, multiplied by 1e6 to convert it to microseconds.

x850044053wwt commented 2 days ago

To implement the resample functionality, you can resample the audio stream using FFmpeg's aresample filter, with a command like audio_stream.ff_filter('aresample', '48000').

If you choose not to use this approach, you would need to implement resampling internally. In this case, the AVFrame PTS should be adjusted based on the number of samples in the frame, and the AVPacket PTS is typically calculated as the number of samples divided by the sample rate, multiplied by 1e6 to convert it to microseconds.

Thank you for your answer. In my case, pts should be set to the value of nsamples()