Recherche avancée

Médias (1)

Mot : - Tags -/Rennes

Autres articles (32)

  • Mise à disposition des fichiers

    14 avril 2011, par

    Par défaut, lors de son initialisation, MediaSPIP ne permet pas aux visiteurs de télécharger les fichiers qu’ils soient originaux ou le résultat de leur transformation ou encodage. Il permet uniquement de les visualiser.
    Cependant, il est possible et facile d’autoriser les visiteurs à avoir accès à ces documents et ce sous différentes formes.
    Tout cela se passe dans la page de configuration du squelette. Il vous faut aller dans l’espace d’administration du canal, et choisir dans la navigation (...)

  • 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

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

Sur d’autres sites (4927)

  • FFmpeg C API - syncing video and audio

    10 novembre 2015, par Justin Bradley

    I am trimming video and having a hard getting the audio to sync correctly. The code below is as close as I’ve gotten it work. I’ve tried both re-encoding and not re-encoding the output streams.

    The video trims correctly and is written to the output container. The audio stream also trims correctly, but is written to the front of the output container. For example if the trim length is 10s - the correct portion of audio plays for 10s and then the correct portion of video plays.

    //////// audio stream ////////
    const AVStream *input_stream_audio = input_container->streams[audio_stream_index];
    const AVCodec *decoder_audio = avcodec_find_decoder(input_stream_audio->codec->codec_id);
    if(!decoder_audio) {
       cleanup(decoded_packet, output_container, decoded_frame);
       avformat_close_input(&input_container);
       LOGE("=> Audio decoder not found");
       return -1;
    }
    if(avcodec_open2(input_stream_audio->codec, decoder_audio, NULL) < 0) {
       cleanup(decoded_packet, output_container, decoded_frame);
       avformat_close_input(&input_container);
       LOGE("=> Error opening audio decoder");
       return -1;
    }

    AVStream *output_stream_audio = avformat_new_stream(output_container, NULL);
    if(avcodec_copy_context(output_stream_audio->codec, input_stream_audio->codec) != 0){
       LOGE("=> Failed to Copy audio Context ");
       return -1;
    }
    else {
       LOGI("=> Copied audio context ");
       output_stream_audio->codec->codec_id = input_stream_audio->codec->codec_id;
       output_stream_audio->codec->codec_tag = 0;
       output_stream_audio->pts = input_stream_audio->pts;
       output_stream_audio->time_base.num = input_stream_audio->time_base.num;
       output_stream_audio->time_base.den = input_stream_audio->time_base.den;

    }

    if(avio_open(&output_container->pb, output_file, AVIO_FLAG_WRITE) < 0) {
       cleanup(decoded_packet, output_container, decoded_frame);
       avformat_close_input(&input_container);
       LOGE("=> Error opening output file");
       return -1;
    }

    // allocate frame for conversion
    decoded_frame = avcodec_alloc_frame();
    if(!decoded_frame) {
       cleanup(decoded_packet, output_container, decoded_frame);
       avformat_close_input(&input_container);
       LOGE("=> Error allocating frame");
       return -1;
    }

    av_dump_format(input_container, 0, input_file, 0);
    avformat_write_header(output_container, NULL);
    av_init_packet(&decoded_packet);

    decoded_packet.data = NULL;
    decoded_packet.size = 0;
    int current_frame_num = 1;
    int current_frame_num_audio = 1;
    int got_frame, len;

    AVRational default_timebase;
    default_timebase.num = 1;
    default_timebase.den = AV_TIME_BASE;

    int64_t starttime_int64 = av_rescale_q((int64_t)( 12.0 * AV_TIME_BASE ), AV_TIME_BASE_Q, input_stream->time_base);
    int64_t endtime_int64 = av_rescale_q((int64_t)( 18.0 * AV_TIME_BASE ), AV_TIME_BASE_Q, input_stream->time_base);
    LOGI("=> starttime_int64:     %" PRId64, starttime_int64);
    LOGI("=> endtime_int64:       %" PRId64, endtime_int64);

    int64_t starttime_int64_audio = av_rescale_q((int64_t)( 12.0 * AV_TIME_BASE ), AV_TIME_BASE_Q, input_stream_audio->time_base);
    int64_t endtime_int64_audio = av_rescale_q((int64_t)( 18.0 * AV_TIME_BASE ), AV_TIME_BASE_Q, input_stream_audio->time_base);
    LOGI("=> starttime_int64_audio:     %" PRId64, starttime_int64_audio);
    LOGI("=> endtime_int64_audio:       %" PRId64, endtime_int64_audio);

    // loop input container and decode frames
    while(av_read_frame(input_container, &decoded_packet)>=0) {
       // video packets
       if (decoded_packet.stream_index == video_stream_index) {
           len = avcodec_decode_video2(input_stream->codec, decoded_frame, &got_frame, &decoded_packet);
           if(len < 0) {
               cleanup(decoded_packet, output_container, decoded_frame);
               avformat_close_input(&input_container);
               LOGE("=> No frames to decode");
               return -1;
           }
           // this is the trim range we're looking for
           if(got_frame && decoded_frame->pkt_pts >= starttime_int64 && decoded_frame->pkt_pts <= endtime_int64) {
                   av_init_packet(&encoded_packet);
                   encoded_packet.data =  NULL;
                   encoded_packet.size =  0;

                   ret = avcodec_encode_video2(output_stream->codec, &encoded_packet, decoded_frame, &got_frame);
                   if (ret < 0) {
                       cleanup(decoded_packet, output_container, decoded_frame);
                       avformat_close_input(&input_container);
                       LOGE("=> Error encoding frames");
                       return ret;
                   }
                   if(got_frame) {
                       if (output_stream->codec->coded_frame->key_frame) {
                           encoded_packet.flags |= AV_PKT_FLAG_KEY;
                       }

                       encoded_packet.stream_index = output_stream->index;
                       encoded_packet.pts = av_rescale_q(current_frame_num, output_stream->codec->time_base, output_stream->time_base);
                       encoded_packet.dts = av_rescale_q(current_frame_num, output_stream->codec->time_base, output_stream->time_base);

                       ret = av_interleaved_write_frame(output_container, &encoded_packet);
                       if (ret < 0) {
                           cleanup(decoded_packet, output_container, decoded_frame);
                           avformat_close_input(&input_container);
                           LOGE("=> Error encoding frames");
                           return ret;
                       }
                       else {
                           current_frame_num +=1;
                       }
                   }
               av_free_packet(&encoded_packet);
           }
       }
       // audio packets
       else if(decoded_packet.stream_index == audio_stream_index) {
           // this is the trim range we're looking for
           if(decoded_packet.pts >= starttime_int64_audio && decoded_packet.pts <= endtime_int64_audio) {
               av_init_packet(&encoded_packet);

               encoded_packet.data =  decoded_packet.data;
               encoded_packet.size =  decoded_packet.size;
               encoded_packet.stream_index = audio_stream_index;
               encoded_packet.pts = av_rescale_q(current_frame_num_audio, output_stream_audio->codec->time_base, output_stream_audio->time_base);
               encoded_packet.dts = av_rescale_q(current_frame_num_audio, output_stream_audio->codec->time_base, output_stream_audio->time_base);

               ret = av_interleaved_write_frame(output_container, &encoded_packet);
               if (ret < 0) {
                   cleanup(decoded_packet, output_container, decoded_frame);
                   avformat_close_input(&input_container);
                   LOGE("=> Error encoding frames");
                   return ret;
               }
               else {
                   current_frame_num_audio +=1;
               }
              av_free_packet(&encoded_packet);
           }
       }
    }

    Edit

    I have slight improvement on the initial code. The audio and video are still not perfectly synced, but the original problem of the audio playing first followed by the video is resolved.

    I’m now writing the decoded packet to the output container rather than re-encoding it.

    In the end though I have the same problem - the trimmed video’s audio and video streams are not perfectly synced.

    // audio packets
       else if(decoded_packet.stream_index == audio_stream_index) {
           // this is the trim range we're looking for
           if(decoded_packet.pts >= starttime_int64_audio && decoded_packet.pts <= endtime_int64_audio) {
               ret = av_interleaved_write_frame(output_container, &decoded_packet);
               if (ret < 0) {
                   cleanup(decoded_packet, output_container, decoded_frame);
                   avformat_close_input(&input_container);
                   LOGE("=> Error writing audio frame (%s)", av_err2str(ret));
                   return ret;
               }
               else {
                   current_frame_num_audio +=1;
               }
           }
           else if(decoded_frame->pkt_pts > endtime_int64_audio) {
               audio_copy_complete = true;
           }
       }
  • how to convert a video to H264 video codec format & webm and ogv with watermark via ffmpeg

    5 mars 2015, par ali

    I used this code :

    function convert()
    {
     exec("$ffmpegPath  -i $inputPath -i $watermark -filter_complex overlay=10:10 $outPath");
    }

    convert('test.mp4');
    convert('test.webm');
    convert('test.ogv');

    This code works...but not in browser !
    I can run output videos via KMPLAYER in desktop (ovg only video - no audio)

    I want to run it on web via videojs.

    mp4 playback with videojs in browsers - audio plays but video is blank.

    I googled and I think I must convert it to h264 format...

    Can somebody change my orginal code to 3 valid codes for h264,webm and ogv ?

  • Xuggler Encoding video of Desktop With Audio - audio has gaps

    2 novembre 2012, par Chris

    I am using Xuggler to convert images captured from the java Robot class and sound read from TargetDataLine class and encoding this into a video. I am then attempting to http stream this video data (after writing my header) to a flash client via http (Socket OutputStream) but it plays and stutters (never just playing smoothly) no matter what buffer value I use on the client side.

    I am asking for help and showing my java code because I suspect it might be to do with how I am encoding the video or something about sending data via http socket which i am not getting..

    ByteArrayURLHandler ba = new ByteArrayURLHandler();
    final IRational FRAME_RATE = IRational.make(30);
    final int SECONDS_TO_RUN_FOR = 20;
    final Robot robot = new Robot();
    final Toolkit toolkit = Toolkit.getDefaultToolkit();
    final Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
    IMediaWriter writer;

    writer = ToolFactory.makeWriter(
       XugglerIO.map(
           XugglerIO.generateUniqueName(out, ".flv"),
           out
       ));

    writer.addListener(new MediaListenerAdapter() {
       public void onAddStream(IAddStreamEvent event) {
           event.getSource().getContainer().setInputBufferLength(1000);
           IStreamCoder coder = event.getSource().getContainer().getStream(event.getStreamIndex()).getStreamCoder();
           if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_AUDIO) {
               coder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, false);  
               coder.setBitRate(32000);
               System.out.println("onaddstream"+ coder.getPropertyNames().toString());
           }
           if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
               // coder.setBitRate(64000);
               // coder.setBitRateTolerance(64000);
           }
       }
    });

    writer.addVideoStream(videoStreamIndex, videoStreamId, 1024, 768);
    final int channelCount = 1;      

    int audionumber =   writer.addAudioStream(audioStreamIndex, audioStreamId,1, 44100);
    int bufferSize = (int)audioFormat.getSampleRate()   *audioFormat.getFrameSize();//*6;///6;
    byte[] audioBuf;// = new byte[bufferSize];

    int i = 0;

    final int audioStreamIndex = 1;
    final int audioStreamId = 1;
    BufferedImage screen, bgrScreen;
    long startTime = System.nanoTime();
    while(keepGoing)
    {

       audioBuf = new byte[bufferSize];
       i++;

       screen = robot.createScreenCapture(screenBounds);

       bgrScreen = convertToType(screen, BufferedImage.TYPE_3BYTE_BGR);
       long nanoTs = System.nanoTime()-startTime;
       writer.encodeVideo(0, bgrScreen, nanoTs, TimeUnit.NANOSECONDS);
       audioBuf = new byte[line.available()];
       int nBytesRead = line.read(audioBuf, 0, audioBuf.length);

       IBuffer iBuf = IBuffer.make(null, audioBuf, 0, nBytesRead);

       IAudioSamples smp = IAudioSamples.make(iBuf,1,IAudioSamples.Format.FMT_S16);
       if (smp == null) {
           return;
       }

       long numSample = audioBuf.length / smp.getSampleSize();

       smp.setComplete(true, numSample,(int)
       audioFormat.getSampleRate(), audioFormat.getChannels(),
       IAudioSamples.Format.FMT_S16, nanoTs/1000);

       writer.encodeAudio(1, smp);

       writer.flush();
    }