Recherche avancée

Médias (1)

Mot : - Tags -/ogv

Autres articles (76)

  • Organiser par catégorie

    17 mai 2013, par

    Dans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
    Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
    Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...)

  • Récupération d’informations sur le site maître à l’installation d’une instance

    26 novembre 2010, par

    Utilité
    Sur le site principal, une instance de mutualisation est définie par plusieurs choses : Les données dans la table spip_mutus ; Son logo ; Son auteur principal (id_admin dans la table spip_mutus correspondant à un id_auteur de la table spip_auteurs)qui sera le seul à pouvoir créer définitivement l’instance de mutualisation ;
    Il peut donc être tout à fait judicieux de vouloir récupérer certaines de ces informations afin de compléter l’installation d’une instance pour, par exemple : récupérer le (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

Sur d’autres sites (3896)

  • FFmpeg audio video merge issue in Android

    20 octobre 2017, par djac

    Below code is to merge audio and video file in Android. Both input files are in raw folder in app and both will be stored to
    sd card in Oncreate funtion and will be merged.

    Here the issue is the code is executing, but the video input file is written into audio input folder and the output merge file result.mp4 is faulty.
    Could you please help to find out the issue in code/ command ?

    public class Mrge  extends AppCompatActivity {


       Uri vuri=null;
       public String vabsolutePath=null,  aabsolutePath=null, dabsolutePath=null;


       @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.message_layout);

           OutputStream out;

           try {
               ByteArrayOutputStream stream = new ByteArrayOutputStream();
               InputStream ins = getResources().openRawResource(
                       getResources().getIdentifier("angry",
                               "raw", getPackageName()));


               byte[] buf = new byte[1024];
               int n;
               while (-1 != (n = ins.read(buf)))
                   stream.write(buf, 0, n);

               byte[] bytes = stream.toByteArray();

               String root = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
               File createDir = new File(root + "master" + File.separator);

               createDir.mkdir();


               File file = new File(root + "master" + File.separator + "master.mp4");


               file.createNewFile();
               out = new FileOutputStream(file);
               out.write(bytes);
               out.close();



               vabsolutePath = file.getAbsolutePath();

               //-------------------------------------------------------------------

               ins = getResources().openRawResource(
                       getResources().getIdentifier("audio",
                               "raw", getPackageName()));

               while (-1 != (n = ins.read(buf)))
                   stream.write(buf, 0, n);

               bytes = stream.toByteArray();


               root = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
               createDir = new File(root + "audio" + File.separator);
               createDir.mkdir();


               file = new File(root + "audio" + File.separator + "audio.aac");

               file.createNewFile();
               out = new FileOutputStream(file);
               out.write(bytes);
               out.close();

               aabsolutePath = file.getAbsolutePath();

               root = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
               createDir = new File(root + "result" + File.separator);
               createDir.mkdir();


               file = new File(root + "result" + File.separator + "result.mp4");

               file.createNewFile();

               dabsolutePath = file.getAbsolutePath();


               //------------------------------------------------------------------------






           } catch (IOException e) {
               e.printStackTrace();
           }
           String ccommand[] = {"-y", "-i",vabsolutePath,"-i",aabsolutePath, "-c:v", "copy", "-c:a", "aac","-shortest", dabsolutePath};

           loadFFMpegBinary();
           execFFmpegBinary(ccommand);

       }






           FFmpeg ffmpeg;
           private void loadFFMpegBinary() {
               try {
                   if (ffmpeg == null) {

                       ffmpeg = FFmpeg.getInstance(this);
                   }
                   ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
                       @Override
                       public void onFailure() {
                           //showUnsupportedExceptionDialog();
                       }

                       @Override
                       public void onSuccess() {

                       }
                   });
               } catch (FFmpegNotSupportedException e) {
                   //showUnsupportedExceptionDialog();
               } catch (Exception e) {

               }
           }




       private void execFFmpegBinary(final String[] command) {
           try {
               ffmpeg.execute(command, new ExecuteBinaryResponseHandler()
               {
                   @Override
                   public void onFailure(String s) {

                   }

                   @Override
                   public void onSuccess(String s) {


                   }


               @Override
               public void onProgress(String s) {

               }

               @Override
               public void onStart() {

               }

               @Override
               public void onFinish() {


               }
           });
       } catch (FFmpegCommandAlreadyRunningException e) {

               String m="hi";

       }




    }










    }
  • Write audio packet to file using ffmpeg

    27 février 2017, par iamyz

    I am trying to write audio packet to file using ffmpeg. The source device sending the packet after some interval. e.g.

    First packet has a time stamp 00:00:00
    Second packet has a time stamp 00:00:00.5000000
    Third packet has a time stamp 00:00:01
    And so on...

    Means two packet per second.

    I want to encode those packets and write to a file.

    I am referring the Ffmpeg example from link Muxing.c

    While encoding and writing there is no error. But output file has only 2 sec audio duration and speed is also super fast.

    The video frames are proper according the settings.

    I think the problem is related to calculation of pts, dts and duration of packet.

    How should I calculate proper values for pts, dts and duration. Or is this problem related to other thing ?

    Code :

    void AudioWriter::WriteAudioChunk(IntPtr chunk, int lenght, TimeSpan timestamp)
    {
       int buffer_size = av_samples_get_buffer_size(NULL, outputStream->tmp_frame->channels, outputStream->tmp_frame->nb_samples,  outputStream->AudioStream->codec->sample_fmt, 0);

       uint8_t *audioData = reinterpret_cast(static_cast(chunk));
       int ret = avcodec_fill_audio_frame(outputStream->tmp_frame,outputStream->Channels, outputStream->AudioStream->codec->sample_fmt, audioData, buffer_size, 1);

       if (!ret)
          throw gcnew System::IO::IOException("A audio file was not opened yet.");

       write_audio_frame(outputStream->FormatContext, outputStream, audioData);
    }


    static int write_audio_frame(AVFormatContext *oc, AudioWriterData^ ost, uint8_t *audioData)
    {
          AVCodecContext *c;
          AVPacket pkt = { 0 };
          int ret;
          int got_packet;
          int dst_nb_samples;

          av_init_packet(&pkt);
          c = ost->AudioStream->codec;

          AVFrame *frame = ost->tmp_frame;

         if (frame)
         {
             dst_nb_samples = av_rescale_rnd(swr_get_delay(ost->swr_ctx, c->sample_rate) + frame->nb_samples, c->sample_rate, c->sample_rate, AV_ROUND_UP);
             if (dst_nb_samples != frame->nb_samples)
               throw gcnew Exception("dst_nb_samples != frame->nb_samples");

             ret = av_frame_make_writable(ost->AudioFrame);
             if (ret < 0)
                throw gcnew Exception("Unable to make writable.");

             ret = swr_convert(ost->swr_ctx, ost->AudioFrame->data, dst_nb_samples, (const uint8_t **)frame->data, frame->nb_samples);
             if (ret < 0)
               throw gcnew Exception("Unable to convert to destination format.");

             frame = ost->AudioFrame;

             AVRational timebase = { 1, c->sample_rate };
             frame->pts = av_rescale_q(ost->samples_count, timebase, c->time_base);
             ost->samples_count += dst_nb_samples;
         }

         ret = avcodec_encode_audio2(c, &pkt, frame, &got_packet);
         if (ret < 0)
           throw gcnew Exception("Error encoding audio frame.");

         if (got_packet)
         {
           ret = write_frame(oc, &c->time_base, ost->AudioStream, &pkt);
           if (ret < 0)
               throw gcnew Exception("Audio is not written.");
         }
         else
            throw gcnew Exception("Audio packet encode failed.");

         return (ost->AudioFrame || got_packet) ? 0 : 1;
    }

    static int write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt)
    {
       av_packet_rescale_ts(pkt, *time_base, st->time_base);
       pkt->stream_index = st->index;
       return av_interleaved_write_frame(fmt_ctx, pkt);
    }
  • ProcessBuilder is not called when trying to start a process

    15 juin 2022, par xnok

    I am trying to understand more about the ffmpeg usage in JavaCV for android studio and for said task I am trying to use ProcessBuilder. I tried writting a simple program to debug the pb.start(); Although, I am not getting a response. What I did was to start a default/empty activity and pasted the following program :

    


    package com.example.myapplication;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;

import org.bytedeco.javacpp.Loader;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    static final int cols = 192;
    static final int rows = 108;
    static final String ffmpeg = Loader.load(org.bytedeco.ffmpeg.ffmpeg.class);
    static final String rtmp_url = "test.flv";
    static final String[] command = {ffmpeg,
            "-y",
            "-f", "rawvideo",
            "-vcodec", "rawvideo",
            "-pix_fmt", "bgr24",
            "-s", (Integer.toString(cols) + "x" + Integer.toString(rows)),
            "-r", "10",
            "-i", "pipe:",
            "-c:v", "libx264",
            "-pix_fmt", "yuv420p",
            "-preset", "ultrafast",
            "-f", "flv",
            rtmp_url};
    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new Thread(t1).start();

    }
    private static Runnable t1 = () -> {
        Log.e("TAG", "void OnCreate called successfully!");
        ProcessBuilder pb = new ProcessBuilder(command).redirectErrorStream(true);
        pb.redirectErrorStream(true);
        try {
            Process process = pb.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            OutputStream writer = process.getOutputStream();
            Log.e("TAG", "Something good happened here");
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("TAG", "Nothing good happened here");
        }
    };


}


    


    My current problem is that I can't seem to start properly the processBuilder process via pb.start() ;

    


    I get the following logs from the logcat panel :

    


    2022-06-14 17:24:46.328 13371-13371/com.example.myapplication E/TAG: void OnCreate called successfully!
2022-06-14 17:24:46.333 13371-13371/com.example.myapplication E/TAG: Nothing good happened here


    


    I'd like to understand why is it skipping the try/catch block and not starting the process ?

    


    EDIT : I made some changes as per @g00se's suggestions and I got the following stack trace from the code above :

    


    2022-06-15 00:32:26.700 29787-29787/? E/USNET: USNET: appName: com.example.myapplication
2022-06-15 00:32:29.328 29787-29828/com.example.myapplication E/TAG: void OnCreate called successfully!
2022-06-15 00:32:29.330 29787-29828/com.example.myapplication E/AndroidRuntime: FATAL EXCEPTION: Thread-4
    Process: com.example.myapplication, PID: 29787
    java.lang.NullPointerException
        at java.lang.ProcessBuilder.start(ProcessBuilder.java:1012)
        at com.example.myapplication.MainActivity.lambda$static$0(MainActivity.java:48)
        at com.example.myapplication.MainActivity$$ExternalSyntheticLambda0.run(Unknown Source:0)
        at java.lang.Thread.run(Thread.java:920)