Recherche avancée

Médias (1)

Mot : - Tags -/ticket

Autres articles (34)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

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

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

Sur d’autres sites (5702)

  • seeking with av_seek_frame returns invalid data

    27 juin 2016, par 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.

  • av_read_frame function in ffmpeg in android always returning packet.stream_index as 0

    31 juillet 2013, par droidmad

    I am using the following standard code pasted below (ref : http://dranger.com/ffmpeg/) to use ffmpeg in android using ndk. My code is working fine in ubuntu 10.04 using gcc compiler. But I am facing an issue in android.The issue is av_read_frame(pFormatCtx, &amp;packet) is always returning packet.stream_index=0. I have tested my code with various rtsp urls and I have the same behaviour in all cases. I do not have any linking or compiling issues as everything seems to be working fine except this issue. I am trying to solve this from last 2 days but I am stuck badly.Please point me in right direction.

    #include
    #include <android></android>log.h>

    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavformat></libavformat>avformat.h>
    #include <libswscale></libswscale>swscale.h>

    #include
    #define DEBUG_TAG "mydebug_ndk"

    jint Java_com_example_tut2_MainActivity_myfunc(JNIEnv * env, jobject this,jstring myjurl) {
     AVFormatContext *pFormatCtx = NULL;
     int             i, videoStream;
     AVCodecContext  *pCodecCtx = NULL;
     AVCodec         *pCodec = NULL;
     AVFrame         *pFrame = NULL;
     AVPacket        packet;
     int             frameFinished;

     AVDictionary    *optionsDict = NULL;
     struct SwsContext *sws_ctx = NULL;

     jboolean isCopy;
     const char * mycurl = (*env)->GetStringUTFChars(env, myjurl, &amp;isCopy);
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:p2: [%s]", mycurl);

     // Register all formats and codecs
     av_register_all();
     avformat_network_init();
     // Open video file
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:before_open");

     if(avformat_open_input(&amp;pFormatCtx, mycurl, NULL, NULL)!=0)
         return -1;
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "start: %d\t%d\n",pFormatCtx->raw_packet_buffer_remaining_size,pFormatCtx->max_index_size);

     (*env)->ReleaseStringUTFChars(env, myjurl, mycurl);
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:before_stream");
     // Retrieve stream information
     if(avformat_find_stream_info(pFormatCtx, NULL)&lt;0)
         return -1;
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:after_stream");
     // Find the first video stream
     videoStream=-1;
     for(i=0; inb_streams; i++)
         if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
           videoStream=i;
           break;
         }
     if(videoStream==-1)
         return -1; // Didn&#39;t find a video stream
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:after_videostream");
     // Get a pointer to the codec context for the video stream
     pCodecCtx=pFormatCtx->streams[videoStream]->codec;
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:after_codec_context");

     // Find the decoder for the video stream
     pCodec=avcodec_find_decoder(pCodecCtx->codec_id);
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:after_decoder");

     if(pCodec==NULL)
         return -1;
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:found_decoder");

     // Open codec
     if(avcodec_open2(pCodecCtx, pCodec, &amp;optionsDict)&lt;0)
         return -1;
     // Allocate video frame
     pFrame=avcodec_alloc_frame();
     sws_ctx = sws_getContext(pCodecCtx->width,pCodecCtx->height,pCodecCtx->pix_fmt,pCodecCtx->width,
           pCodecCtx->height,PIX_FMT_YUV420P,SWS_BILINEAR,NULL,NULL,NULL);
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:before_while");

     int count=0;
     while(av_read_frame(pFormatCtx, &amp;packet)>=0) {
           __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "entered while: %d   %d   %d\n", packet.duration,packet.stream_index,packet.size);

         if(packet.stream_index==videoStream) {
             // Decode video frame
             //break;
             avcodec_decode_video2(pCodecCtx, pFrame, &amp;frameFinished,&amp;packet);
             __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:in_while");
             if(frameFinished) {
                 __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:gng_out_of_while");
                   break;
             }
         }

         // Free the packet that was allocated by av_read_frame
         av_free_packet(&amp;packet);
         if(++count>1000)
            return -2; //infinite while loop
     }
     __android_log_print(ANDROID_LOG_DEBUG, DEBUG_TAG, "NDK:after_while");

     // Free the YUV frame
     av_free(pFrame);
     // Close the codec
     avcodec_close(pCodecCtx);
     // Close the video file
     avformat_close_input(&amp;pFormatCtx);

     return 0;

    }
  • ffmpeg audio synch issue - fractional framerate

    29 mars 2013, par JoeCitizen

    We are working on an Android app which uses the ffmpeg library via JNI to edit the frames of a video while keeping size, codec etc the same.

    We are having an issue where the audio of the output video is getting out of sync with the video. We believe this is because some input videos have a frame rate which isn't a whole number e.g 25.66 fps and our output will be at 25fps. We have tried to change the time_base field of the output codec to keep the precision i.e by multiply the numerator and denominator but it makes the output frame rate ridiculously high.

    Does anyone know how to force ffmpeg to use the exact same output frame rate as the one it reads in ? We have not found a way to output videos with a fractional frame rate.

    Example of setting up the output codec :

       c =                 st->codec;
       c->codec_id =       codec_id;
       c->codec_type =     AVMEDIA_TYPE_VIDEO;
       c->bit_rate =       inputCodecCtx->bit_rate;
       c->width =          inputCodecCtx->width;
       c->height =         inputCodecCtx->height;

       c->time_base.num =   1000;
       c->time_base.den =  (int)(fps*1000);//fps of the input video *1000 to keep precision

       c->gop_size =       inputCodecCtx->gop_size;
       c->pix_fmt =        inputCodecCtx->pix_fmt;



       static int write_video_frame(AVFormatContext *oc, AVStream *st, AVFrame *newpict, double fps)
       {
           int             ret = 0;
           AVCodecContext* c = st->codec;

           AVPacket pkt;
           av_init_packet(&amp;pkt);

           if (pkt.pts != AV_NOPTS_VALUE)
           {
               pkt.pts =  av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);

           }
           if (pkt.dts != AV_NOPTS_VALUE)


           {
               pkt.dts = av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base);
           }

    .....
    }