Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • FFMPEG command doesn't work in PHP, what am I doing wrong ?

    3 mars 2013, par Charlie Ryan

    I'm a bit of a beginner when it comes to PHP, and I'm trying to create a simple(ish) system where files are input, and then converted to html5 video in various resolutions.

    I've sorted out how to handle multiple file uploads etc, but now I'm having a problem.

    I can't seem to get exec to execute FFMPEG in PHP.

    For example, if I type this into my command line (Terminal on Mac OSX 10.8), It converts the video correctly:

    ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov
    

    This correctly outputs the converted video file into my home directory.

    However if I run this in PHP as follows:

    exec('ffmpeg -i /Users/charlieryan/Desktop/MOV01785.MPG websample.mov');
    

    Absolutely nothing happens ... my stat monitor doesn't register any change in processor use, and I can't find the output file anywhere on my system.

    Since I'm a bit of a noob at this, I'm assuming I'm doing something wrong, but what is it?

    Thanks,

    Charlie

  • Fluent-FFmpeg Blocks any server activity

    3 mars 2013, par user2009114

    I'm having an issue where fluent-ffmpeg will actually make the server hang until it has transcoded a video. I have a script checking if any files need transcoding with Meteor.js server and then calling a fluent-ffmpeg process if needed for those videos. However, when I do this, the server actually can't do anything until fluent-ffmpeg is down transcoding the videos. It just hangs. Is there a way I can get around this? Can I spawn another thread with node.js for this? Or maybe there is a setting in fluent ffmpeg that will allow a workaround?

    Here is my code:

    var x = 0;
    var transcodeAll = function(files){
        console.log("X", x);
        dead_transcode(files[x],function(){
            x++;
            console.log("In callback");
            if(x/ Remove ".." etc
        var rootfile = path.join(rootPath, file);
        var output = file.substr(0, file.lastIndexOf('.')) || file;
        newfile = path.join(rootPath, "/transcoded"+output +".mp4");
        console.log(rootfile);
        console.log(newfile);
    lock=true;
    var proc = new ffmpeg({ source: rootfile, priority: 10 })
    .toFormat('mp4')
    //.withVideoBitrate('1500k')
    .withVideoCodec('libx264')
    //.withSize('720x?')
    //.withAudioBitrate('128k')
    .withAudioCodec('libfaac')
    .saveToFile(newfile, function(stdout, stderr) {
        console.log('file has been converted succesfully');
        lock = false;
        console.log(stdout);
        console.log(stderr);
        callback();
    });
    
    }
    
  • ffmpeg generating out of sync audio/video file

    2 mars 2013, par marcelorocks

    I am trying to convert a flv video to mp4 using a264, but the result video has a out of sync audio/video. Audio seems ok but video seems slow and therefore out of sync. I am a newbie on video conversion so any help is appreciated.

    Here is the command I am running:

    /opt/local/bin/ffmpeg -i complaint.flv -f mp4 -vcodec libx264 -acodec aac -copyts -strict experimental -fpre /opt/local/share/ffmpeg/libx264-lossless_slow.ffpreset -ab 44k -threads 0 -crf 23 complaint.mp4
    

    And the printout:

    Desktop  /opt/local/bin/ffmpeg -i complaint.flv -f mp4 -vcodec libx264 -acodec aac -copyts -strict experimental -fpre /opt/local/share/ffmpeg/libx264-lossless_slow.ffpreset -ab 44k -threads 0 -crf 23 complaint.mp4
    ffmpeg version 0.7.8, Copyright (c) 2000-2011 the FFmpeg developers
      built on Jan 12 2012 21:12:26 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
      configuration: --prefix=/opt/local --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libopenjpeg --enable-libxvid --enable-libx264 --enable-libvpx --enable-libspeex --mandir=/opt/local/share/man --enable-shared --enable-pthreads --cc=/usr/bin/gcc-4.2 --arch=x86_64 --enable-yasm
      libavutil    50. 43. 0 / 50. 43. 0
      libavcodec   52.123. 0 / 52.123. 0
      libavformat  52.111. 0 / 52.111. 0
      libavdevice  52.  5. 0 / 52.  5. 0
      libavfilter   1. 80. 0 /  1. 80. 0
      libswscale    0. 14. 1 /  0. 14. 1
      libpostproc  51.  2. 0 / 51.  2. 0
    [flv @ 0x7fe57a04ac00] Estimating duration from bitrate, this may be inaccurate
    Input #0, flv, from 'complaint.flv':
      Metadata:
        duration        : 7
        creationdate    : Thu Jan 12 23:47:24
        description     : Recorded using VideoRecording example.
      Duration: 00:00:06.61, start: 0.000000, bitrate: N/A
        Stream #0.0: Video: flv, yuv420p, 288x288, 1k tbr, 1k tbn, 1k tbc
        Stream #0.1: Audio: nellymoser, 11025 Hz, mono, s16
    File 'complaint.mp4' already exists. Overwrite ? [y/N] y
    [buffer @ 0x7fe579c32cc0] w:288 h:288 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:
    [libx264 @ 0x7fe57a044600] using cpu capabilities: none!
    [libx264 @ 0x7fe57a044600] profile High, level 4.2
    [libx264 @ 0x7fe57a044600] 264 - core 118 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=2 deblock=1:0:0 analyse=0x3:0x33 me=umh subme=6 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=0 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.41 aq=1:1.00
    Output #0, mp4, to 'complaint.mp4':
      Metadata:
        duration        : 7
        creationdate    : Thu Jan 12 23:47:24
        description     : Recorded using VideoRecording example.
        encoder         : Lavf52.111.0
        Stream #0.0: Video: libx264, yuv420p, 288x288, q=0-69, 200 kb/s, 1k tbn, 1k tbc
        Stream #0.1: Audio: aac, 11025 Hz, mono, s16, 44 kb/s
    Stream mapping:
      Stream #0.0 -> #0.0
      Stream #0.1 -> #0.1
    Press [q] to stop, [?] for help
    frame= 6557 fps=106 q=-1.0 Lsize=     685kB time=00:00:03.62 bitrate=1549.1kbits/s dup=6367 drop=0    
    video:615kB audio:17kB global headers:0kB muxing overhead 8.361360%
    frame I:27    Avg QP:19.98  size:  8242
    [libx264 @ 0x7fe57a044600] frame P:6530  Avg QP:30.71  size:    62
    [libx264 @ 0x7fe57a044600] mb I  I16..4: 11.1% 79.3%  9.6%
    [libx264 @ 0x7fe57a044600] mb P  I16..4:  0.1%  0.2%  0.0%  P16..4:  1.2%  0.2%  0.3%  0.0%  0.0%    skip:98.0%
    [libx264 @ 0x7fe57a044600] 8x8 transform intra:77.8% inter:64.9%
    [libx264 @ 0x7fe57a044600] coded y,uvDC,uvAC intra: 75.3% 81.3% 33.3% inter: 0.5% 0.7% 0.1%
    [libx264 @ 0x7fe57a044600] i16 v,h,dc,p: 78%  9% 10%  3%
    [libx264 @ 0x7fe57a044600] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 35% 11% 32%  3%  4%  5%  2%  5%  4%
    [libx264 @ 0x7fe57a044600] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 56%  7%  9%  3%  4%  7%  3%  7%  3%
    [libx264 @ 0x7fe57a044600] i8c dc,h,v,p: 45% 15% 34%  6%
    [libx264 @ 0x7fe57a044600] Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 0x7fe57a044600] ref P L0: 80.5%  9.5% 10.0%
    [libx264 @ 0x7fe57a044600] kb/s:767.20
    
  • Meteor Spawn_Child_Process for FFMpeg [duplicate]

    2 mars 2013, par user2009114

    Hi I am trying to use Meteor and javascript (Node) to spawn an ffmpeg transcoding event and then stream it live through HTML5 video tags. However, though I can get it working with node.js it seems to hang on the Meteor server and not stream anything though it does seem to be transcoding okay. It appears that the transcoding thread hangs up the server, or is not even a different thread at all? I am pasting the relevant server side code followed by the client code calling it. One JQuery function calls the transcoding process and the PollForPlaylist is called from the video tags by the hls/. Any help would be much appreciated in solving this. I am wondering if there is a meteor function which I can call to spawn a thread for the ffmpeg function? Or maybe there is another way to push data to the video tag through jQuery?

    var spawnNewProcess = function(file, playlistPath) {
        var outputUrlPrefix = '/segment/';
        var args = ['-i', file, '-async', '1', '-acodec', 'libmp3lame', '-b:a', 128 + 'k', '-vf', 'scale=min(' + targetWidth + '\\, iw):-1', '-b:v', videoBitrate + 'k', '-ar', '44100', '-ac', '2', '-vcodec', 'libx264', '-x264opts', 'level=3.0', '-profile:v', 'baseline', '-preset:v' ,'superfast', '-threads', '0', '-flags', '-global_header', '-map', '0', '-f', 'segment', '-segment_time', '10', '-segment_list', 'stream.m3u8', '-segment_format', 'mpegts', '-segment_list_flags', 'live', 'stream%05d.ts'];
    
        var encoderChild = childProcess.spawn(transcoderPath, args, {cwd: outputPath});
    
        console.log(transcoderPath + args);
    
        encoderProcesses[file] = encoderChild;
        currentFile = file;
    
        console.log('Spawned transcoder instance');
    
        if (debug) {
            encoderChild.stderr.on('data', function(data) {
                console.log(data.toString());
            });
        }
    
        encoderChild.on('exit', function(code) {
            console.log('Transcoder exited with code ' + code);
    
            delete encoderProcesses[file];
        });
    
        // Kill any "zombie" processes
        setTimeout(function() {
            if (encoderProcesses[file]) {
                console.log('Killing long running process');
    
                killProcess(encoderProcesses[file]);
            }
        }, processCleanupTimeout);
    };
    
    var pollForPlaylist = function(file, response) {
        var numTries = 0;
        console.log("IN POLL FOR PLAYLIST");
    
        var tryOpenFile = function() {
            if (numTries > 20) {
                console.log('Gave up trying to open m3u8 file');
                response.writeHead(500);
                response.end();
            }
            else {
                console.log("IN ELSE");
                fs.readFile(playlistPath, function (err, data) {
                    console.log("Trying to read file");
                    if (err || data.length === 0) {
                        numTries++;
                        setTimeout(tryOpenFile, 200);
                        console.log("ERROR, number of tries", numTries);
                    }
                    else {
                        if (!debug) {
                            response.setHeader('Content-Type', 'application/x-mpegURL');
                        }
                        console.log('response: ' + data);
                        response.write(data);
                        response.end();
                    }
                });
            }
        };
            console.log("Try open");
            tryOpenFile();
    };
    
    var killProcess = function(processToKill, callback) {
        processToKill.kill();
    
        setTimeout(function() {
            processToKill.kill('SIGKILL');
        }, 5000);
    
        processToKill.on('exit', function(code) {
            if (callback) callback();
        });
    }
    
    var handlePlaylistRequest = function(file, request, response) {
        if (!file) {
            request.writeHead(400);
            request.end();
        }
    
        if (lock) {
            console.log('Ongoing spawn process not finished, denying request');
            response.writeHead(503);
            response.end();
            return;
        }
    
        file = path.join('/', file); // Remove ".." etc
        file = path.join(rootPath, file);
    
        console.log("PLAYLIST PATH", playlistPath);
        if (currentFile != file) {
            lock = true;
    
            console.log('New file to encode chosen');
    
            // Make sure old one gets killed
            if (encoderProcesses[currentFile]) {
                killProcess(encoderProcesses[currentFile], function() {
                    fs.unlink(playlistPath, function (err) {
                        spawnNewProcess(file, playlistPath, outputPath);
                        lock = false;
                    });
                });
            }
            else {
                fs.unlink(playlistPath, function (err) {
                    spawnNewProcess(file, playlistPath, outputPath);
                    lock = false;
                });
            }
            currentFile = file;
        }
    };
    

    The Client side code which calls this is:

    var videoNode = document.querySelector('video');
    $.get('hls/?file='+file);
    videoNode.src = "hls/" + file;
    
  • Encoder/Decoder PCM to AMR Android

    2 mars 2013, par Syred

    I've been looking for a while now for any java library that allows me to encode and decode a PCM-AMR audio stream that is sent through a TCP socket connection. Without having to use Android's JNI.

    Is there anything that can help me?

    In the worst case scenario. How can I do it using any C++ library with JNI? (any reference of how to use ffmpeg with JNI will be appreciated)

    Hope you can help me.