Recherche avancée

Médias (0)

Mot : - Tags -/objet éditorial

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (99)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

Sur d’autres sites (7574)

  • How to new & delete AVPacket ?

    18 octobre 2020, par PatrickSCLin

    I'm working with a FFmpeg project right now, I have to store the data of AVPacket which from av_read_frame, and fill data to new AVPacket for following decoding.

    


    Here is my problem : when I try to new & free an AVPacket, memory leaks always happen.

    


    I am just doing a simple testing :

    


    for(;;) {
    AVPacket pkt;
    av_new_packet(&pkt, 1000);
    av_init_packet(&pkt);
    av_free_packet(&pkt);
}


    


    What am I doing wrong ?

    


  • How to play and seek fragmented MP4 audio using MSE SourceBuffer ?

    29 juin 2024, par Stefan Falk

    Note :

    


    


    If you end up here, you might want to take a look at shaka-player and the accompanying shaka-streamer. Use it. Don't implement this yourself unless you really have to.

    


    


    I am trying for quite some time now to be able to play an audio track on Chrome, Firefox, Safari, etc. but I keep hitting brick walls. My problem is currently that I am just not able to seek within a fragmented MP4 (or MP3).

    


    At the moment I am converting audio files such as MP3 to fragmented MP4 (fMP4) and send them chunk-wise to the client. What I do is defining a CHUNK_DURACTION_SEC (chunk duration in seconds) and compute a chunk size like this :

    


    chunksTotal = Math.ceil(this.track.duration / CHUNK_DURATION_SEC);
chunkSize = Math.ceil(this.track.fileSize / this.chunksTotal);


    


    With this I partition the audio file and can fetch it entirely jumping chunkSize-many bytes for each chunk :

    


    -----------------------------------------
| chunk 1 | chunk 2 |   ...   | chunk n |
-----------------------------------------


    


    How audio files are converted to fMP4

    


    ffmpeg -i input.mp3 -acodec aac -b:a 256k -f mp4 \
       -movflags faststart+frag_every_frame+empty_moov+default_base_moof \
        output.mp4


    


    This seems to work with Chrome and Firefox (so far).

    


    How chunks are appended

    


    After following this example, and realizing that it's simply not working as it is explained here, I threw it away and started over from scratch. Unfortunately without success. It's still not working.

    


    The following code is supposed to play a track from the very beginning to the very end. However, I also need to be able to seek. So far, this is simply not working. Seeking will just stop the audio after the seeking event got triggered.

    


    The code

    


    /* Desired chunk duration in seconds. */&#xA;const CHUNK_DURATION_SEC = 20;&#xA;&#xA;const AUDIO_EVENTS = [&#xA;  &#x27;ended&#x27;,&#xA;  &#x27;error&#x27;,&#xA;  &#x27;play&#x27;,&#xA;  &#x27;playing&#x27;,&#xA;  &#x27;seeking&#x27;,&#xA;  &#x27;seeked&#x27;,&#xA;  &#x27;pause&#x27;,&#xA;  &#x27;timeupdate&#x27;,&#xA;  &#x27;canplay&#x27;,&#xA;  &#x27;loadedmetadata&#x27;,&#xA;  &#x27;loadstart&#x27;,&#xA;  &#x27;updateend&#x27;,&#xA;];&#xA;&#xA;&#xA;class ChunksLoader {&#xA;&#xA;  /** The total number of chunks for the track. */&#xA;  public readonly chunksTotal: number;&#xA;&#xA;  /** The length of one chunk in bytes */&#xA;  public readonly chunkSize: number;&#xA;&#xA;  /** Keeps track of requested chunks. */&#xA;  private readonly requested: boolean[];&#xA;&#xA;  /** URL of endpoint for fetching audio chunks. */&#xA;  private readonly url: string;&#xA;&#xA;  constructor(&#xA;    private track: Track,&#xA;    private sourceBuffer: SourceBuffer,&#xA;    private logger: NGXLogger,&#xA;  ) {&#xA;&#xA;    this.chunksTotal = Math.ceil(this.track.duration / CHUNK_DURATION_SEC);&#xA;    this.chunkSize = Math.ceil(this.track.fileSize / this.chunksTotal);&#xA;&#xA;    this.requested = [];&#xA;    for (let i = 0; i &lt; this.chunksTotal; i&#x2B;&#x2B;) {&#xA;      this.requested[i] = false;&#xA;    }&#xA;&#xA;    this.url = `${environment.apiBaseUrl}/api/tracks/${this.track.id}/play`;&#xA;  }&#xA;&#xA;  /**&#xA;   * Fetch the first chunk.&#xA;   */&#xA;  public begin() {&#xA;    this.maybeFetchChunk(0);&#xA;  }&#xA;&#xA;  /**&#xA;   * Handler for the "timeupdate" event. Checks if the next chunk should be fetched.&#xA;   *&#xA;   * @param currentTime&#xA;   *  The current time of the track which is currently played.&#xA;   */&#xA;  public handleOnTimeUpdate(currentTime: number) {&#xA;&#xA;    const nextChunkIndex = Math.floor(currentTime / CHUNK_DURATION_SEC) &#x2B; 1;&#xA;    const hasAllChunks = this.requested.every(val => !!val);&#xA;&#xA;    if (nextChunkIndex === (this.chunksTotal - 1) &amp;&amp; hasAllChunks) {&#xA;      this.logger.debug(&#x27;Last chunk. Calling mediaSource.endOfStream();&#x27;);&#xA;      return;&#xA;    }&#xA;&#xA;    if (this.requested[nextChunkIndex] === true) {&#xA;      return;&#xA;    }&#xA;&#xA;    if (currentTime &lt; CHUNK_DURATION_SEC * (nextChunkIndex - 1 &#x2B; 0.25)) {&#xA;      return;&#xA;    }&#xA;&#xA;    this.maybeFetchChunk(nextChunkIndex);&#xA;  }&#xA;&#xA;  /**&#xA;   * Fetches the chunk if it hasn&#x27;t been requested yet. After the request finished, the returned&#xA;   * chunk gets appended to the SourceBuffer-instance.&#xA;   *&#xA;   * @param chunkIndex&#xA;   *  The chunk to fetch.&#xA;   */&#xA;  private maybeFetchChunk(chunkIndex: number) {&#xA;&#xA;    const start = chunkIndex * this.chunkSize;&#xA;    const end = start &#x2B; this.chunkSize - 1;&#xA;&#xA;    if (this.requested[chunkIndex] == true) {&#xA;      return;&#xA;    }&#xA;&#xA;    this.requested[chunkIndex] = true;&#xA;&#xA;    if ((end - start) == 0) {&#xA;      this.logger.warn(&#x27;Nothing to fetch.&#x27;);&#xA;      return;&#xA;    }&#xA;&#xA;    const totalKb = ((end - start) / 1000).toFixed(2);&#xA;    this.logger.debug(`Starting to fetch bytes ${start} to ${end} (total ${totalKb} kB). Chunk ${chunkIndex &#x2B; 1} of ${this.chunksTotal}`);&#xA;&#xA;    const xhr = new XMLHttpRequest();&#xA;    xhr.open(&#x27;get&#x27;, this.url);&#xA;    xhr.setRequestHeader(&#x27;Authorization&#x27;, `Bearer ${AuthenticationService.getJwtToken()}`);&#xA;    xhr.setRequestHeader(&#x27;Range&#x27;, &#x27;bytes=&#x27; &#x2B; start &#x2B; &#x27;-&#x27; &#x2B; end);&#xA;    xhr.responseType = &#x27;arraybuffer&#x27;;&#xA;    xhr.onload = () => {&#xA;      this.logger.debug(`Range ${start} to ${end} fetched`);&#xA;      this.logger.debug(`Requested size:        ${end - start &#x2B; 1}`);&#xA;      this.logger.debug(`Fetched size:          ${xhr.response.byteLength}`);&#xA;      this.logger.debug(&#x27;Appending chunk to SourceBuffer.&#x27;);&#xA;      this.sourceBuffer.appendBuffer(xhr.response);&#xA;    };&#xA;    xhr.send();&#xA;  };&#xA;&#xA;}&#xA;&#xA;export enum StreamStatus {&#xA;  NOT_INITIALIZED,&#xA;  INITIALIZING,&#xA;  PLAYING,&#xA;  SEEKING,&#xA;  PAUSED,&#xA;  STOPPED,&#xA;  ERROR&#xA;}&#xA;&#xA;export class PlayerState {&#xA;  status: StreamStatus = StreamStatus.NOT_INITIALIZED;&#xA;}&#xA;&#xA;&#xA;/**&#xA; *&#xA; */&#xA;@Injectable({&#xA;  providedIn: &#x27;root&#x27;&#xA;})&#xA;export class MediaSourcePlayerService {&#xA;&#xA;  public track: Track;&#xA;&#xA;  private mediaSource: MediaSource;&#xA;&#xA;  private sourceBuffer: SourceBuffer;&#xA;&#xA;  private audioObj: HTMLAudioElement;&#xA;&#xA;  private chunksLoader: ChunksLoader;&#xA;&#xA;  private state: PlayerState = new PlayerState();&#xA;&#xA;  private state$ = new BehaviorSubject<playerstate>(this.state);&#xA;&#xA;  public stateChange = this.state$.asObservable();&#xA;&#xA;  private currentTime$ = new BehaviorSubject<number>(null);&#xA;&#xA;  public currentTimeChange = this.currentTime$.asObservable();&#xA;&#xA;  constructor(&#xA;    private httpClient: HttpClient,&#xA;    private logger: NGXLogger&#xA;  ) {&#xA;  }&#xA;&#xA;  get canPlay() {&#xA;    const state = this.state$.getValue();&#xA;    const status = state.status;&#xA;    return status == StreamStatus.PAUSED;&#xA;  }&#xA;&#xA;  get canPause() {&#xA;    const state = this.state$.getValue();&#xA;    const status = state.status;&#xA;    return status == StreamStatus.PLAYING || status == StreamStatus.SEEKING;&#xA;  }&#xA;&#xA;  public playTrack(track: Track) {&#xA;    this.logger.debug(&#x27;playTrack&#x27;);&#xA;    this.track = track;&#xA;    this.startPlayingFrom(0);&#xA;  }&#xA;&#xA;  public play() {&#xA;    this.logger.debug(&#x27;play()&#x27;);&#xA;    this.audioObj.play().then();&#xA;  }&#xA;&#xA;  public pause() {&#xA;    this.logger.debug(&#x27;pause()&#x27;);&#xA;    this.audioObj.pause();&#xA;  }&#xA;&#xA;  public stop() {&#xA;    this.logger.debug(&#x27;stop()&#x27;);&#xA;    this.audioObj.pause();&#xA;  }&#xA;&#xA;  public seek(seconds: number) {&#xA;    this.logger.debug(&#x27;seek()&#x27;);&#xA;    this.audioObj.currentTime = seconds;&#xA;  }&#xA;&#xA;  private startPlayingFrom(seconds: number) {&#xA;    this.logger.info(`Start playing from ${seconds.toFixed(2)} seconds`);&#xA;    this.mediaSource = new MediaSource();&#xA;    this.mediaSource.addEventListener(&#x27;sourceopen&#x27;, this.onSourceOpen);&#xA;&#xA;    this.audioObj = document.createElement(&#x27;audio&#x27;);&#xA;    this.addEvents(this.audioObj, AUDIO_EVENTS, this.handleEvent);&#xA;    this.audioObj.src = URL.createObjectURL(this.mediaSource);&#xA;&#xA;    this.audioObj.play().then();&#xA;  }&#xA;&#xA;  private onSourceOpen = () => {&#xA;&#xA;    this.logger.debug(&#x27;onSourceOpen&#x27;);&#xA;&#xA;    this.mediaSource.removeEventListener(&#x27;sourceopen&#x27;, this.onSourceOpen);&#xA;    this.mediaSource.duration = this.track.duration;&#xA;&#xA;    this.sourceBuffer = this.mediaSource.addSourceBuffer(&#x27;audio/mp4; codecs="mp4a.40.2"&#x27;);&#xA;    // this.sourceBuffer = this.mediaSource.addSourceBuffer(&#x27;audio/mpeg&#x27;);&#xA;&#xA;    this.chunksLoader = new ChunksLoader(&#xA;      this.track,&#xA;      this.sourceBuffer,&#xA;      this.logger&#xA;    );&#xA;&#xA;    this.chunksLoader.begin();&#xA;  };&#xA;&#xA;  private handleEvent = (e) => {&#xA;&#xA;    const currentTime = this.audioObj.currentTime.toFixed(2);&#xA;    const totalDuration = this.track.duration.toFixed(2);&#xA;    this.logger.warn(`MediaSource event: ${e.type} (${currentTime} of ${totalDuration} sec)`);&#xA;&#xA;    this.currentTime$.next(this.audioObj.currentTime);&#xA;&#xA;    const currentStatus = this.state$.getValue();&#xA;&#xA;    switch (e.type) {&#xA;      case &#x27;playing&#x27;:&#xA;        currentStatus.status = StreamStatus.PLAYING;&#xA;        this.state$.next(currentStatus);&#xA;        break;&#xA;      case &#x27;pause&#x27;:&#xA;        currentStatus.status = StreamStatus.PAUSED;&#xA;        this.state$.next(currentStatus);&#xA;        break;&#xA;      case &#x27;timeupdate&#x27;:&#xA;        this.chunksLoader.handleOnTimeUpdate(this.audioObj.currentTime);&#xA;        break;&#xA;      case &#x27;seeking&#x27;:&#xA;        currentStatus.status = StreamStatus.SEEKING;&#xA;        this.state$.next(currentStatus);&#xA;        if (this.mediaSource.readyState == &#x27;open&#x27;) {&#xA;          this.sourceBuffer.abort();&#xA;        }&#xA;        this.chunksLoader.handleOnTimeUpdate(this.audioObj.currentTime);&#xA;        break;&#xA;    }&#xA;  };&#xA;&#xA;  private addEvents(obj, events, handler) {&#xA;    events.forEach(event => obj.addEventListener(event, handler));&#xA;  }&#xA;&#xA;}&#xA;</number></playerstate>

    &#xA;

    Running it will give me the following output :

    &#xA;

    enter image description here

    &#xA;

    &#xA;

    Apologies for the screenshot but it's not possible to just copy the output without all the stack traces in Chrome.

    &#xA;

    &#xA;

    What I also tried was following this example and call sourceBuffer.abort() but that didn't work. It looks more like a hack that used to work years ago but it's still referenced in the docs (see "Example" -> "You can see something similar in action in Nick Desaulnier's bufferWhenNeeded demo ..").

    &#xA;

    case &#x27;seeking&#x27;:&#xA;  currentStatus.status = StreamStatus.SEEKING;&#xA;  this.state$.next(currentStatus);        &#xA;  if (this.mediaSource.readyState === &#x27;open&#x27;) {&#xA;    this.sourceBuffer.abort();&#xA;  } &#xA;  break;&#xA;

    &#xA;

    Trying with MP3

    &#xA;

    I have tested the above code under Chrome by converting tracks to MP3 :

    &#xA;

    ffmpeg -i input.mp3 -acodec aac -b:a 256k -f mp3 output.mp3&#xA;

    &#xA;

    and creating a SourceBuffer using audio/mpeg as type :

    &#xA;

    this.mediaSource.addSourceBuffer(&#x27;audio/mpeg&#x27;)&#xA;

    &#xA;

    I have the same problem when seeking.

    &#xA;

    The issue wihout seeking

    &#xA;

    The above code has another issue :

    &#xA;

    After two minutes of playing, the audio playback starts to stutter and comes to a halt prematurely. So, the audio plays up to a point and then it stops without any obvious reason.

    &#xA;

    For whatever reason there is another canplay and playing event. A few seconds after, the audio simply stops..

    &#xA;

    enter image description here

    &#xA;

  • 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.

    &#xA;

    Using FFMPEG :

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

    Using Media Codec :

    &#xA;

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

    &#xA;

    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 :

    &#xA;

    fun Convert_Mp3_to_acc() {&#xA;&#xA;   &#xA;    AndroidAudioConverter.load(requireActivity(), object : ILoadCallback {&#xA;        override fun onSuccess() {&#xA;&#xA;            val callback: IConvertCallback = object : IConvertCallback {&#xA;                override fun onSuccess(convertedFile: File) {&#xA;                    toggleLoader(false)&#xA;                    audioLink = convertedFile.absolutePath&#xA;                    append()&#xA;                 &#xA;&#xA;                }&#xA;&#xA;                override fun onFailure(error: java.lang.Exception) {&#xA;                    toggleLoader(false)&#xA;                    Toast.makeText(requireActivity(), "" &#x2B; error, Toast.LENGTH_SHORT).show()&#xA;                }&#xA;            }&#xA;            AndroidAudioConverter.with(requireActivity())&#xA;                .setFile(File(audioLink))&#xA;                .setFormat(AudioFormat.AAC)&#xA;                .setCallback(callback)&#xA;                .convert()&#xA;        }&#xA;&#xA;        override fun onFailure(error: java.lang.Exception) {&#xA;            toggleLoader(false)&#xA;        }&#xA;    })&#xA;}&#xA;

    &#xA;

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

    &#xA;

     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;