МихаилллApril 17, 2020, 11:02 a.m.
Qt and ffmpeg, как работать со звуком.
Добрый день.
Так получаю данные звука:
static struct SwsContext *img_convert_ctx; int videoStream, i, numBytes, audioStream; int ret, got_picture; avformat_network_init(); //初始化FFmpeg网络模块 av_register_all(); //初始化FFMPEG 调用了这个才能正常适用编码器和解码器 AVFormatContext *pFormatCtx = NULL; //Allocate an AVFormatContext. pFormatCtx = avformat_alloc_context(); // Open video file if(avformat_open_input(&pFormatCtx, "./Wildlife.wmv", 0, 0) != 0) qDebug()<<"Couldn't open file"; if(avformat_find_stream_info(pFormatCtx, NULL) < 0) qDebug()<<"Couldn't find stream information"; av_dump_format(pFormatCtx, 0, "./Wildlife.wmv", 0);//information abaut file //vide0 AVCodecContext *pCodecCtxOrig = NULL; AVCodecContext *pCodecCtx = NULL; //audio AVCodecContext *aCodecCtxOrig; AVCodecContext *aCodecCtx; // Find the first video and audio stream videoStream = -1; audioStream = -1; for(i=0; i < pFormatCtx->nb_streams; i++) { if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO && videoStream < 0) { videoStream=i; } if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_AUDIO && audioStream < 0) { audioStream=i; } } if(videoStream==-1) qDebug()<<"Didn't find a video stream"; if(audioStream==-1) qDebug()<<"Didn't find a audio stream"; // Get a pointer to the codec context for the video stream pCodecCtx=pFormatCtx->streams[videoStream]->codec; //audio aCodecCtxOrig=pFormatCtx->streams[audioStream]->codec; //aCodecCtx=pFormatCtx->streams[audioStream]->codec; //audio AVCodec *aCodec; aCodec = avcodec_find_decoder(aCodecCtxOrig->codec_id); if(!aCodec) { qDebug()<<"Unsupported codec!"; } // Copy context aCodecCtx = avcodec_alloc_context3(aCodec); if(avcodec_copy_context(aCodecCtx, aCodecCtxOrig) != 0) { qDebug()<<"Couldn't copy codec contextt"; } /* set up SDL Audio here */ avcodec_open2(aCodecCtx, aCodec, NULL);
Так предлогается работать со звуком с помощью STL:
wanted_spec.freq = aCodecCtx->sample_rate; wanted_spec.format = AUDIO_S16SYS; wanted_spec.channels = aCodecCtx->channels; wanted_spec.silence = 0; wanted_spec.samples = SDL_AUDIO_BUFFER_SIZE; wanted_spec.callback = audio_callback; wanted_spec.userdata = aCodecCtx; if(SDL_OpenAudio(&wanted_spec, &spec) < 0) { fprintf(stderr, "SDL_OpenAudio: %s\n", SDL_GetError()); return -1; }
Начал делать так:
QAudioRecorder audioRecorder; QAudioEncoderSettings audioSettings; audioSettings.setCodec("audio/amr"); audioSettings.setQuality(QMultimedia::HighQuality); audioRecorder.setEncodingSettings(audioSettings);
Как правильно сделать воспроизведение с помощью Qt?
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
SH
- Sak Hax
- April 25, 2024, 2 p.m.
C++ - Test 001. The first program and data types
- Result:33points,
- Rating points-10
l
- laei
- April 23, 2024, 9:19 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:10points,
- Rating points-10
Last comments
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
АК
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
Анатолий КононенкоFeb. 5, 2024, 1:50 a.m.
EVADec. 25, 2023, 10:30 a.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
DA
Unlock Your Aesthetic Potential: Explore MSC in Facial Aesthetics and Cosmetology in India Embark on a transformative journey with an msc in facial aesthetics and cosmetology in india . Delve into the intricate world of beauty and rejuvenation, guided by expert faculty and …
Dr Gangil AcademicsApril 20, 2024, 7:45 a.m.
Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Евгений, добрый день! Такой вопрос. Верно ли следующее утверждение: Любое Android-приложение, написанное на Java/Kotlin чисто теоретически (пусть и с большими трудностями) можно написать и на C+…
Павел ДорофеевApril 14, 2024, 2:35 a.m.
Вернуть старое поведение QComboBox, не менять индекс при resetModel Добрый день! У нас много проектов в которых используется QComboBox, в версии 5.5.1, когда модель испускает сигнал resetModel, currentIndex не менялся. В версии 5.15 при resetModel происходит try…
Добрый день
Могу только предположение высказать, что возможно формат кодека не соответствует, а также какие-то параметры не соотносятся.
Пробовли соотнести параметры настройки кодека Qt, а также библиотеки... SDL может всё-же?
Я похоже пользовался не теми инструментами Qt. А какие точно нужня я пока не знаю.