Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Php fail converting avi to mp4

    27 octobre 2013, par Dirk Swarz

    I'm able to convert video via server command using:

    ffmpeg -i movie.avi -acodec libmp3lame -vcodec libx264 -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 goodmovie.mp4
    

    For this test I used a 1.8mb video and after conversion it is 5 MB. I'm able to upload the video to my server after I download it from FTP and it will work with flash player, but when I try to automate this it fails.

    CODE:

    $ffmpeg_command = 'ffmpeg -i '.$new_name.' -acodec libmp3lame -vcodec libx264 -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 '.$anew_name;
    $convert_avi = true;
    

    It converts to MP4, but

    • it is not 5 MB but rather 2.2 MB when the original file is 1.8 MB

    • it doesn't play in flash player

  • ffmpeg ideal format to convert videos using ffmpeg

    27 octobre 2013, par Offboard

    well the thing is, I intend to do a conversion of videos in the following qualities 240p, 360, 480p and 720p

    I researched a lot out there and got some codes to use, but there's something wrong some videos takes several hours to convert and shows this message.

    [libvo_aacenc @ 000000000032a0a0] Bitrate 32 is extremely low, maybe you mean 32k
    The bitrate parameter is set too low. It takes bits/s as argument, not kbits/s
    

    but some videos converts normally what I want is if someone has done some code that converts faster and is lighter in player jwplayer

    ffmpeg -i discovery_channel.webm -ar 22050 -ab 32 -f mp4 -s 640x240 -preset ultrafast video240.mp4
    
    ffmpeg -i discovery_channel.webm -ar 22050 -ab 32 -f mp4 -s 640x360 video360.mp4
    
    ffmpeg -i FIDELIDADE.mp4 -ar 22050 -ab 32 -f flv -s 640x720 -preset ultrafast video720.mp4
    
    ffmpeg -i FIDELIDADE.mp4 -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 video720.mp4
    
    ffmpeg -i discovery_channel.webm -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 video360.mp4
    

    the last code I like most because it makes the conversion from vertical to 720 pixels, and does nothing in the horizontal video.

    I tested several codes, when some take too much when video with the extension "webm"

    anyway if someone has a good code that works in jwplayer and is unversão serves to any video.

  • video overwriting using ffmpeg - I want to Add video rotation code and rewrite the existing file..How can i do that ?

    27 octobre 2013, par Lakshmi Priya.K

    I want to rotate the .mov file which is in portrait mode by 90 degrees, for that i used the following code.. It works but, it results in loss of video frames...

    My code is,

    public void encode(File source, File target, EncodingAttributes attributes,
            EncoderProgressListener listener, Integer i) throws IllegalArgumentException,
            InputFormatException, EncoderException {        
        String formatAttribute = attributes.getFormat();
    
        Float offsetAttribute = attributes.getOffset();
    
        Float durationAttribute = attributes.getDuration();
    
        QualityScale qualityScale = attributes.getQualityScale();
    
        AudioAttributes audioAttributes = attributes.getAudioAttributes();
    
        VideoAttributes videoAttributes = attributes.getVideoAttributes();
    
        if (audioAttributes == null && videoAttributes == null) {
            throw new IllegalArgumentException(
                    "Both audio and video attributes are null");
        }
        target = target.getAbsoluteFile();
        target.getParentFile().mkdirs();        
        FFMPEGExecutor ffmpeg = locator.createExecutor();
        if (offsetAttribute != null) {
            ffmpeg.addArgument("-ss");
            ffmpeg.addArgument(String.valueOf(offsetAttribute.floatValue()));
        }
        ffmpeg.addArgument("-i");
        ffmpeg.addArgument(source.getAbsolutePath());
        if (durationAttribute != null) {
            ffmpeg.addArgument("-t");
            ffmpeg.addArgument(String.valueOf(durationAttribute.floatValue()));
        }
        if (qualityScale != null) {
            ffmpeg.addArgument("-qscale:"+qualityScale.getQualityStreamSpecifier());
            ffmpeg.addArgument(String.valueOf(qualityScale.getQualityValue()));
        }
        if (videoAttributes == null) {
            ffmpeg.addArgument("-vn");
        } else {
            String codec = videoAttributes.getCodec();
            if (codec != null) {
                ffmpeg.addArgument("-vcodec");
                ffmpeg.addArgument(codec);
            }
            String tag = videoAttributes.getTag();
            if (tag != null) {
                ffmpeg.addArgument("-vtag");
                ffmpeg.addArgument(tag);
            }
            Integer bitRate = videoAttributes.getBitRate();
            if (bitRate != null) {
                ffmpeg.addArgument("-b");
                ffmpeg.addArgument(String.valueOf(bitRate.intValue()));
            }
            Integer frameRate = videoAttributes.getFrameRate();
            if (frameRate != null) {
                ffmpeg.addArgument("-r");
                ffmpeg.addArgument(String.valueOf(frameRate.intValue()));
            }
            VideoSize size = videoAttributes.getSize();
            if (size != null) {
                ffmpeg.addArgument("-s");
                ffmpeg.addArgument(String.valueOf(size.getWidth()) + "x"
                        + String.valueOf(size.getHeight()));
            }
            FilterGraph filterGraph = videoAttributes.getFilterGraph();
            if (filterGraph != null) {
                ffmpeg.addArgument("-vf");
                if(videoAttributes.getRotate() != null && videoAttributes.getRotate() == 90){                   
                    ffmpeg.addArgument("transpose=1");
                }else if(videoAttributes.getRotate() != null && videoAttributes.getRotate() == 180){
                    ffmpeg.addArgument("vflip,hflip");
                }               
                else {
                    if (filterGraph.isUseExpression()) {
                        ffmpeg.addArgument(filterGraph.getFilterGraphExpression());
                    }
                }           
    
            }
    
        }
        if (audioAttributes == null) {
            ffmpeg.addArgument("-an");
        } else {
            String codec = audioAttributes.getCodec();
            if (codec != null) {
                ffmpeg.addArgument("-acodec");
                ffmpeg.addArgument(codec);
            }
            Integer bitRate = audioAttributes.getBitRate();
            if (bitRate != null) {
                ffmpeg.addArgument("-ab");
                ffmpeg.addArgument(String.valueOf(bitRate.intValue()));
            }
            Integer channels = audioAttributes.getChannels();
            if (channels != null) {
                ffmpeg.addArgument("-ac");
                ffmpeg.addArgument(String.valueOf(channels.intValue()));
            }
            Integer samplingRate = audioAttributes.getSamplingRate();
            if (samplingRate != null) {
                ffmpeg.addArgument("-ar");
                ffmpeg.addArgument(String.valueOf(samplingRate.intValue()));
            }
            Integer volume = audioAttributes.getVolume();
            if (volume != null) {
                ffmpeg.addArgument("-vol");
                ffmpeg.addArgument(String.valueOf(volume.intValue()));
            }
        }
        ffmpeg.addArgument("-f");
        ffmpeg.addArgument(formatAttribute);
        ffmpeg.addArgument("-y");
        ffmpeg.addArgument(target.getAbsolutePath());       
        try {
            ffmpeg.execute();
        } catch (IOException e) {
            throw new EncoderException(e);
        }
        try {
            String lastWarning = null;
            long duration;
            long progress = 0;
            RBufferedReader reader = null;
            reader = new RBufferedReader(new InputStreamReader(ffmpeg
                    .getErrorStream()));
            MultimediaInfo info = parseMultimediaInfo(source, reader);
            if (durationAttribute != null) {
                duration = (long) Math
                        .round((durationAttribute.floatValue() * 1000L));
            } else {
                duration = info.getDuration();
                if (offsetAttribute != null) {
                    duration -= (long) Math
                            .round((offsetAttribute.floatValue() * 1000L));
                }
            }
            if (listener != null) {
                listener.sourceInfo(info);
            }
            int step = 0;
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println("line::::"+line);
    
                if (step == 0) {
                    if (line.startsWith("WARNING: ")) {
                        if (listener != null) {
                            listener.message(line);
                        }
                    } else if (!line.startsWith("Output #0")) {
                        //throw new EncoderException(line);
                    } else {
                        step++;
                    }
                } else if (step == 1) {
                    if (!line.startsWith("  ")) {
                        step++;
                    } else {
                        System.out.println("line>>>>>>"+line);
                        Hashtable table1 = new Hashtable();
                        Matcher m = ROTATE_INFO_PATTERN.matcher(line);
                        while (m.find()) {
                            if (table1 == null) {
                                table1 = new Hashtable();
                            }
                            String key = m.group(1);
                            String value = m.group(2);
                            table1.put(key, value);
                        }
                        System.out.println("Table values"+table1.get("rotate"));                
                        if(table1.get("rotate") != null){
                            Object videoRotateValue = table1.get("rotate");
                            int rotate = Integer.valueOf(videoRotateValue.toString());
                            switch(rotate){
                            case 90: 
                                    videoAttributes.setRotate(rotate);
                                    if(i == 0){
                                        i++;                                        
                                        encode(source, target, attributes, null, i);                                        
                                    }
    
                            break;
                            case 180:                       
                                videoAttributes.setRotate(rotate);
                                if(i == 0){
                                    i++;
                                    encode(source, target, attributes, null, i);                                        
                                }
    
                        break;
                            case 270: System.out.println("case 3 :: "+videoRotateValue);
                            break;
                            }
                        }
                    }
                }
                if (step == 2) {
                    if (!line.startsWith("Stream mapping:")) {
                        throw new EncoderException(line);
                    } else {
                        step++;
                    }
                } else if (step == 3) {
                    if (!line.startsWith("  ")) {
                        step++;
                    }
                }
                if (step == 4) {
                    line = line.trim();
                    if (line.length() > 0) {
                        Hashtable table = parseProgressInfoLine(line);
                        if (table == null) {
                            if (listener != null) {
                                listener.message(line);
                            }
                            lastWarning = line;
                        } else {
                            if (listener != null) {
                                String time = (String) table.get("time");
                                if (time != null) {
                                    int dot = time.indexOf('.');
                                    if (dot > 0 && dot == time.length() - 2
                                            && duration > 0) {
                                        String p1 = time.substring(0, dot);
                                        String p2 = time.substring(dot + 1);
                                        try {
                                            long i1 = Long.parseLong(p1);
                                            long i2 = Long.parseLong(p2);
                                            progress = (i1 * 1000L)
                                                    + (i2 * 100L);
                                            int perm = (int) Math
                                                    .round((double) (progress * 1000L)
                                                            / (double) duration);
                                            if (perm > 1000) {
                                                perm = 1000;
                                            }
                                            listener.progress(perm);
                                        } catch (NumberFormatException e) {
                                            ;
                                        }
                                    }
                                }
                            }
    
                            lastWarning = null;
                        }
                    }
                }
            }
            if (lastWarning != null) {
                if (!SUCCESS_PATTERN.matcher(lastWarning).matches()) {
                    throw new EncoderException(lastWarning);
                }
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            ffmpeg.destroy();
        }
    }
    

    Please advise, how to achieve video rotation without any video Frame loss

    Thanks In Advance

    Lakshmi Priya . K

  • Converting avi to mp4 php fail

    27 octobre 2013, par Dirk Swarz

    I'm able to convert video via server command using:

    ffmpeg -i movie.avi -acodec libmp3lame -vcodec libx264 -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 goodmovie.mp4
    

    For this test I used a 1.8mb video and after conversion it is 5 MB. I'm able to upload the video to my server after I download it from FTP and it will work with flash player, but when I try to automate this it fails.

    CODE:

    $ffmpeg_command = 'ffmpeg -i '.$new_name.' -acodec libmp3lame -vcodec libx264 -s 1280x720 -ar 44100 -async 44100 -r 29.970 -ac 2 -qscale 5 '.$anew_name;
    $convert_avi = true;
    

    It converts to MP4, but

    • it is not 5 MB but rather 2.2 MB when the original file is 1.8 MB
    • it doesn't play in flash player.

    The main upload script is in upload.php which anyone can download from here:

    http://www.mediafire.com/?lp3f5pjal2oc19c

    That code which i provided i just put into config.php

  • Jwplayer function snapshot using ffmpeg and php

    27 octobre 2013, par Offboard

    before anything I'm using version 6, then the Snapshot plugin does not work.

    I'm finally with 2 questions, take a sequence of photos of a percentage of the video, so googled it and got this code from ffmpeg:

    ffmpeg -i video.mp4 -r 0.5 -f image2 output-%05d.jpeg
    

    so far so good, but I do not know how to take a screen shot of the video by setting the time, if I'm right this code is per frame.

    I searched again to get the function that calls the images, to generate good is quite simple, but the problem is that I found the pictures looks is all in one look.

    if anyone has any function or know how to do please tell me: D My English sucks, so do not call if I messed up.