Newest 'ffmpeg' Questions - Stack Overflow

http://stackoverflow.com/questions/tagged/ffmpeg

Les articles publiés sur le site

  • Trying to compile last FFmpeg iPhone : error : invalid operand in inline asm

    1er décembre 2011, par juanramoney

    I am trying to compile last FFmpeg for iPhone, but I am getting an error:

        CC  libavformat/asfcrypt.o
    error: invalid operand in inline asm: 'ldr   ${0:Q}, $1  
        ldr   ${0:R}, $2  
        '
    make: *** [libavformat/asfcrypt.o] Error 1
    

    thanks

  • H264 encoder settings

    30 novembre 2011, par Chris Robinson

    I'm using xuggler to encode a series of images to an MP4 file. I use the following code to setup the IStreamCoder and specify the H264 codec:

    // only set if codec is H264
    Configuration.configure("/usr/local/xuggler/share/ffmpeg/libx264-hq.ffpreset",
                outStreamCoder);
    
    outStreamCoder.setNumPicturesInGroupOfPictures(12);
    outStreamCoder.setCodec(codec);
    outStreamCoder.setBitRate(videoSettings.getBitrate());
    outStreamCoder.setBitRateTolerance(videoSettings.getBitrateTolerance());
    outStreamCoder.setPixelType(IPixelFormat.Type.YUV420P);
    outStreamCoder.setHeight(videoSettings.getResolution().height);
    outStreamCoder.setWidth(videoSettings.getResolution().width);
    outStreamCoder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true);
    outStreamCoder.setGlobalQuality(0);
    fps = IRational.make((int) videoSettings.getFramerate(), 1);
    outStreamCoder.setFrameRate(fps);
    outStreamCoder.setTimeBase(IRational.make(fps.getDenominator(), fps.getNumerator()));
    

    which yields the following output:

    Codec: CODEC_ID_H264
    Resolution: 1280x720
    Bitrate: 25000
    Bitrate Tolerance: 1000
    Framerate: 25.0
    

    H264 encoded video

    Now when I specify the MPEG4 codec, I get the following output:

    Codec: CODEC_ID_MPEG4
    Resolution: 1280x720
    Bitrate: 25000
    Bitrate Tolerance: 1000
    Framerate: 25.0
    

    MPEG4 encoded video

    As you can see, the only difference is the ICodec type (MPEG4 instead of H264) and the use of the preset (which is required by xuggler when using an H264 codec). Can anyone explain to me the huge difference in quality and tell me how to resolve the issue?

  • X264 encoding using Opencv

    29 novembre 2011, par user573193

    I am working with a high resolution camera: 4008x2672. I a writing a simple program which grabs frame from the camera and sends the frame to a avi file. For working with such a high resolution, I found only x264 codec that could do the trick (Suggestions welcome). I am using opencv for most of the image handling stuff. As mentioned in this post http://doom10.org/index.php?topic=1019.0 , I modified the AVCodecContext members as per ffmpeg presets for libx264 (Had to do this to avoid broken ffmpeg defaults settings error). This is output I am getting when I try to run the program

    libx264 @ 0x992d040]non-strictly-monotonic PTS 
    1294846981.526675 1 0 //Timestamp camera_no frame_no
    1294846981.621101 1 1
    1294846981.715521 1 2
    1294846981.809939 1 3
    1294846981.904360 1 4
    1294846981.998782 1 5
    1294846982.093203 1 6
        Last message repeated 7 times
    [avi @ 0x992beb0]st:0 error, non monotone timestamps 
    -614891469123651720 >= -614891469123651720
    
     OpenCV Error: Unspecified error (Error while writing video frame) in
     icv_av_write_frame_FFMPEG, file 
    /home/ajoshi/ext/OpenCV-2.2.0/modules/highgui/src/cap_ffmpeg.cpp, line 1034
    terminate called after throwing an instance of 'cv::Exception'
     what():  /home/ajoshi/ext/OpenCV-2.2.0/modules/highgui/src/cap_ffmpeg.cpp:1034:
    error: (-2) Error while writing video frame in function icv_av_write_frame_FFMPEG
    

    Aborted

    Modifications to the AVCodecContext are:

    if(codec_id == CODEC_ID_H264)
    {
        //fprintf(stderr, "Trying to parse a preset file for libx264\n");
        //Setting Values manually from medium preset
        c->me_method = 7;
        c->qcompress=0.6;
        c->qmin = 10;
        c->qmax = 51;
        c->max_qdiff = 4;
        c->i_quant_factor=0.71;
        c->max_b_frames=3;
        c->b_frame_strategy = 1;
        c->me_range = 16;
    c->me_subpel_quality=7; c->coder_type = 1; c->scenechange_threshold=40; c->partitions = X264_PART_I8X8 | X264_PART_I4X4 | X264_PART_P8X8 | X264_PART_B8X8; c->flags = CODEC_FLAG_LOOP_FILTER; c->flags2 = CODEC_FLAG2_BPYRAMID | CODEC_FLAG2_MIXED_REFS | CODEC_FLAG2_WPRED | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP; c->keyint_min = 25; c->refs = 3; c->trellis=1; c->directpred = 1; c->weighted_p_pred=2; }

    I am probably not setting the dts and pts values which I believed ffmpeg should be setting it for me.

    Any sugggestions welcome.
    Thanks in advance

  • converting images to mp4 using ffmpeg on iphone

    29 novembre 2011, par user633901

    Up till now, i can create mpeg1 but with no luck for mp4.Maybe we can talk and share information.Someone told me that i have to set some flags for using mp4.But i am stuck at using it...

    following is the working code:

    av_register_all();
    printf("Video encoding\n"); 
    
    /// find the mpeg video encoder 
    //codec=avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); 
    codec = avcodec_find_encoder(CODEC_ID_MPEG4); 
    
    if (!codec) { 
        fprintf(stderr, "codec not found\n"); 
        exit(1); 
    } 
    
    c = avcodec_alloc_context(); 
    picture = avcodec_alloc_frame(); 
    
    // put sample parameters 
    c->bit_rate = 400000;
    /// resolution must be a multiple of two 
    c->width = 240; 
    c->height = 320; 
    //c->codec_id = fmt->video_codec;
    //frames per second 
    c->time_base= (AVRational){1,25}; 
    c->gop_size = 10; /// emit one intra frame every ten frames 
    c->max_b_frames=1; 
    c->pix_fmt =PIX_FMT_YUV420P; // PIX_FMT_YUV420P
    
    if (avcodec_open(c, codec) < 0) { 
        fprintf(stderr, "could not open codec\n"); 
        exit(1); 
    }
    
    f = fopen([[NSHomeDirectory() stringByAppendingPathComponent:@"test.mp4"] UTF8String], "wb"); 
    
    if (!f) { 
        fprintf(stderr, "could not open %s\n",[@"test.mp4" UTF8String]); 
        exit(1); 
    } 
    
    // alloc image and output buffer 
    outbuf_size = 100000; 
    outbuf = malloc(outbuf_size); 
    size = c->width * c->height; 
    
    #pragma mark - 
    
    AVFrame* outpic = avcodec_alloc_frame(); 
    int nbytes = avpicture_get_size(PIX_FMT_YUV420P, c->width, c->height); //this is half size of numbytes. 
    
    //create buffer for the output image 
    uint8_t* outbuffer = (uint8_t*)av_malloc(nbytes); 
    
    #pragma mark -  
    for(k=0;k<1;k++) { 
        for(i=0;i<25;i++) { 
            fflush(stdout); 
    
            int numBytes = avpicture_get_size(PIX_FMT_RGBA, c->width, c->height); 
            uint8_t *buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t)); 
    
            UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", i+1]]; 
            CGImageRef newCgImage = [image CGImage]; 
    
            CGDataProviderRef dataProvider = CGImageGetDataProvider(newCgImage); 
            CFDataRef bitmapData = CGDataProviderCopyData(dataProvider); 
            buffer = (uint8_t *)CFDataGetBytePtr(bitmapData);   
            /////////////////////////// 
            //outbuffer=(uint8_t *)CFDataGetBytePtr(bitmapData); 
            ////////////////////////// 
            avpicture_fill((AVPicture*)picture, buffer, PIX_FMT_RGBA, c->width, c->height); 
            avpicture_fill((AVPicture*)outpic, outbuffer, PIX_FMT_YUV420P, c->width, c->height);//does not have image data. 
    
            struct SwsContext* fooContext = sws_getContext(c->width, c->height, 
                                                          PIX_FMT_RGBA, 
                                                          c->width, c->height, 
                                                          PIX_FMT_YUV420P, 
                                                          SWS_FAST_BILINEAR, NULL, NULL, NULL); 
    
            //perform the conversion 
            sws_scale(fooContext, picture->data, picture->linesize, 0, c->height, outpic->data, outpic->linesize); 
            // Here is where I try to convert to YUV 
    
            // encode the image 
            out_size = avcodec_encode_video(c, outbuf, outbuf_size, outpic); 
            printf("encoding frame %3d (size=%5d)\n", i, out_size); 
            fwrite(outbuf, 1, out_size, f); 
    
            free(buffer); 
            buffer = NULL;
        }
    
        // get the delayed frames 
        for(; out_size; i++) { 
            fflush(stdout); 
    
            out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); 
            printf("write frame %3d (size=%5d)\n", i, out_size); 
            fwrite(outbuf, 1, outbuf_size, f);       
        } 
    }
    
    // add sequence end code to have a real mpeg file 
    outbuf[0] = 0x00; 
    outbuf[1] = 0x00; 
    outbuf[2] = 0x01; 
    outbuf[3] = 0xb7; 
    fwrite(outbuf, 1, 4, f); 
    fclose(f); 
    free(picture_buf);
    free(outbuf); 
    
    avcodec_close(c); 
    av_free(c); 
    av_free(picture); 
    //av_free(outpic); 
    printf("\n"); 
    

    my msn:hieeli@hotmail.com

  • OpenGLES glReadPixels exc_bad_access

    29 novembre 2011, par Yanny

    I'm trying to create video from images using OpenGLES and ffmpeg, but on iPad(4.3) I have a crash on glReadPixels

    -(NSData *) glToUIImage {
    
        int numberOfComponents = NUMBER_OF_COMPONENTS; //4
        int width = PICTURE_WIDTH; 
        int height = PICTURE_HEIGHT;
    
        NSInteger myDataLength = width * height * numberOfComponents;   
    
        NSMutableData * buffer= [NSMutableData dataWithLength :myDataLength];    
    
        [self checkForGLError]; 
    
        GLenum type = NUMBER_OF_COMPONENTS == 3 ? GL_RGB : GL_RGBA; //RGBA
        glReadPixels(0, 0, width, height, type, GL_UNSIGNED_BYTE, [buffer mutableBytes]);   //EXC_BAD_ACCESS here
    
        return buffer; 
    }
    

    It is working on iPhone 4 (4.3) and iPod Touch, but have problems on iPhone 3G(3.0) and iPad(4.3). Can you help me with this issue?

    Also on iPhone 3G(3.0) and iPad(4.3) I have problems with Video - first 5-20 video frames have trash. Maybe issue with optimization? Or architecture?