Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • How to encode a stream of RGBA values to video ?

    20 septembre 2011, par Rob Oplawar

    More specifically: I have a sequence of 32 bit unsigned RGBA integers for pixels- e.g. 640 integers per row starting at the left pixel, 480 rows per frame starting at the top row, repeat for n frames. Is there an easy way to feed this to ffmpeg (or some other encoder) without first encoding it to a common image format?

    I'm assuming ffmpeg is the best tool for me to use in this case, but I'm open to suggestions (the output video format doesn't matter too much).


    I know the documentation would enlighten me if I just knew the right keywords... In case I'm asking the wrong question, here's what I'm trying to do at the highest level:

    I have some Actionscript code that draws and animates on the display tree, and I've wrapped it in an AIR application that draws BitmapData frame-by-frame. AIR has proved to be woefully inefficient at directly encoding this output- the best I've managed is a few frames per second, and I need to render at least 15 fps, preferably more like 100 fps, which I get out of ffmpeg when I feed it PNG images (AIR can take 1+ seconds to encode one 640x480 png... appalling). Instead of encoding inside AIR I can send the raw byte data out to an encoder or to disk as fast as it's rendered.

    If you're wondering why I'm using Actionscript to render an animation or why it has to be encoded quickly, don't. Suffice it to say, the frames are computed at execution time (not stored as an animation in a .swf file, for example), I have a very large amount of video to create and limited time to do so, and using something other than Actionscript to produce the frames is not an option.

  • What are the video streaming specifics : video coded parameters, web server configuration, video player ?

    20 septembre 2011, par albanx

    With my server I encode videos from any format to mp4 with ffmpeg, for making play them with flowplayer on the web site. The problem is that videos buffering is not working. Video plays once it has been fully buffered (downloaded).

    • Should mp4 videos be encoded in any particular way for having streaming work?
    • Or maybe the IIS7 server need extra configuration?
    • I am using php for getting video files: getMedia?file=asd.mp4

    I have IIS7 web server with php. Any suggestions?

  • FFMpeg doesn't convert the video, just creates a thumb... It was working now not ?

    20 septembre 2011, par Matt Reid

    Theres a site im making for someone where it uses FFMpeg to convert the files to MP4's... I set it up and got the converter working... but now a week or so later ive came to use it and it doesn't convert the video, it runs the create thumbnail exec() but the video exec() doesn't run. It returns a 1 status like its gone through but there is no converted file and the browser quickly processes the convert file rather than lagging for a few seconds like it did when it was working...

    Any ideas?

     <?php
    
     //Thumbnail VARS
     $tn_size = '480x360';
     $tn_interval = 3;
     $tn_type = 'mjpeg';
    
     //Video VARS
     $vi_size = '480x360';
     $vi_fileto = 'mp4';
    
     //Default Setup
     $id = $_GET['ListingID'];
     $ext = $_GET['Ext'];
     $temp_url = '/var/www/files/videos-tmp/'.$id.".".$ext;
     $new_url = '/var/www/files/videos/'.$id.".mp4";
     $new_url_thumb = '/var/www/files/videos-thumb/'.$id.".jpg";
    
     //echo $new_url."
    ".$id." ".$ext. " " .$temp_url; //Do if(file_exists($temp_url)) { @unlink($new_url); //echo "/usr/local/bin/ffmpeg -i {$temp_url} -f {$vi_fileto} -r 25 -ar 22050 -ab 48000 -ac 1 -s {$vi_size} {$new_url}"; exec("/usr/local/bin/ffmpeg -i {$temp_url} -deinterlace -an -ss $tn_interval -f {$tn_type} -t 1 -r 1 -y -s $tn_size '{$new_url_thumb}'"); //make thumbnai exec("/usr/local/bin/ffmpeg -i {$temp_url} -f {$vi_fileto} -r 25 -ar 22050 -ab 48000 -ac 1 -s {$vi_size} {$new_url}",$output,$status); //convert video //@unlink($temp_url); if(isset($_GET['UsrOvr'])) { } else { echo "Convert Complete"; echo "

    Return to listings page."; exit; } } else { die("The video selected does not exist!"); } ?>
  • Tell a java servlet when to return from an external command line call

    20 septembre 2011, par Morgan

    I have a java servlet api, that when requested, starts a live conversion of a video file using ffmpeg and pipes it to mediastreamsegmenter to segment it for http live streaming. What I want is for the java servlet to return the url of the index file as soon as it has been generated (after the 4th transport stream file is written) so the user can start watching the video without waiting for it to fully finish converting.

    How I was thinking of achieving this was to pass a command into the -file-complete-command argument of mediastreamsegmenter, and have it call some sort of a command that could tell the java servlet to return its response if the last file completed was the index file.

    Another idea I had was to just segment the first 30 seconds or so of the video, and then return the response, and add the remainder of the video into some sort of a background task in the servlet. I'm not sure how this would be done though. Could I create a separate thread to do this conversion that will continue to run after the servlet returns? I'm sure there must be a better way of doing this. Any thoughts would be appreciated.

  • Raw PCM 16 bit 8Khz file to GSM_MS (610) conversion using ffmpeg

    20 septembre 2011, par MANN

    I'm trying to convert a raw PCM 8000Hz MONO 16 bit file to GSM_MS (gsm610) encoded file using the ffmpeg. I Have compiled the ffmpeg with libgsm and while executing code I'm able to get the GSM_MS codec. But as of now I'm not able to create a valid gsm_ms file. Here is my code...

    void EncodeTest(uint8_t *audioData, size_t audioSize){
    AVCodecContext  *audioCodec;
    AVCodec *codec;
    uint8_t *buf;    int bufSize, frameBytes;
    __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG,"Lets encode :%u with size %d\n",(int)audioData, (int)audioSize);
    //Set up audio encoder
    codec = avcodec_find_encoder(CODEC_ID_GSM_MS);
    
    
    
    if (codec == NULL){
        __android_log_print(ANDROID_LOG_ERROR, DEBUG_TAG,"ERROR:: Unable to find encoder(CODEC_ID_GSM)");
        codec = avcodec_find_encoder(CODEC_ID_GSM);
        if (codec == NULL){
            __android_log_print(ANDROID_LOG_ERROR, DEBUG_TAG,"ERROR:: Unable to find encoder(CODEC_ID_GSM)");
            return;
        }
    }
    audioCodec                  = avcodec_alloc_context();
    audioCodec->channels        = 1;
    audioCodec->sample_rate     = 8000;
    audioCodec->sample_fmt      = SAMPLE_FMT_S16;
    audioCodec->bit_rate        = 13200;
    audioCodec->priv_data       = gsm_create();
    audioCodec->codec_id        = CODEC_ID_GSM_MS;
    __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG,"audioCodec->codec_id == %d",audioCodec->codec_id);
    switch(audioCodec->codec_id) {
        case CODEC_ID_GSM:
            audioCodec->frame_size = GSM_FRAME_SIZE;
            audioCodec->block_align = GSM_BLOCK_SIZE;
            int one = 1;
            gsm_option(audioCodec->priv_data, GSM_OPT_WAV49, &one);
            break;
        case CODEC_ID_GSM_MS: {
            int one = 1;
            gsm_option(audioCodec->priv_data, GSM_OPT_WAV49, &one);
            audioCodec->frame_size = 2*GSM_FRAME_SIZE;
            audioCodec->block_align = GSM_MS_BLOCK_SIZE;
        }
    }
    audioCodec->coded_frame= avcodec_alloc_frame();
    audioCodec->coded_frame->key_frame= 1;
    audioCodec->time_base       = (AVRational){1,  audioCodec->sample_rate};
    audioCodec->codec_type      = CODEC_TYPE_AUDIO;
    
    if (avcodec_open(audioCodec, codec) < 0){
        __android_log_print(ANDROID_LOG_ERROR, DEBUG_TAG,"ERROR:: Unable to avcodec_open");
        return;
    }
    
    bufSize     = FF_MIN_BUFFER_SIZE;
    buf         = (uint8_t *)malloc(bufSize);
    if (buf == NULL) return;
    
    
    //frameBytes = audioCodec->frame_size * audioCodec->channels * 2;
    //audioCodec->frame_size = 160;
    frameBytes = audioCodec->frame_size * audioCodec->channels * 2;
    
     //frameBytes = buf_size * input_sample_size / output_sample_size;
    //frameBytes = 160;//audioSize * 8000 / 13000;
    
    
    
    FILE *fileWrite = fopen(FILE_NAME,"w+b");
    if(NULL == fileWrite){
        __android_log_print(ANDROID_LOG_ERROR, DEBUG_TAG,"ERROR:: Unable to open file for reading.");
    }
    /*Write wave header*/
    WriteWav(fileWrite, 127920);/*Just for test*/
    
    /*Lets encode raw packet and write into file after header.*/
    __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG,"Lets Encode Actual Bytes");
    int nChunckSize = 0;
    while (audioSize >= frameBytes)
    {
        int packetSize;
    
        packetSize = avcodec_encode_audio(audioCodec, buf, bufSize, (short *)audioData);
        if(packetSize < 0){
             __android_log_print(ANDROID_LOG_ERROR, DEBUG_TAG,"Encoder returned -ve data, %d bytes of data\n", packetSize);
        }
        __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG,"Consumed Bytes: %d  and encoded Bytes:%d\n", packetSize,bufSize);
        nChunckSize += packetSize;
    
    
        audioData += 160;
        audioSize -= 160;
    
        if(NULL != fileWrite){
            fwrite(buf, 1,packetSize, fileWrite);
        }
        else{
            __android_log_print(ANDROID_LOG_ERROR, DEBUG_TAG,"Unable to open file for writting... NULL");
        }
    }
    if(NULL != fileWrite){
        fclose(fileWrite);
    }
    __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG,"----- Done with nChunckSize: %d --- ",nChunckSize);
     __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG,"*****************************");
    wavReadnDisplayHeader(FILE_NAME);
    __android_log_print(ANDROID_LOG_INFO, DEBUG_TAG,"*****************************");
    wavReadnDisplayHeader("/sdcard/Voicemail2.wav");
    

    } code here