Newest 'x264' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Trying to compile x264 and ffmpeg for iPhone - "missing required architecture arm in file"

    11 février 2013, par jtrim

    I'm trying to compile x264 for use in an iPhone application. I see there are instructions on how to compile ffmpeg for use on the platform here: http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-October/076618.html , but I can't seem to find anything this complete for compiling x264 on the iPhone. I've found this source tree: http://gitorious.org/x264-arm that seems to have support for the ARM platform.

    Here is my config line:

    ./configure --cross-prefix=/usr/bin/ --host=arm-apple-darwin10 --extra-cflags="-B /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/usr/lib/ -I /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/usr/lib/"
    

    ...and inside configure I'm using the gas-preprocessor script (first link above) as my assembler:

    gas-preprocessor.pl gcc
    

    When I start compiling, it chunks away for a little while, then it spits out these warnings and a huge list of undefined symbols:

    ld: warning: option -s is obsolete and being ignored
    ld: warning: -force_cpusubtype_ALL will become unsupported for ARM architectures
    ld: warning: in /usr/lib/crt1.o, missing required architecture arm in file
    ld: warning: in /usr/X11R6/lib/libX11.dylib, missing required architecture arm in file
    ld: warning: in /usr/lib/libm.dylib, missing required architecture arm in file
    ld: warning: in /usr/lib/libpthread.dylib, missing required architecture arm in file
    ld: warning: in /usr/lib/libgcc_s.1.dylib, missing required architecture arm in file
    ld: warning: in /usr/lib/libSystem.dylib, missing required architecture arm in file
    Undefined symbols:
    

    My guess would be that the problem has to do with the "missing required architecture arm in file" warning...any ideas?

  • .mov conversion to .mp4 using ffmpeg doesn't convert the entire video

    5 février 2013, par user504879

    I am trying to convert a mov file which I got from saving my powerpoint presentation to a movie file. However only a part of the presentation is converted not the entire one and also running qt-start doesn't make the exported mp4 to stream over rtmp. Is there something which I am missing?

    I am attaching the output which i get when I am trying to convert the file using ffmpeg

    $ export LD_LIBRARY_PATH=/usr/local/lib; /usr/local/bin/ffmpeg -y -i /data/tmp/vialogues_prez.mov -r 20 -g 40 -acodec libfaac -ar 44100  -ab 96k -vcodec libx264 -s 640x480 -vpre medium /data/videos/vialogues_prez.mp4
    
    FFmpeg version 0.6.1, Copyright (c) 2000-2010 the FFmpeg developers
      built on Feb 19 2011 19:03:56 with gcc 4.4.5
      configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-x11grab
      libavutil     50.15. 1 / 50.15. 1
      libavcodec    52.72. 2 / 52.72. 2
      libavformat   52.64. 2 / 52.64. 2
      libavdevice   52. 2. 0 / 52. 2. 0
      libswscale     0.11. 0 /  0.11. 0
      libpostproc   51. 2. 0 / 51. 2. 0
    [mov,mp4,m4a,3gp,3g2,mj2 @ 0x186f460]max_analyze_duration reached
    
    Seems stream 0 codec frame rate differs from container frame rate: 600.00 (600/1) -> 0.08 (1/12)
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/data/tmp/vialogues_prez.mov':
      Metadata:
        major_brand     : qt  
        minor_version   : 537199360
        compatible_brands: qt  
        comment         : Microsoft PowerPoint Movie
        comment-eng     : Microsoft PowerPoint Movie
      Duration: 00:04:47.00, start: 0.000000, bitrate: 22 kb/s
        Stream #0.0(eng): Video: qtrle, bgra, 640x480, 21 kb/s, 0.01 fps, 0.08 tbr, 600 tbn, 600 tbc
        Stream #0.1(eng): Video: 0x0000, 600 tbr, 600 tbn, 600 tbc
        Stream #0.2(eng): Video: 0x0000, 600 tbr, 600 tbn, 600 tbc
    [libx264 @ 0x1873b50]using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64
    [libx264 @ 0x1873b50]profile High, level 3.0
    [libx264 @ 0x1873b50]264 - core 114 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=200 ratetol=20.0 qcomp=0.60 qpmin=10 qpmax=51 qpstep=4 ip_ratio=1.41 aq=1:1.00
    Output #0, mp4, to '/data/videos/vialogues_prez.mp4':
      Metadata:
        encoder         : Lavf52.64.2
        Stream #0.0(eng): Video: libx264, yuv420p, 640x480, q=10-51, 200 kb/s, 20 tbn, 20 tbc
    Stream mapping:
      Stream #0.0 -> #0.0
    Press [q] to stop encoding
    frame=    4 fps=  0 q=32766.0 Lsize=      50kB time=45.05 bitrate=   9.0kbits/s    
    video:49kB audio:0kB global headers:0kB muxing overhead 1.740573%
    [libx264 @ 0x1873b50]frame I:1     Avg QP:32.73  size:  8427
    [libx264 @ 0x1873b50]frame P:3     Avg QP:20.68  size: 13640
    [libx264 @ 0x1873b50]mb I  I16..4: 60.8% 14.6% 24.7%
    [libx264 @ 0x1873b50]mb P  I16..4: 28.7%  7.2% 15.4%  P16..4:  2.0%  1.3%  1.4%  0.0%  0.0%    skip:43.9%
    [libx264 @ 0x1873b50]final ratefactor: -16.67
    [libx264 @ 0x1873b50]8x8 transform intra:14.2% inter:5.0%
    [libx264 @ 0x1873b50]coded y,uvDC,uvAC intra: 25.2% 18.4% 13.0% inter: 5.3% 7.4% 7.2%
    [libx264 @ 0x1873b50]i16 v,h,dc,p: 63% 34%  1%  2%
    [libx264 @ 0x1873b50]i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 19% 41% 31%  1%  1%  1%  1%  1%  4%
    [libx264 @ 0x1873b50]i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 33% 19%  2%  3%  3%  4%  3%  4%
    [libx264 @ 0x1873b50]i8c dc,h,v,p: 75% 20%  4%  1%
    [libx264 @ 0x1873b50]Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 0x1873b50]ref P L0: 57.0% 12.2% 26.2%  4.7%
    [libx264 @ 0x1873b50]kb/s:1.14
    

    any help is appreciated.

  • How to write NALs produced by x264_encoder_encode() using ffmpeg av_interleaved_write_frame()

    21 janvier 2013, par Haleeq Usman

    I have been trying to produce a "flv" video file in the following sequence:

    av_register_all();
    
    // Open video file
    if (avformat_open_input(&pFormatCtx, "6.mp4", NULL, NULL) != 0)
        return -1; // Couldn't open file
    
    // Retrieve stream information
    if (avformat_find_stream_info(pFormatCtx, NULL) < 0)
        return -1; // Couldn't find stream information
    
    // Dump information about file onto standard error
    av_dump_format(pFormatCtx, 0, "input_file.mp4", 0);
    
    // Find the first video stream
    videoStream = -1;
    for (i = 0; i < pFormatCtx->nb_streams; i++)
        if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
            videoStream = i;
            break;
        }
    if (videoStream == -1)
        return -1; // Didn't find a video stream
    
    // Get a pointer to the codec context for the video stream
    pCodecCtx = pFormatCtx->streams[videoStream]->codec;
    
    // Find the decoder for the video stream
    pCodec = avcodec_find_decoder(pCodecCtx->codec_id);
    if (pCodec == NULL) {
        fprintf(stderr, "Unsupported codec!\n");
        return -1; // Codec not found
    }
    // Open codec
    if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0)
        return -1; // Could not open codec
    
    // Allocate video frame
    pFrame = avcodec_alloc_frame();
    
    // Allocate video frame
    pFrame = avcodec_alloc_frame();
    
    // Allocate an AVFrame structure
    pFrameYUV420 = avcodec_alloc_frame();
    if (pFrameYUV420 == NULL)
        return -1;
    
    // Determine required buffer size and allocate buffer
    numBytes = avpicture_get_size(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
    buffer = (uint8_t *) av_malloc(numBytes * sizeof(uint8_t));
    
    // Assign appropriate parts of buffer to image planes in pFrameYUV420
    // Note that pFrameYUV420 is an AVFrame, but AVFrame is a superset of AVPicture
    avpicture_fill((AVPicture *) pFrameRGB, buffer, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height);
    
    // Setup scaler
    img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, SWS_BILINEAR, 0, 0, 0);
    if (img_convert_ctx == NULL) {
        fprintf(stderr, "Cannot initialize the conversion context!\n");
        exit(1);
    }
    
    // Setup encoder/muxing now
    filename = "output_file.flv";
    fmt = av_guess_format("flv", filename, NULL);
    if (fmt == NULL) {
        printf("Could not guess format.\n");
        return -1;
    }
    /* allocate the output media context */
    oc = avformat_alloc_context();
    if (oc == NULL) {
        printf("could not allocate context.\n");
        return -1;
    }
    oc->oformat = fmt;
    snprintf(oc->filename, sizeof(oc->filename), "%s", filename);
    
    video_st = NULL;
    if (fmt->video_codec != AV_CODEC_ID_NONE) {
        video_st = add_stream(oc, &video_codec, fmt->video_codec);
    }
    
    // Let's see some information about our format
    av_dump_format(oc, 0, filename, 1);
    
    /* open the output file, if needed */
    if (!(fmt->flags & AVFMT_NOFILE)) {
        ret = avio_open(&oc->pb, filename, AVIO_FLAG_WRITE);
        if (ret < 0) {
            fprintf(stderr, "Could not open '%s': %s\n", filename, av_err2str(ret));
            return 1;
        }
        }
    /* Write the stream header, if any. */
    ret = avformat_write_header(oc, NULL);
    if (ret < 0) {
        fprintf(stderr, "Error occurred when opening output file: %s\n", av_err2str(ret));
        return 1;
    }
    
    // Setup x264 params
    x264_param_t param;
    x264_param_default_preset(&param, "veryfast", "zerolatency");
    param.i_threads = 1;
    param.i_width = video_st->codec->width;
    param.i_height = video_st->codec->height;
    param.i_fps_num = STREAM_FRAME_RATE; // 30 fps, same as video
    param.i_fps_den = 1;
    // Intra refres:
    param.i_keyint_max = STREAM_FRAME_RATE;
    param.b_intra_refresh = 1;
    // Rate control:
    param.rc.i_rc_method = X264_RC_CRF;
    param.rc.f_rf_constant = 25;
    param.rc.f_rf_constant_max = 35;
    // For streaming:
    param.b_repeat_headers = 1;
    param.b_annexb = 1;
    x264_param_apply_profile(&param, "baseline");
    
    x264_t* encoder = x264_encoder_open(&param);
    x264_picture_t pic_in, pic_out;
    x264_picture_alloc(&pic_in, X264_CSP_I420, video_st->codec->width, video_st->codec->height);
    
    x264_nal_t* nals;
    int i_nals;
    
    // The loop:
    // 1. Read frames
    // 2. Decode the frame
    // 3. Attempt to re-encode using x264
    // 4. Write the x264 encoded frame using av_interleaved_write_frame
    while (av_read_frame(pFormatCtx, &packet) >= 0) {
        // Is this a packet from the video stream?
        if (packet.stream_index == videoStream) {
            // Decode video frame
            avcodec_decode_video2(pCodecCtx, pFrame, &frameFinished, &packet);
    
            // Did we get a video frame?
            if (frameFinished) {
                sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pic_in.img.plane, pic_in.img.i_stride);
                int frame_size = x264_encoder_encode(encoder, &nals, &i_nals, &pic_in, &pic_out);
    
                if (frame_size >= 0) {
                    if (i_nals < 0)
                        printf("invalid frame size: %d\n", i_nals);
                    // write out NALs
                    for (i = 0; i < i_nals; i++) {
                        // initalize a packet
                        AVPacket p;
                        av_init_packet(&p);
                        p.data = nals[i].p_payload;
                        p.size = nals[i].i_payload;
                        p.stream_index = video_st->index;
                        p.flags = AV_PKT_FLAG_KEY;
                        p.pts = AV_NOPTS_VALUE;
                        p.dts = AV_NOPTS_VALUE;
                        ret = av_interleaved_write_frame(oc, &p);
                    }
                }
                printf("encoded frame #%d\n", frame_count);
                frame_count++;
            }
        }
    
        // Free the packet that was allocated by av_read_frame
        av_free_packet(&packet);
    }
    
    // Now we free up resources used/close codecs, and finally close our program.
    

    Here is the implementation for the add_stream() function:

    /* Add an output stream. */
    static AVStream *add_stream(AVFormatContext *oc, AVCodec **codec, enum AVCodecID codec_id) {
        AVCodecContext *c;
        AVStream *st;
        int r;
        /* find the encoder */
        *codec = avcodec_find_encoder(codec_id);
        if (!(*codec)) {
            fprintf(stderr, "Could not find encoder for '%s'\n",
                    avcodec_get_name(codec_id));
            exit(1);
        }
        st = avformat_new_stream(oc, *codec);
        if (!st) {
            fprintf(stderr, "Could not allocate stream\n");
            exit(1);
        }
        st->id = oc->nb_streams - 1;
        c = st->codec;
        switch ((*codec)->type) {
        case AVMEDIA_TYPE_AUDIO:
            st->id = 1;
            c->sample_fmt = AV_SAMPLE_FMT_FLTP;
            c->bit_rate = 64000;
            c->sample_rate = 44100;
            c->channels = 2;
            break;
        case AVMEDIA_TYPE_VIDEO:
            avcodec_get_context_defaults3(c, *codec);
            c->codec_id = codec_id;
            c->bit_rate = 500*1000;
            //c->rc_min_rate = 500*1000;
            //c->rc_max_rate = 500*1000;
            //c->rc_buffer_size = 500*1000;
            /* Resolution must be a multiple of two. */
            c->width = 1280;
            c->height = 720;
            /* timebase: This is the fundamental unit of time (in seconds) in terms
             * of which frame timestamps are represented. For fixed-fps content,
             * timebase should be 1/framerate and timestamp increments should be
             * identical to 1. */
            c->time_base.den = STREAM_FRAME_RATE;
            c->time_base.num = 1;
            c->gop_size = 12; /* emit one intra frame every twelve frames at most */
            c->pix_fmt = STREAM_PIX_FMT;
            if (c->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
                /* just for testing, we also add B frames */
                c->max_b_frames = 2;
            }
            if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
                /* Needed to avoid using macroblocks in which some coeffs overflow.
                 * This does not happen with normal video, it just happens here as
                 * the motion of the chroma plane does not match the luma plane. */
                c->mb_decision = 2;
            }
            break;
        default:
            break;
        }
        /* Some formats want stream headers to be separate. */
        if (oc->oformat->flags & AVFMT_GLOBALHEADER)
            c->flags |= CODEC_FLAG_GLOBAL_HEADER;
        return st;
    }
    

    After the encoding is complete, I check the output file output_file.flv. I notice it's size is very large: 101MB and it does not play. If I use ffmpeg to decode/encode the input file, then I get an output file about 83MB in size (which is about the same size as the original .mp4 file used as input). Also, the 83MB output from just using ffmpeg C api, as opposed to using x264 for the encoding step, plays just fine. Does anyone know where I am going wrong? I have tried researching this for a few days now but with no luck :(. I feel that I am close to making it work, however, I just cannot figure out what I am doing wrong. Thank you!

  • X264 & ARM encoding on Android

    20 janvier 2013, par Tishu

    I recently built a Video encoding class that runs on Android using ffmpeg and native code. I am surprised by the time it takes to encode a video, about 1 frame / second at best. I have tried with x264 and settings optimised for speed and with mpeg as well - no real difference.

    The x264 library now has support for ARM architecture and is meant to be quite efficient on these boasting over 20fps encoding speed. I am not sure I am using it correctly. Here the script I use for compiling:

    ./configure --prefix=$PREFIX \
    --enable-shared \
    --enable-static \
    --disable-gpac \
    --enable-debug \
    --extra-cflags=" -I$ARM_INC -fPIC -DANDROID -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -Wno-psabi -march=armv5te -msoft-float -mthumb -O3 -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -DANDROID -Wa,--noexecstack -MMD -MP " \
    --extra-ldflags=" -nostdlib -Bdynamic -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,nocopyreloc -Wl,-soname,/usr/lib/libz.so -Wl,-rpath-link=$ARM_LIB,-dynamic-linker=/system/bin/linker -L$ARM_LIB -lc -lm -ldl -lgcc" \
    --cross-prefix=${ARM_PRE}- \
    --disable-asm \
    --host=arm-linux \
    

    I believe the last line should so what I am after ie enable ARM optimisations. Maybe I am missing something.

    For info I am encoding a 640x480 video on a Nexus 7 tablet. Here are my encoder settings (x264)

    c->gop_size       = 12;
    c->pix_fmt        = PIX_FMT_YUV420P;
    c->max_b_frames   = 0;
    c->scenechange_threshold = 0;
    c->rc_buffer_size = 0;
    

    Thanks

  • mp4 wont play in Chrome 17, but plays in Safari, IE etc

    12 janvier 2013, par marca

    File is from a Nikon D3s (mov) converted with ffmpeg to mp4. Working without problems with all other files (avi, flv, mp4 etc)

    Please see file: http://shootitlive.s3.amazonaws.com/output.mp4 (Same non working result in Chrome when served from diffrent hosts, and always works in Safari and with flash in Firefox, Chromium)

    /usr/local/bin/ffmpeg -i nonworking.MOV -acodec libfaac -ab 128k -vcodec libx264 -preset slow -crf 30 -threads 0 -s 768x576 -aspect 1.33333333333 -ar 48000 output.mp4

    Cant find anything strange with (but dont really know what to look for):

    ffmpeg -v 5 -i filename -f null - 2>error.log`
    

    Any ideas?