Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • ffmpeg not returning duration, cant play video until complete. Stream images 2 video via PHP

    17 février 2014, par John J

    I am real struggling with ffmpeg. I am trying to convert images to video, I have an ip camera which I am recording from. The recordings are mjpegs 1 frame per image.

    I am trying to create a script in php so I can recreate a video from date to date, this requires inputting the images via image2pipe and then creating the video.

    The trouble is, ffmpeg does return the duration and start stats, so I have no way of working out when the video is done or what percentage is done. The video won't play until its finished, and its not a very good UE.

    Any ideas of how I can resolve this, the video format can be anything I am open to suggestions.

    PHP:

    //Shell command
    exec('cat /image/dir/*.jpg | ffmpeg -y -c:v mjpeg -f image2pipe -r 10 -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart myvids/vidname.mp4 1>vidname.txt 2>&1')
    
    //This is loaded via javascript when the video is loaded (which is failing due to stats being wrong
    $video_play = "";
    

    Javascript:

    //Javascript to create the loop until video is loaded
    <script>
    $(document).ready(function() {
    var loader = $("#clip_load").percentageLoader();
    $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
    var interval = setInterval(updateProgress,1000);
    function updateProgress(){ $.get( "&#39;.base_url().&#39;video/getVideoCompile_Process?l=&#39;.$vid_name.&#39;-output.txt&amp;t=per", function( data ) { if(data=>\&#39;100\&#39;){ $("#clip_load").html(\&#39;&#39;.$video_play.&#39;\&#39;); clearInterval(interval); }else{loader.setProgress(data); } }); }
    });
    </script>

    PHP (page is called via javascript:

    //This is the script which returns the current percentage
    $logloc = $this->input->get('l');
    $content = @file_get_contents($logloc);
    
    if($content){
        //get duration of source
        preg_match("/Duration: (.*?), start:/", $content, $matches);
    
        $rawDuration = $matches[1];
    
        //rawDuration is in 00:00:00.00 format. This converts it to seconds.
        $ar = array_reverse(explode(":", $rawDuration));
        $duration = floatval($ar[0]);
        if (!empty($ar[1])) $duration += intval($ar[1]) * 60;
        if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60;
    
        //get the time in the file that is already encoded
        preg_match_all("/time=(.*?) bitrate/", $content, $matches);
    
        $rawTime = array_pop($matches);
    
        //this is needed if there is more than one match
        if (is_array($rawTime)){$rawTime = array_pop($rawTime);}
    
        //rawTime is in 00:00:00.00 format. This converts it to seconds.
        $ar = array_reverse(explode(":", $rawTime));
        $time = floatval($ar[0]);
        if (!empty($ar[1])) $time += intval($ar[1]) * 60;
        if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;
    
        //calculate the progress
        $progress = round(($time/$duration) * 100);
        if ($this->input->get('t')=='per'){
            echo $progress;
        }else{
                echo "Duration: " . $duration . "
    "; echo "Current Time: " . $time . "
    "; echo "Progress: " . $progress . "%";} }else{ echo "cannot locate";}

    Thanks

  • Get Stream and save as jpeg (image) file from IP Camera using ffmpeg

    17 février 2014, par Mustafa Ekici

    How i can get stream from Ip Camera, Its using RTP, stream is MPEG4, i have multicast address and port,and i have ip camera's IP address and Port Number.
    And I cant reach via http forexample (http://ip/jpeg) And I cant reach stream with VLC Player too. forexample (rtp://ipadressofcam:port) and (rtp://multicastaddress:port)
    So What is ffmpeg command of that?
    I have windows OS, I only write code with C# right now.
    But producer created their own ocx which used for viewing cam,that plugin can work on .net but i dont want to use it becouse it doesnt have much funcionality, I mean you cant get current picture or snapshot of cams, thats why i have to do it myself.

  • Terminating a c function

    17 février 2014, par dempap

    I want to make a function in c, that will capture video under Linux. I embedded ffmpeg command via system() in my c program, which captures video. ffmpeg terminates by pressing [q]. How can I include termination into my c program.

    This function is part of a server.c program. When client requests for termination, I want video cature function to terminate. Is this possible?

    #include
    #include 
    
    
    main()
    {
    
    char command[180];
    
    sprintf(command, "ffmpeg -f v4l2 -r 25 -s 640x480 -i /dev/video0 out.avi");
    system(command);
    
    }
    
  • how to convert videos to flv using ffmpeg in php ?

    17 février 2014, par Patrioticcow

    i am trying to convert some different video formats to flv using ffmpeg. But it seems that only some videos go through.

    ffmpeg -i /var/www/tmp/91640.avi -ar 22050 -ab 32 -f flv /var/www/videos/91640.flv

    here is some debug info:

    Seems stream 0 codec frame rate differs from container frame rate: 23.98 (65535/2733) -> 23.98 (5000000/208541)
    Input #0, avi, from '/var/www/tmp/91640.avi':
      Duration: 00:01:12.82, start: 0.000000, bitrate: 5022 kb/s
        Stream #0.0: Video: mpeg4, yuv420p, 1280x528 [PAR 1:1 DAR 80:33], 23.98 tbr, 23.98 tbn, 23.98 tbc
        Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 448 kb/s
    WARNING: The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
    Output #0, flv, to '/var/www/videos/91640.flv':
        Stream #0.0: Video: flv, yuv420p, 1280x528 [PAR 1:1 DAR 80:33], q=2-31, 200 kb/s, 90k tbn, 23.98 tbc
        Stream #0.1: Audio: adpcm_swf, 22050 Hz, 5.1, s16, 0 kb/s
    Stream mapping:
      Stream #0.0 -> #0.0
      Stream #0.1 -> #0.1
    Error while opening codec for output stream #0.1 - maybe incorrect parameters such as bit_rate, rate, width or height
    

    also, if i try to grab one frame ad convert it to jpeg i get an error as well

    ffmpeg -i /var/www/tmp/91640.avi -an -ss 00:00:03 -t 00:00:01 -r 1 -y /var/www/videos/91640.jpg

    debug info

    ...
    [mpeg4 @ 0x1d7d810]Invalid and inefficient vfw-avi packed B frames detected
    av_interleaved_write_frame(): I/O error occurred
    Usually that means that input file is truncated and/or corrupted.
    

    im thinking that the image fails because the video conversion failed in the first place, not sure though

    any ideas what goes wrong?

  • Determine if OpenCV has FFMpeg Support at Configuration Time

    17 février 2014, par archgoon

    I'm building my project with CMake, but I want to throw an error if OPENCV has not been compiled with FFMPEG support (as this will prevent a large amount of functinoality of my application). How can I modify my CMake scripts to check for this?