Recherche avancée

Médias (91)

Autres articles (84)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • Menus personnalisés

    14 novembre 2010, par

    MediaSPIP utilise le plugin Menus pour gérer plusieurs menus configurables pour la navigation.
    Cela permet de laisser aux administrateurs de canaux la possibilité de configurer finement ces menus.
    Menus créés à l’initialisation du site
    Par défaut trois menus sont créés automatiquement à l’initialisation du site : Le menu principal ; Identifiant : barrenav ; Ce menu s’insère en général en haut de la page après le bloc d’entête, son identifiant le rend compatible avec les squelettes basés sur Zpip ; (...)

  • Gestion de la ferme

    2 mars 2010, par

    La ferme est gérée dans son ensemble par des "super admins".
    Certains réglages peuvent être fais afin de réguler les besoins des différents canaux.
    Dans un premier temps il utilise le plugin "Gestion de mutualisation"

Sur d’autres sites (8080)

  • Audio Video Mixing - Sync issue in Android with FFMPEG, Media Codec in different devices

    24 novembre 2020, par khushbu

    I have already tried everything for Audio Video mixing and it's not working perfectly as in processing while mixing audio into the recorded video, sometimes the audio is ahead of video and vice-versa.

    


    Using FFMPEG :

    


    This is for add an Audio file to the Video file and generated the final Video where audio is replaced in the video.

    


    val cmd ="-i $inputVideoPath -i ${inputAudio.absolutePath} -map 0:v -map 1:a -c:v copy -shortest ${outputVideo.absolutePath}"


    


    After generating the final video, found some delay based on device performance so added delay in the below two cases :

    


    1)Added delay in Audio if audio is ahead of the video.

    


    val  cmd =  "-i ${tmpVideo.absolutePath} -itsoffset $hms -i ${tmpVideo.absolutePath} -map 0:v -map 1:a -c copy -preset veryfast ${createdVideo1?.absolutePath}"


    


    2)Added delay in Video if the video is ahead of the audio.

    


    val  cmd =   "-i ${tmpVideo.absolutePath} -itsoffset $hms -i ${tmpVideo.absolutePath} -map 1:v -map 0:a -c copy -preset veryfast ${createdVideo1?.absolutePath}"


    


    NOTE : Here $hms is delay in 00:00:00.000 formate

    


    but still, it's not working on all the devices like readmi, oneplus etc.

    


    Using Media Codec :

    


    Found some better performance in this solution but still not working on all the devices.

    


    In this process, It's supporting .aac format so first if the user selected .mp3 formate than i have to convert it into .aac format using the below function :

    


    fun Convert_Mp3_to_acc() {

   
    AndroidAudioConverter.load(requireActivity(), object : ILoadCallback {
        override fun onSuccess() {

            val callback: IConvertCallback = object : IConvertCallback {
                override fun onSuccess(convertedFile: File) {
                    toggleLoader(false)
                    audioLink = convertedFile.absolutePath
                    append()
                 

                }

                override fun onFailure(error: java.lang.Exception) {
                    toggleLoader(false)
                    Toast.makeText(requireActivity(), "" + error, Toast.LENGTH_SHORT).show()
                }
            }
            AndroidAudioConverter.with(requireActivity())
                .setFile(File(audioLink))
                .setFormat(AudioFormat.AAC)
                .setCallback(callback)
                .convert()
        }

        override fun onFailure(error: java.lang.Exception) {
            toggleLoader(false)
        }
    })
}


    


    After successful conversion from .mp3 to .aac formate, It's extracting audio track and video track for merge

    


     private fun append(): Boolean {&#xA;&#xA;    val progressDialog = ProgressDialog(requireContext())&#xA;    Thread {&#xA;        requireActivity().runOnUiThread {&#xA;            progressDialog.setMessage("Please wait..")&#xA;            progressDialog.show()&#xA;        }&#xA;        val video_list = ArrayList<string>()&#xA;        for (i in videopaths.indices) {&#xA;            val file: File = File(videopaths.get(i))&#xA;            if (file.exists()) {&#xA;                val retriever = MediaMetadataRetriever()&#xA;                retriever.setDataSource(requireActivity(), Uri.fromFile(file))&#xA;                val hasVideo =&#xA;                    retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_VIDEO)&#xA;                val isVideo = "yes" == hasVideo&#xA;                if (isVideo /*&amp;&amp; file.length() > 1000*/) {&#xA;                    Log.d("resp", videopaths.get(i))&#xA;                    video_list.add(videopaths.get(i))&#xA;                }&#xA;            }&#xA;        }&#xA;        try {&#xA;            val inMovies = arrayOfNulls<movie>(video_list.size)&#xA;            for (i in video_list.indices) {&#xA;                inMovies[i] = MovieCreator.build(video_list[i])&#xA;            }&#xA;            val videoTracks: MutableList<track> =&#xA;                LinkedList()&#xA;            val audioTracks: MutableList<track> =&#xA;                LinkedList()&#xA;            for (m in inMovies) {&#xA;                for (t in m!!.tracks) {&#xA;                    if (t.handler == "soun") {&#xA;                        audioTracks.add(t)&#xA;                    }&#xA;                    if (t.handler == "vide") {&#xA;                        videoTracks.add(t)&#xA;                    }&#xA;                }&#xA;            }&#xA;            val result = Movie()&#xA;            if (audioTracks.size > 0) {&#xA;                result.addTrack(AppendTrack(*audioTracks.toTypedArray()))&#xA;            }&#xA;            if (videoTracks.size > 0) {&#xA;                result.addTrack(AppendTrack(*videoTracks.toTypedArray()))&#xA;            }&#xA;            val out = DefaultMp4Builder().build(result)&#xA;            var outputFilePath: String? = null&#xA;            outputFilePath =  Variables.outputfile&#xA;&#xA;            /*if (audio != null) {&#xA;                Variables.outputfile&#xA;            } else {&#xA;                Variables.outputfile2&#xA;            }*/&#xA;&#xA;            val fos = FileOutputStream(File(outputFilePath))&#xA;            out.writeContainer(fos.channel)&#xA;            fos.close()&#xA;&#xA;            requireActivity().runOnUiThread {&#xA;                progressDialog.dismiss()&#xA;&#xA;                Merge_withAudio()&#xA;&#xA;                /* if (audio != null) else {&#xA;                     //Go_To_preview_Activity()&#xA;                 }*/&#xA;            }&#xA;        } catch (e: java.lang.Exception) {&#xA;        }&#xA;    }.start()&#xA;&#xA;    return true&#xA;}&#xA;</track></track></movie></string>

    &#xA;

    This will add the selected audio with the recorded video

    &#xA;

    fun Merge_withAudio() {&#xA;    val root = Environment.getExternalStorageDirectory().toString()&#xA;&#xA;    // Uri mediaPath = Uri.parse("android.resource://" &#x2B; getPackageName() &#x2B; "/" &#x2B; R.raw.file_copy);&#xA;    //String audio_file =Variables.app_folder&#x2B;Variables.SelectedAudio_AAC;&#xA;&#xA;    //String filename = "android.resource://" &#x2B; getPackageName() &#x2B; "/raw/file_copy.aac";&#xA;    val audio_file: String = audioLink!!&#xA;    Log.e("Merge ", audio_file)&#xA;    val video = "$root/output.mp4"&#xA;&#xA;    val bundle=Bundle()&#xA;    bundle.putString("FinalVideo", createdVideo?.absolutePath)&#xA;&#xA;    val merge_video_audio = Merge_Video_Audio(this, bundle, object : AsyncResponse {&#xA;        override fun processFinish(output: Bundle?) {&#xA;&#xA;            requireActivity().runOnUiThread {&#xA;                finalVideo = bundle.getString("FinalVideo")&#xA;                createdVideo = File(finalVideo)&#xA;&#xA;                Log.e("Final Path ", finalVideo)&#xA;&#xA;                createThumb {&#xA;                    setUpExoPlayer()&#xA;                }&#xA;            }&#xA;&#xA;        }&#xA;    })&#xA;    merge_video_audio.doInBackground(audio_file, video, createdVideo?.absolutePath)&#xA;}&#xA;&#xA;&#xA; public class Merge_Video_Audio extends AsyncTask {&#xA;&#xA;   ProgressDialog progressDialog;&#xA;   RecentCompletedVideoFragment context;&#xA;   public AsyncResponse delegate = null;&#xA;&#xA;&#xA;Bundle bundleValue;&#xA;&#xA;String audio,video,output;&#xA;&#xA;public Merge_Video_Audio(RecentCompletedVideoFragment context, Bundle bundle , AsyncResponse delegate ){&#xA;    this.context=context;&#xA;    this.bundleValue=bundle;&#xA;    this.delegate=delegate;&#xA;    progressDialog=new ProgressDialog(context.requireContext());&#xA;    progressDialog.setMessage("Please Wait...");&#xA;}&#xA;&#xA;@Override&#xA;protected void onPreExecute() {&#xA;    super.onPreExecute();&#xA;}&#xA;&#xA;@Override&#xA;public String doInBackground(String... strings) {&#xA;    try {&#xA;        progressDialog.show();&#xA;    }catch (Exception e){&#xA;&#xA;    }&#xA;     audio=strings[0];&#xA;     video=strings[1];&#xA;     output=strings[2];&#xA;&#xA;     Log.d("resp",audio&#x2B;"----"&#x2B;video&#x2B;"-----"&#x2B;output);&#xA;&#xA;    Thread thread = new Thread(runnable);&#xA;    thread.start();&#xA;&#xA;    return null;&#xA;}&#xA;&#xA;&#xA;@Override&#xA;protected void onPostExecute(String s) {&#xA;    super.onPostExecute(s);&#xA;    Log.e("On Post Execute ", "True");&#xA;&#xA;&#xA;}&#xA;&#xA;&#xA;   public void Go_To_preview_Activity(){&#xA;&#xA;    delegate.processFinish(bundleValue);&#xA;   }&#xA;&#xA;  public Track CropAudio(String videopath, Track fullAudio){&#xA;    try {&#xA;&#xA;        IsoFile isoFile = new IsoFile(videopath);&#xA;&#xA;        double lengthInSeconds = (double)&#xA;                isoFile.getMovieBox().getMovieHeaderBox().getDuration() /&#xA;                isoFile.getMovieBox().getMovieHeaderBox().getTimescale();&#xA;&#xA;&#xA;        Track audioTrack = (Track) fullAudio;&#xA;&#xA;&#xA;        double startTime1 = 0;&#xA;        double endTime1 = lengthInSeconds;&#xA;&#xA;&#xA;        long currentSample = 0;&#xA;        double currentTime = 0;&#xA;        double lastTime = -1;&#xA;        long startSample1 = -1;&#xA;        long endSample1 = -1;&#xA;&#xA;&#xA;        for (int i = 0; i &lt; audioTrack.getSampleDurations().length; i&#x2B;&#x2B;) {&#xA;&#xA;            long delta = audioTrack.getSampleDurations()[i];&#xA;&#xA;            if (currentTime > lastTime &amp;&amp; currentTime &lt;= startTime1) {&#xA;                // current sample is still before the new starttime&#xA;                startSample1 = currentSample;&#xA;            }&#xA;            if (currentTime > lastTime &amp;&amp; currentTime &lt;= endTime1) {&#xA;                // current sample is after the new start time and still before the new endtime&#xA;                endSample1 = currentSample;&#xA;            }&#xA;&#xA;            lastTime = currentTime;&#xA;            currentTime &#x2B;= (double) delta / (double) audioTrack.getTrackMetaData().getTimescale();&#xA;            currentSample&#x2B;&#x2B;;&#xA;        }&#xA;&#xA;        CroppedTrack cropperAacTrack = new CroppedTrack(fullAudio, startSample1, endSample1);&#xA;&#xA;        return cropperAacTrack;&#xA;&#xA;    } catch (IOException e) {&#xA;        e.printStackTrace();&#xA;    }&#xA;&#xA;    return fullAudio;&#xA;}&#xA;&#xA;&#xA;&#xA;  public Runnable runnable =new Runnable() {&#xA;    @Override&#xA;    public void run() {&#xA;&#xA;        try {&#xA;&#xA;            Movie m = MovieCreator.build(video);&#xA;&#xA;&#xA;            List nuTracks = new ArrayList&lt;>();&#xA;&#xA;            for (Track t : m.getTracks()) {&#xA;                if (!"soun".equals(t.getHandler())) {&#xA;&#xA;                    Log.e("Track  ",t.getName());&#xA;                    nuTracks.add(t);&#xA;                }&#xA;            }&#xA;&#xA;            Log.e("Path ",audio.toString());&#xA;&#xA;&#xA;            try {&#xA;                // Track nuAudio = new AACTrackImpl();&#xA;                Track nuAudio = new AACTrackImpl(new FileDataSourceImpl(audio));&#xA;&#xA;                Track crop_track = CropAudio(video, nuAudio);&#xA;&#xA;                nuTracks.add(crop_track);&#xA;&#xA;                m.setTracks(nuTracks);&#xA;&#xA;                Container mp4file = new DefaultMp4Builder().build(m);&#xA;&#xA;                FileChannel fc = new FileOutputStream(new File(output)).getChannel();&#xA;                mp4file.writeContainer(fc);&#xA;                fc.close();&#xA;&#xA;            }catch (FileNotFoundException fnfe){&#xA;                fnfe.printStackTrace();&#xA;            }catch(IOException ioe){&#xA;                ioe.printStackTrace();&#xA;           }&#xA;&#xA;&#xA;            try {&#xA;&#xA;                progressDialog.dismiss();&#xA;            }catch (Exception e){&#xA;                Log.d("resp",e.toString());&#xA;&#xA;            }finally {&#xA;                Go_To_preview_Activity();&#xA;&#xA;            }&#xA;&#xA;        } catch (IOException e) {&#xA;            e.printStackTrace();&#xA;            Log.d("resp",e.toString());&#xA;&#xA;        }&#xA;&#xA;    }&#xA;&#xA; };&#xA;&#xA; }&#xA;

    &#xA;

    This solution is also not working in all the devices.

    &#xA;

    Can anyone suggest where i am going wrong or any solution for it ?

    &#xA;

  • Corrupt AVFrame returned by libavcodec

    2 janvier 2015, par informer2000

    As part of a bigger project, I’m trying to decode a number of HD (1920x1080) video streams simultaneously. Each video stream is stored in raw yuv420p format within an AVI container. I have a Decoder class from which I create a number of objects within different threads (one object per thread). The two main methods in Decoder are decode() and getNextFrame(), which I provide the implementation for below.

    When I separate the decoding logic and use it to decode a single stream, everything works fine. However, when I use the multi-threaded code, I get a segmentation fault and the program crashes within the processing code in the decoding loop. After some investigation, I realized that the data array of the AVFrame filled in getNextFrame() contains addresses which are out of range (according to gdb).

    I’m really lost here ! I’m not doing anything that would change the contents of the AVFrame in my code. The only place where I attempt to access the AVFrame is when I call sws_scale() to convert the color format and that’s where the segmentation fault occurs in the second case because of the corrupt AVFrame. Any suggestion as to why this is happening is greatly appreciated. Thanks in advance.

    The decode() method :

    void decode() {

       QString filename("video.avi");

       AVFormatContext* container = 0;

       if (avformat_open_input(&amp;container, filename.toStdString().c_str(), NULL, NULL) &lt; 0) {
           fprintf(stderr, "Could not open %s\n", filename.toStdString().c_str());
           exit(1);
       }

       if (avformat_find_stream_info(container, NULL) &lt; 0) {
           fprintf(stderr, "Could not find file info..\n");
       }

       // find a video stream
       int stream_id = -1;
       for (unsigned int i = 0; i &lt; container->nb_streams; i++) {
           if (container->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
               stream_id = i;
               break;
           }
       }

       if (stream_id == -1) {
           fprintf(stderr, "Could not find a video stream..\n");
       }

       av_dump_format(container, stream_id, filename.toStdString().c_str(), false);

       // find the appropriate codec and open it
       AVCodecContext* codec_context = container->streams[stream_id]->codec;   // Get a pointer to the codec context for the video stream

       AVCodec* codec = avcodec_find_decoder(codec_context->codec_id);  // Find the decoder for the video stream

       if (codec == NULL) {
           fprintf(stderr, "Could not find a suitable codec..\n");
           return -1; // Codec not found
       }


       // Inform the codec that we can handle truncated bitstreams -- i.e.,
       // bitstreams where frame boundaries can fall in the middle of packets
       if (codec->capabilities &amp; CODEC_CAP_TRUNCATED)
           codec_context->flags |= CODEC_FLAG_TRUNCATED;

       fprintf(stderr, "Codec: %s\n", codec->name);

       // open the codec
       int ret = avcodec_open2(codec_context, codec, NULL);
       if (ret &lt; 0) {
           fprintf(stderr, "Could not open the needed codec.. Error: %d\n", ret);
           return -1;
       }


       // allocate video frame
       AVFrame *frame = avcodec_alloc_frame();  // deprecated, should use av_frame_alloc() instead

       if (!frame) {
           fprintf(stderr, "Could not allocate video frame..\n");
           return -1;
       }

       int frameNumber = 0;

       // as long as there are remaining frames in the stream
       while  (getNextFrame(container, codec_context, stream_id, frame)) {

           // Processing logic here...
           // AVFrame data array contains three addresses which are out of range

       }

       // freeing resources
       av_free(frame);

       avcodec_close(codec_context);

       avformat_close_input(&amp;container);
    }

    The getNextFrame() method :

    bool getNextFrame(AVFormatContext *pFormatCtx,
                     AVCodecContext *pCodecCtx,
                     int videoStream,
                     AVFrame *pFrame) {

       uint8_t inbuf[INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];

       char buf[1024];

       int len;

       int got_picture;
       AVPacket avpkt;

       av_init_packet(&amp;avpkt);

       memset(inbuf + INBUF_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE);

       // read data from bit stream and store it in the AVPacket object
       while(av_read_frame(pFormatCtx, &amp;avpkt) >= 0) {

           // check the stream index of the read packet to make sure it is a video stream
           if(avpkt.stream_index == videoStream) {

               // decode the packet and store the decoded content in the AVFrame object and set the flag if we have a complete decoded picture
               avcodec_decode_video2(pCodecCtx, pFrame, &amp;got_picture, &amp;avpkt);

               // if we have completed decoding an entire picture (frame), return true
               if(got_picture) {

                   av_free_packet(&amp;avpkt);

                   return true;
               }
           }

           // free the AVPacket object that was allocated by av_read_frame
           av_free_packet(&amp;avpkt);
       }

       return false;

    }

    The lock management callback function :

    static int lock_call_back(void ** mutex, enum AVLockOp op) {
       switch (op) {
           case AV_LOCK_CREATE:
               *mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
               pthread_mutex_init((pthread_mutex_t *)(*mutex), NULL);
               break;
           case AV_LOCK_OBTAIN:
               pthread_mutex_lock((pthread_mutex_t *)(*mutex));
               break;
           case AV_LOCK_RELEASE:
               pthread_mutex_unlock((pthread_mutex_t *)(*mutex));
               break;
           case AV_LOCK_DESTROY:
               pthread_mutex_destroy((pthread_mutex_t *)(*mutex));
               free(*mutex);
               break;
       }

       return 0;
    }
  • Wrap audio data of the pcm_alaw type into an MKA audio file using the ffmpeg API

    19 septembre 2020, par bbdd

    Imagine that in my project, I receive RTP packets with the payload type-8, for later saving this load as the Nth part of the audio track. I extract this load from the RTP packet and save it to a temporary buffer :

    &#xA;

    ...&#xA;&#xA;while ((rtp = receiveRtpPackets()).withoutErrors()) {&#xA;   payloadData.push(rtp.getPayloadData());&#xA;}&#xA;&#xA;audioGenerator.setPayloadData(payloadData);&#xA;audioGenerator.recordToFile();&#xA;&#xA;...&#xA;

    &#xA;

    After filling a temporary buffer of a certain size with this payload, I process this buffer, namely, extract the entire payload and encode it using ffmpeg for further saving to an audio file in Matroska format. But I have a problem. Since the payload of the RTP packet is type 8, I have to save the raw audio data of the pcm_alaw format to mka audio format. But when saving raw data pcm_alaw to an audio file, I get these messages from the library :

    &#xA;

    ...&#xA;&#xA;[libopus @ 0x18eff60] Queue input is backward in time&#xA;[libopus @ 0x18eff60] Queue input is backward in time&#xA;[libopus @ 0x18eff60] Queue input is backward in time&#xA;[libopus @ 0x18eff60] Queue input is backward in time&#xA;&#xA;...&#xA;

    &#xA;

    When you open an audio file in vlc, nothing is played (the audio track timestamp is missing).

    &#xA;

    The task of my project is to simply take pcm_alaw data and pack it in a container, in mka format. The best way to determine the codec is to use the av_guess_codec() function, which in turn automatically selects the desired codec ID. But how do I pack the raw data into the container correctly, I do not know.

    &#xA;

    It is important to note that I can get as raw data any format of this data (audio formats only) defined by the RTP packet type (All types of RTP packet payload). All I know is that in any case, I have to pack the audio data in an mka container.

    &#xA;

    I also attach the code (borrowed from this resource) that I use :

    &#xA;

    audiogenerater.h

    &#xA;

    extern "C"&#xA;{&#xA;#include "libavformat/avformat.h"&#xA;#include "libavcodec/avcodec.h"&#xA;#include "libswresample/swresample.h"&#xA;}&#xA;&#xA;class AudioGenerater&#xA;{&#xA;public:&#xA;&#xA;    AudioGenerater();&#xA;   ~AudioGenerater() = default;&#xA;&#xA;    void generateAudioFileWithOptions(&#xA;            QString        fileName,&#xA;            QByteArray     pcmData,&#xA;            int            channel,&#xA;            int            bitRate,&#xA;            int            sampleRate,&#xA;            AVSampleFormat format);&#xA;            &#xA;private:&#xA;&#xA;    // init Format&#xA;    bool initFormat(QString audioFileName);&#xA;&#xA;private:&#xA;&#xA;    AVCodec         *m_AudioCodec        = nullptr;&#xA;    AVCodecContext  *m_AudioCodecContext = nullptr;&#xA;    AVFormatContext *m_FormatContext     = nullptr;&#xA;    AVOutputFormat  *m_OutputFormat      = nullptr;&#xA;};&#xA;

    &#xA;

    audiogenerater.cpp

    &#xA;

    AudioGenerater::AudioGenerater()&#xA;{&#xA;    av_register_all();&#xA;    avcodec_register_all();&#xA;}&#xA;&#xA;AudioGenerater::~AudioGenerater()&#xA;{&#xA;    // ... &#xA;}&#xA;&#xA;bool AudioGenerater::initFormat(QString audioFileName)&#xA;{&#xA;    // Create an output Format context&#xA;    int result = avformat_alloc_output_context2(&amp;m_FormatContext, nullptr, nullptr, audioFileName.toLocal8Bit().data());&#xA;    if (result &lt; 0) {&#xA;        return false;&#xA;    }&#xA;&#xA;    m_OutputFormat = m_FormatContext->oformat;&#xA;&#xA;    // Create an audio stream&#xA;    AVStream* audioStream = avformat_new_stream(m_FormatContext, m_AudioCodec);&#xA;    if (audioStream == nullptr) {&#xA;        avformat_free_context(m_FormatContext);&#xA;        return false;&#xA;    }&#xA;&#xA;    // Set the parameters in the stream&#xA;    audioStream->id = m_FormatContext->nb_streams - 1;&#xA;    audioStream->time_base = { 1, 8000 };&#xA;    result = avcodec_parameters_from_context(audioStream->codecpar, m_AudioCodecContext);&#xA;    if (result &lt; 0) {&#xA;        avformat_free_context(m_FormatContext);&#xA;        return false;&#xA;    }&#xA;&#xA;    // Print FormatContext information&#xA;    av_dump_format(m_FormatContext, 0, audioFileName.toLocal8Bit().data(), 1);&#xA;&#xA;    // Open file IO&#xA;    if (!(m_OutputFormat->flags &amp; AVFMT_NOFILE)) {&#xA;        result = avio_open(&amp;m_FormatContext->pb, audioFileName.toLocal8Bit().data(), AVIO_FLAG_WRITE);&#xA;        if (result &lt; 0) {&#xA;            avformat_free_context(m_FormatContext);&#xA;            return false;&#xA;        }&#xA;    }&#xA;&#xA;    return true;&#xA;}&#xA;&#xA;void AudioGenerater::generateAudioFileWithOptions(&#xA;    QString _fileName,&#xA;    QByteArray _pcmData,&#xA;    int _channel,&#xA;    int _bitRate,&#xA;    int _sampleRate,&#xA;    AVSampleFormat _format)&#xA;{&#xA;    AVFormatContext* oc;&#xA;    if (avformat_alloc_output_context2(&#xA;            &amp;oc, nullptr, nullptr, _fileName.toStdString().c_str())&#xA;        &lt; 0) {&#xA;        qDebug() &lt;&lt; "Error in line: " &lt;&lt; __LINE__;&#xA;        return;&#xA;    }&#xA;    if (!oc) {&#xA;        printf("Could not deduce output format from file extension: using mka.\n");&#xA;        avformat_alloc_output_context2(&#xA;            &amp;oc, nullptr, "mka", _fileName.toStdString().c_str());&#xA;    }&#xA;    if (!oc) {&#xA;        qDebug() &lt;&lt; "Error in line: " &lt;&lt; __LINE__;&#xA;        return;&#xA;    }&#xA;    AVOutputFormat* fmt = oc->oformat;&#xA;    if (fmt->audio_codec == AV_CODEC_ID_NONE) {&#xA;        qDebug() &lt;&lt; "Error in line: " &lt;&lt; __LINE__;&#xA;        return;&#xA;    }&#xA;&#xA;    AVCodecID codecID = av_guess_codec(&#xA;        fmt, nullptr, _fileName.toStdString().c_str(), nullptr, AVMEDIA_TYPE_AUDIO);&#xA;    // Find Codec&#xA;    m_AudioCodec = avcodec_find_encoder(codecID);&#xA;    if (m_AudioCodec == nullptr) {&#xA;        qDebug() &lt;&lt; "Error in line: " &lt;&lt; __LINE__;&#xA;        return;&#xA;    }&#xA;    // Create an encoder context&#xA;    m_AudioCodecContext = avcodec_alloc_context3(m_AudioCodec);&#xA;    if (m_AudioCodecContext == nullptr) {&#xA;        qDebug() &lt;&lt; "Error in line: " &lt;&lt; __LINE__;&#xA;        return;&#xA;    }&#xA;&#xA;    // Setting parameters&#xA;    m_AudioCodecContext->bit_rate = _bitRate;&#xA;    m_AudioCodecContext->sample_rate = _sampleRate;&#xA;    m_AudioCodecContext->sample_fmt = _format;&#xA;    m_AudioCodecContext->channels = _channel;&#xA;&#xA;    m_AudioCodecContext->channel_layout = av_get_default_channel_layout(_channel);&#xA;    m_AudioCodecContext->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;&#xA;&#xA;    // Turn on the encoder&#xA;    int result = avcodec_open2(m_AudioCodecContext, m_AudioCodec, nullptr);&#xA;    if (result &lt; 0) {&#xA;        avcodec_free_context(&amp;m_AudioCodecContext);&#xA;        if (m_FormatContext != nullptr)&#xA;            avformat_free_context(m_FormatContext);&#xA;        return;&#xA;    }&#xA;&#xA;    // Create a package&#xA;    if (!initFormat(_fileName)) {&#xA;        avcodec_free_context(&amp;m_AudioCodecContext);&#xA;        if (m_FormatContext != nullptr)&#xA;            avformat_free_context(m_FormatContext);&#xA;        return;&#xA;    }&#xA;&#xA;    // write to the file header&#xA;    result = avformat_write_header(m_FormatContext, nullptr);&#xA;    if (result &lt; 0) {&#xA;        avcodec_free_context(&amp;m_AudioCodecContext);&#xA;        if (m_FormatContext != nullptr)&#xA;            avformat_free_context(m_FormatContext);&#xA;        return;&#xA;    }&#xA;&#xA;    // Create Frame&#xA;    AVFrame* frame = av_frame_alloc();&#xA;    if (frame == nullptr) {&#xA;        avcodec_free_context(&amp;m_AudioCodecContext);&#xA;        if (m_FormatContext != nullptr)&#xA;            avformat_free_context(m_FormatContext);&#xA;        return;&#xA;    }&#xA;&#xA;    int nb_samples = 0;&#xA;    if (m_AudioCodecContext->codec->capabilities &amp; AV_CODEC_CAP_VARIABLE_FRAME_SIZE) {&#xA;        nb_samples = 10000;&#xA;    }&#xA;    else {&#xA;        nb_samples = m_AudioCodecContext->frame_size;&#xA;    }&#xA;&#xA;    // Set the parameters of the Frame&#xA;    frame->nb_samples = nb_samples;&#xA;    frame->format = m_AudioCodecContext->sample_fmt;&#xA;    frame->channel_layout = m_AudioCodecContext->channel_layout;&#xA;&#xA;    // Apply for data memory&#xA;    result = av_frame_get_buffer(frame, 0);&#xA;    if (result &lt; 0) {&#xA;        av_frame_free(&amp;frame);&#xA;        {&#xA;            avcodec_free_context(&amp;m_AudioCodecContext);&#xA;            if (m_FormatContext != nullptr)&#xA;                avformat_free_context(m_FormatContext);&#xA;            return;&#xA;        }&#xA;    }&#xA;&#xA;    // Set the Frame to be writable&#xA;    result = av_frame_make_writable(frame);&#xA;    if (result &lt; 0) {&#xA;        av_frame_free(&amp;frame);&#xA;        {&#xA;            avcodec_free_context(&amp;m_AudioCodecContext);&#xA;            if (m_FormatContext != nullptr)&#xA;                avformat_free_context(m_FormatContext);&#xA;            return;&#xA;        }&#xA;    }&#xA;&#xA;    int perFrameDataSize = frame->linesize[0];&#xA;    int count = _pcmData.size() / perFrameDataSize;&#xA;    bool needAddOne = false;&#xA;    if (_pcmData.size() % perFrameDataSize != 0) {&#xA;        count&#x2B;&#x2B;;&#xA;        needAddOne = true;&#xA;    }&#xA;&#xA;    int frameCount = 0;&#xA;    for (int i = 0; i &lt; count; &#x2B;&#x2B;i) {&#xA;        // Create a Packet&#xA;        AVPacket* pkt = av_packet_alloc();&#xA;        if (pkt == nullptr) {&#xA;            avcodec_free_context(&amp;m_AudioCodecContext);&#xA;            if (m_FormatContext != nullptr)&#xA;                avformat_free_context(m_FormatContext);&#xA;            return;&#xA;        }&#xA;        av_init_packet(pkt);&#xA;&#xA;        if (i == count - 1)&#xA;            perFrameDataSize = _pcmData.size() % perFrameDataSize;&#xA;&#xA;        // Synthesize WAV files&#xA;        memset(frame->data[0], 0, perFrameDataSize);&#xA;        memcpy(frame->data[0], &amp;(_pcmData.data()[perFrameDataSize * i]), perFrameDataSize);&#xA;&#xA;        frame->pts = frameCount&#x2B;&#x2B;;&#xA;        // send Frame&#xA;        result = avcodec_send_frame(m_AudioCodecContext, frame);&#xA;        if (result &lt; 0)&#xA;            continue;&#xA;&#xA;        // Receive the encoded Packet&#xA;        result = avcodec_receive_packet(m_AudioCodecContext, pkt);&#xA;        if (result &lt; 0) {&#xA;            av_packet_free(&amp;pkt);&#xA;            continue;&#xA;        }&#xA;&#xA;        // write to file&#xA;        av_packet_rescale_ts(pkt, m_AudioCodecContext->time_base, m_FormatContext->streams[0]->time_base);&#xA;        pkt->stream_index = 0;&#xA;        result = av_interleaved_write_frame(m_FormatContext, pkt);&#xA;        if (result &lt; 0)&#xA;            continue;&#xA;&#xA;        av_packet_free(&amp;pkt);&#xA;    }&#xA;&#xA;    // write to the end of the file&#xA;    av_write_trailer(m_FormatContext);&#xA;    // Close file IO&#xA;    avio_closep(&amp;m_FormatContext->pb);&#xA;    // Release Frame memory&#xA;    av_frame_free(&amp;frame);&#xA;&#xA;    avcodec_free_context(&amp;m_AudioCodecContext);&#xA;    if (m_FormatContext != nullptr)&#xA;        avformat_free_context(m_FormatContext);&#xA;}&#xA;

    &#xA;

    main.cpp

    &#xA;

    int main(int argc, char **argv)&#xA;{&#xA;    av_log_set_level(AV_LOG_TRACE);&#xA;&#xA;    QFile file("rawDataOfPcmAlawType.bin");&#xA;    if (!file.open(QIODevice::ReadOnly)) {&#xA;        return EXIT_FAILURE;&#xA;    }&#xA;    QByteArray rawData(file.readAll());&#xA;&#xA;    AudioGenerater generator;&#xA;    generator.generateAudioFileWithOptions(&#xA;               "test.mka",&#xA;               rawData,&#xA;               1, &#xA;               64000, &#xA;               8000,&#xA;               AV_SAMPLE_FMT_S16);&#xA;&#xA;    return 0;&#xA;}&#xA;

    &#xA;

    It is IMPORTANT you help me find the most appropriate way to record pcm_alaw or a different data format in an MKA audio file.

    &#xA;

    I ask everyone who knows anything to help (there is too little time left to implement this project)

    &#xA;