Advanced search

Medias (91)

Other articles (39)

  • Personnaliser les catégories

    21 June 2013, by

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • Publier sur MédiaSpip

    13 June 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

  • La sauvegarde automatique de canaux SPIP

    1 April 2010, by

    Dans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
    Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...)

On other websites (5887)

  • Google Speech - Streaming Request Returns EOF

    9 October 2017, by Josh

    Using Go, I’m taking a RTMP stream, transcoding it to FLAC (using ffmpeg) and attempting to stream to Google’s Speech API to transcribe the audio. However, I keep getting EOF errors when sending the data. I can’t find any information on this error in the docs so I’m not exactly sure what’s causing it.

    I’m chunking the received data into 3s clips (length isn’t relevant as long as it’s less than the maximum length of a streaming recognition request).

    Here is the core of my code:

    func main() {

       done := make(chan os.Signal)
       received := make(chan []byte)

       go receive(received)
       go transcribe(received)

       signal.Notify(done, os.Interrupt, syscall.SIGTERM)

       select {
       case <-done:
           os.Exit(0)
       }
    }

    func receive(received chan<- []byte) {
       var b bytes.Buffer
       stdout := bufio.NewWriter(&b)

       cmd := exec.Command("ffmpeg", "-i", "rtmp://127.0.0.1:1935/live/key", "-f", "flac", "-ar", "16000", "-")
       cmd.Stdout = stdout

       if err := cmd.Start(); err != nil {
           log.Fatal(err)
       }

       duration, _ := time.ParseDuration("3s")
       ticker := time.NewTicker(duration)

       for {
           select {
           case <-ticker.C:
               stdout.Flush()
               log.Printf("Received %d bytes", b.Len())
               received <- b.Bytes()
               b.Reset()
           }
       }
    }

    func transcribe(received <-chan []byte) {
       ctx := context.TODO()

       client, err := speech.NewClient(ctx)
       if err != nil {
           log.Fatal(err)
       }

       stream, err := client.StreamingRecognize(ctx)
       if err != nil {
           log.Fatal(err)
       }

       // Send the initial configuration message.
       if err = stream.Send(&speechpb.StreamingRecognizeRequest{
           StreamingRequest: &speechpb.StreamingRecognizeRequest_StreamingConfig{
               StreamingConfig: &speechpb.StreamingRecognitionConfig{
                   Config: &speechpb.RecognitionConfig{
                       Encoding:        speechpb.RecognitionConfig_FLAC,
                       LanguageCode:    "en-GB",
                       SampleRateHertz: 16000,
                   },
               },
           },
       }); err != nil {
           log.Fatal(err)
       }

       for {
           select {
           case data := <-received:
               if len(data) > 0 {
                   log.Printf("Sending %d bytes", len(data))
                   if err := stream.Send(&speechpb.StreamingRecognizeRequest{
                       StreamingRequest: &speechpb.StreamingRecognizeRequest_AudioContent{
                           AudioContent: data,
                       },
                   }); err != nil {
                       log.Printf("Could not send audio: %v", err)
                   }
               }
           }
       }
    }

    Running this code gives this output:

    2017/10/09 16:05:00 Received 191704 bytes
    2017/10/09 16:05:00 Saving 191704 bytes
    2017/10/09 16:05:00 Sending 191704 bytes
    2017/10/09 16:05:00 Could not send audio: EOF

    2017/10/09 16:05:03 Received 193192 bytes
    2017/10/09 16:05:03 Saving 193192 bytes
    2017/10/09 16:05:03 Sending 193192 bytes
    2017/10/09 16:05:03 Could not send audio: EOF

    2017/10/09 16:05:06 Received 193188 bytes
    2017/10/09 16:05:06 Saving 193188 bytes
    2017/10/09 16:05:06 Sending 193188 bytes // Notice that this doesn't error

    2017/10/09 16:05:09 Received 191704 bytes
    2017/10/09 16:05:09 Saving 191704 bytes
    2017/10/09 16:05:09 Sending 191704 bytes
    2017/10/09 16:05:09 Could not send audio: EOF

    Notice that not all of the Sends fail.

    Could anyone point me in the right direction here? Is it something to do with the FLAC headers or something? I also wonder if maybe resetting the buffer causes some of the data to be dropped (i.e. it’s a non-trivial operation that actually takes some time to complete) and it doesn’t like this missing information?

    Any help would be really appreciated.

  • Revision 1161055129: Be consistent with SAD values SAD returns unsigned values. Make all the declara

    26 June 2012, by Johann

    Changed Paths: Modify /test/sad_test.cc Modify /vp8/common/mfqe.c Modify /vp8/common/rtcd_defs.sh Modify /vp8/common/sad_c.c Modify /vp8/common/variance.h Modify /vp8/common/x86/sad_sse2.asm Modify /vp8/encoder/mcomp.c Modify /vp8/encoder/rdopt.c Be consistent with SAD (...)

  • seeking with av_seek_frame returns invalid data

    27 June 2016, by mtadmk

    Based on dranger tutorial I’m trying to implement seeking in video file. Problem is with seeking to beginning milliseconds - it always returns 0 when seeking backward, or some place in file (based on file format).

    I.e. with this video file and seeking forward to 500 pts there is always 6163 pts returned. Seeking backward to 500 is always returning 0. I have no idea why.

    Code to do this:

    import java.util.Arrays;
    import java.util.List;
    import org.bytedeco.javacpp.BytePointer;
    import org.bytedeco.javacpp.DoublePointer;
    import org.bytedeco.javacpp.PointerPointer;
    import org.bytedeco.javacpp.avcodec;
    import org.bytedeco.javacpp.avformat;
    import org.bytedeco.javacpp.avutil;
    import org.bytedeco.javacpp.swscale;

    import static org.bytedeco.javacpp.avcodec.av_free_packet;
    import static org.bytedeco.javacpp.avcodec.avcodec_close;
    import static org.bytedeco.javacpp.avcodec.avcodec_decode_video2;
    import static org.bytedeco.javacpp.avcodec.avcodec_find_decoder;
    import static org.bytedeco.javacpp.avcodec.avcodec_flush_buffers;
    import static org.bytedeco.javacpp.avcodec.avcodec_open2;
    import static org.bytedeco.javacpp.avcodec.avpicture_fill;
    import static org.bytedeco.javacpp.avcodec.avpicture_get_size;
    import static org.bytedeco.javacpp.avformat.AVSEEK_FLAG_BACKWARD;
    import static org.bytedeco.javacpp.avformat.av_dump_format;
    import static org.bytedeco.javacpp.avformat.av_read_frame;
    import static org.bytedeco.javacpp.avformat.av_register_all;
    import static org.bytedeco.javacpp.avformat.av_seek_frame;
    import static org.bytedeco.javacpp.avformat.avformat_close_input;
    import static org.bytedeco.javacpp.avformat.avformat_find_stream_info;
    import static org.bytedeco.javacpp.avformat.avformat_open_input;
    import static org.bytedeco.javacpp.avutil.AVMEDIA_TYPE_VIDEO;
    import static org.bytedeco.javacpp.avutil.AV_PIX_FMT_RGB24;
    import static org.bytedeco.javacpp.avutil.AV_TIME_BASE;
    import static org.bytedeco.javacpp.avutil.av_frame_alloc;
    import static org.bytedeco.javacpp.avutil.av_frame_get_best_effort_timestamp;
    import static org.bytedeco.javacpp.avutil.av_free;
    import static org.bytedeco.javacpp.avutil.av_make_q;
    import static org.bytedeco.javacpp.avutil.av_malloc;
    import static org.bytedeco.javacpp.avutil.av_q2d;
    import static org.bytedeco.javacpp.avutil.av_rescale_q;
    import static org.bytedeco.javacpp.swscale.SWS_BILINEAR;
    import static org.bytedeco.javacpp.swscale.sws_getContext;
    import static org.bytedeco.javacpp.swscale.sws_scale;

    public class SeekTest1 {
       private avformat.AVFormatContext videoFile;
       private final avcodec.AVPacket framePacket = new avcodec.AVPacket();
       private avcodec.AVCodecContext videoCodec;
       private avutil.AVFrame yuvFrame;
       private swscale.SwsContext scalingContext;
       private avutil.AVFrame rgbFrame;
       private int streamId;
       private long lastTime;

       public static void main(String[] args) {
           if (args.length > 0) {
               new SeekTest1().start(args[0]);
           } else {
               new SeekTest1().start("/path/to/file");
           }

       }

       private void start(String path) {
           init(path);
           //test for forward
    //        List<integer> seekPos = Arrays.asList(0, 100, 0, 200, 0, 300, 0, 400, 0, 500, 0, 600, 0, 700);
           //test for backward
           List<integer> seekPos = Arrays.asList(10000, 8000, 10000, 7000, 10000, 6000, 10000, 4000, 10000, 2000, 10000, 1000, 10000, 200);
           seekPos.forEach(seekPosition -> {
               readFrame();
               seek(seekPosition);
           });
           readFrame();
           cleanUp();
       }

       long seek(long seekPosition) {
           final avutil.AVRational timeBase = fetchTimeBase();
           long timeInBaseUnit = fetchTimeInBaseUnit(seekPosition, timeBase);

           //changing flag to AVSEEK_FLAG_ANY does not change behavior
           int flag = 0;
           if (timeInBaseUnit &lt; lastTime) {
               flag = AVSEEK_FLAG_BACKWARD;
               System.out.println("seeking backward to " + timeInBaseUnit);
           } else {
               System.out.println("seeking forward to " + timeInBaseUnit);
           }
           avcodec_flush_buffers(videoCodec);
           av_seek_frame(videoFile, streamId, timeInBaseUnit, flag);
           return timeInBaseUnit;
       }

       private long fetchTimeInBaseUnit(long seekPositionMillis, avutil.AVRational timeBase) {
           return av_rescale_q((long) (seekPositionMillis / 1000.0 * AV_TIME_BASE), av_make_q(1, AV_TIME_BASE), timeBase);
       }

       private void readFrame() {
           while (av_read_frame(videoFile, framePacket) >= 0) {
               if (framePacket.stream_index() == streamId) {
                   // Decode video frame
                   final int[] frameFinished = new int[1];
                   avcodec_decode_video2(this.videoCodec, yuvFrame, frameFinished, framePacket);

                   if (frameFinished[0] != 0) {
                       av_free_packet(framePacket);
                       long millis = produceFinishedFrame();
                       System.out.println("produced time " + millis);
                       break;
                   }
               }
               av_free_packet(framePacket);
           }
       }

       private long produceFinishedFrame() {
           sws_scale(scalingContext, yuvFrame.data(), yuvFrame.linesize(), 0,
               videoCodec.height(), rgbFrame.data(), rgbFrame.linesize());
           final long pts = av_frame_get_best_effort_timestamp(yuvFrame);
           final double timeBase = av_q2d(fetchTimeBase());
           final long foundMillis = (long) (pts * 1000 * timeBase);
           lastTime = foundMillis;
           return foundMillis;
       }

       private avutil.AVRational fetchTimeBase() {
           return videoFile.streams(streamId).time_base();
       }

       private void init(String videoPath) {
           final avformat.AVFormatContext videoFile = new avformat.AVFormatContext(null);

           av_register_all();
           if (avformat_open_input(videoFile, videoPath, null, null) != 0) throw new RuntimeException("unable to open");
           if (avformat_find_stream_info(videoFile, (PointerPointer) null) &lt; 0) throw new RuntimeException("Couldn't find stream information");

           av_dump_format(videoFile, 0, videoPath, 0);

           final int streamId = findFirstVideoStream(videoFile);

           final avcodec.AVCodecContext codec = videoFile.streams(streamId).codec();

           final avcodec.AVCodec pCodec = avcodec_find_decoder(codec.codec_id());
           if (pCodec == null) throw new RuntimeException("Unsupported codec");

           if (avcodec_open2(codec, pCodec, (avutil.AVDictionary) null) &lt; 0) throw new RuntimeException("Could not open codec");

           final avutil.AVFrame yuvFrame = av_frame_alloc();

           final avutil.AVFrame rgbFrame = av_frame_alloc();
           if (rgbFrame == null) throw new RuntimeException("Can't allocate avframe");

           final int numBytes = avpicture_get_size(AV_PIX_FMT_RGB24, codec.width(), codec.height());
           final BytePointer frameBuffer = new BytePointer(av_malloc(numBytes));

           final swscale.SwsContext swsContext = sws_getContext(codec.width(), codec.height(), codec.pix_fmt(), codec.width(), codec.height(),
               AV_PIX_FMT_RGB24, SWS_BILINEAR, null, null, (DoublePointer) null);

           avpicture_fill(new avcodec.AVPicture(rgbFrame), frameBuffer, AV_PIX_FMT_RGB24, codec.width(), codec.height());

           this.videoFile = videoFile;
           this.videoCodec = codec;
           this.yuvFrame = yuvFrame;
           this.scalingContext = swsContext;
           this.rgbFrame = rgbFrame;
           this.streamId = streamId;
       }

       private static int findFirstVideoStream(avformat.AVFormatContext videoFile) {
           int videoStream = -1;
           for (int i = 0; i &lt; videoFile.nb_streams(); i++) {
               if (videoFile.streams(i).codec().codec_type() == AVMEDIA_TYPE_VIDEO) {
                   videoStream = i;
                   break;
               }
           }
           if (videoStream == -1) throw new RuntimeException("Didn't find video stream");
           return videoStream;
       }

       private void cleanUp() {
           av_free(this.rgbFrame);
           av_free(yuvFrame);
           avcodec_close(videoCodec);
           avformat_close_input(videoFile);
       }
    }
    </integer></integer>

    As input arg should be provided file from above.