Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to save naked stream in Qt fmpeg

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to save naked flow in Qt fmpeg". In daily operation, I believe that many people have doubts about how to save naked flow in Qt fmpeg. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the question of "how to save naked flow in Qt fmpeg". Next, please follow the editor to study!

I. Preface

At the beginning, ffmpeg saves video files, that is, the naked stream data is saved directly. The naked stream data is generally in H264 format. This kind of data file can be played by some players. Because it is not a standard format, many players do not support it, so you need to install the corresponding decoder. Later, it is found that after the K-Lite decoder is installed, even the player included in the system can play H264 video stream files normally, and if the aac audio files with the same name are placed in the same directory, the sound can be played synchronously. Maybe this is the player's processing.

It is basically not difficult to save the naked stream directly. The general process is to open the file first, and then write the decoded data to the file directly in the place of circular decoding. If timing storage is used, open a timer, close the file first, and then reopen the file with a new name. It should be noted here that information such as pps sps needs to be added for rtmp video stream. Therefore, before writing to the file in each frame, you should first use AVBitStreamFilter to use h364_mp4toannexb processing.

II. Functional features

Multi-thread real-time playback video stream + local video + USB camera and so on.

Support windows+linux+mac, support ffmpeg3 and ffmpeg4, support 32-bit and 64-bit.

Multi-thread display image, do not card the main interface.

Automatically reconnect the webcam.

The border size can be set, that is, the offset and the border color.

You can set whether to draw OSD tags, that is, label text or pictures and label locations.

There are two OSD locations and styles that can be set.

You can set whether to save to a file and the file name.

You can drag the file directly to the ffmpegwidget control to play.

Supports h365 video streams + rtmp and other common video streams.

Playback can be paused and resumed.

Support for storing individual video files and storing video files at regular intervals.

Customize the top suspension bar and send click signal notification, which can be set whether it is enabled or not.

Can set screen stretch fill or proportional fill.

Programmable decoding is speed priority, quality priority and balanced processing.

You can take screenshots (original pictures) and screenshots of the video.

Video file storage supports naked streaming and MP4 files.

Qsv, dxva2, d3d11va and other hard decoding are supported.

Support opengl to draw video data with very low CPU usage.

Support embedded linux, cross-compilation can be done.

Third, effect picture

4. Core code void FFmpegThread::initSave () {if (! saveFile) {return;} / / if the storage interval is greater than 0, if (saveInterval > 0) {QString dirName = QString ("% 1max% 2") .arg (savePath) .arg (QDATE); newDir (dirName) FileName = QString ("% 1/%2_%3.mp4") .arg (dirName) .arg (fileFlag) .arg (STRDATETIME); emit sig_startSave ();} if (saveMp4) {saveVideoMp4 (fileName);} else {saveVideoH264 (fileName);}} void FFmpegThread::startSave () {timerSave- > start (saveInterval * 1000) } void FFmpegThread::stopSave () {/ / stop storing files and storage timer closeVideo (); if (timerSave- > isActive ()) {timerSave- > stop ();}} void FFmpegThread::saveVideo () {if (! saveFile) {return;} / / reset file name QString dirName = QString ("% 1Acer% 2") .arg (savePath) .arg (QDATE); newDir (dirName) FileName = QString ("% 1/%2_%3.mp4") .arg (dirName) .arg (fileFlag) .arg (STRDATETIME); if (saveMp4) {saveVideoMp4 (fileName);} else {saveVideoH264 (fileName);}} void FFmpegThread::closeVideo () {if (! saveFile) {return } if (saveMp4) {if (formatOut! = NULL) {/ / write end flag av_write_trailer (formatOut); avcodec_close (formatOut- > streams [0]-> codec); av_freep (& formatOut- > streams [0]-> codec); av_freep (& formatOut- > streams [0]); avio_close (formatOut- > pb) Av_free (formatOut); initSaveOk = false; formatOut = NULL;}} else {if (fileVideo.isOpen ()) {fileVideo.close ();} if (fileAudio.isOpen ()) {fileAudio.close ();} void FFmpegThread::saveVideoH264 (const QString & fileName) {QMutexLocker locker (& mutex) CloseVideo (); if (videoStreamIndex > = 0) {fileVideo.setFileName (fileName); fileVideo.open (QFile::WriteOnly);} / / save the audio file if (audioStreamIndex > = 0 & & playAudio) {QString audioName = fileName; audioName = audioName.replace (QFileInfo (audioName). Suffix (), "aac"); fileAudio.setFileName (audioName) FileAudio.open (QFile::WriteOnly);}} at this point, the study on "how to save naked streams in Qt fmpeg" is over. I hope to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report