Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Error writing to file when saving matplotlib animation with a given codec

    31 mars 2017, par idesh

    I've had trouble saving an mp4 animation created with matplotlib with a given codec. However I should mention beforehand that I could save the mp4 animation without specifying codecs and that seems to work fine, except that I am not able to insert this mp4 animation into powerpoint for a presentation. Powerpoint says it cannot read the file because it is missing 64bit codec.

    When digging further I discovered that Windows media player which is used by power point for the animations, has already some video codecs installed.

    So I thought of saving the initial matplotlib animation with one of these codecs, which is also compatible with ffmpeg. The command ffmpeg -codecs on terminal lists the supported codecs and I could spot the codecs common with ffmpeg and windows media player, ex: MSS1, MSS2

    So I tried to save the animation with the argument codec set as follows.

    anim = animation.FuncAnimation(fig, animate, 158,interval=300, blit=True)
    writer = animation.writers['ffmpeg']
    anim.save('film_v5.mp4', codec='mss1')
    

    Nevertheless it leads to an error, no matter what type of codec argument I put.

    So I was wondering perhaps there was someone savvy, willing to help me troubleshoot this problem. Despite my attempts I could not find any solution in the stackoverflow forum.

    Thank you in advance for your attention.

  • FFMpeg : Created video from images and wav file in not synced

    31 mars 2017, par Koby Douek

    I am using ffmpeg to create a .mp4 video from hundred of images, 10 per second, and a .wav file.

    This is the command I am using:

    ffmpeg -framerate 10 -i \slides\img_%d.jpeg -i sound.wav -r 10 -pix_fmt yuv420p -shortest output.mp4
    

    When the video is created, the image is OK (measured with a stopwatch), but the audio is slower than the video (smeered), and the unsync is getting worst as the video progresses.

    Any ideas?

  • Android square video cropping [on hold]

    31 mars 2017, par Karthik

    I want to develop a tool that records a video in square frame. I don't want to use ffmpeg as it increase the app size.

    Is there any other way to do this. I came across MediaCodec but don't know how to implement it

    Thanks

  • How convert High bitrate mp3 to lower rate using ffmpeg in android

    31 mars 2017, par Android Weblineindia

    We want to convert 320kbps mp3 file to 128kbps mp3 so currently we are using below ffmpeg command but its not working.

    ffmpeg -i input.mp3 -codec:a libmp3lame -qscale:a 5 output.mp3
    

    Result:-the output bitrate same as input mp3.

    And we are following the FFmpeg Encoding guideline for that here is the link :- https://trac.ffmpeg.org/wiki/Encode/MP3

    so please suggest any solution.

  • Can't play at a good framerate with JavaAV

    31 mars 2017, par TW2

    I have a problem in framerate when I use JavaAV (which use JavaCPP + ffmpeg). When I set my framerate as mentionned at DemuxerExample.java, the frame change each ~47000ms which is too long and false. It's better when I set 1000 / demuxer.getFrameRate() * 1000 (~47ms) but it's also false. I can't have a good framerate. Here is my player class :

    package gr.av;
    
    import hoary.javaav.Audio;
    import hoary.javaav.AudioFrame;
    import hoary.javaav.Demuxer;
    import hoary.javaav.Image;
    import hoary.javaav.JavaAVException;
    import hoary.javaav.MediaFrame;
    import hoary.javaav.VideoFrame;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.SourceDataLine;
    import javax.sound.sampled.UnsupportedAudioFileException;
    import javax.swing.JPanel;
    
    public class Player extends JPanel {
    
        VideoThread videoTHREAD;
        AudioThread audioTHREAD;
        BufferedImage img = null;
    
        public Player() {
            init();
        }
    
        private void init(){        
            videoTHREAD = new VideoThread(this);
            audioTHREAD = new AudioThread();
        }
    
        public void setImage(BufferedImage img){
            this.img = img;
            repaint();
        }
    
        @Override
        public void paint(Graphics g){
            if(img != null){
                g.drawImage(img, 0, 0, null);
            }else{
                g.setColor(Color.blue);
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        }
    
        public void setFilename(String filename){
            videoTHREAD.setFilename(filename);
            audioTHREAD.setFilename(filename);
        }
    
        public void play(){
            videoTHREAD.playThread();
            audioTHREAD.playThread();
        }
    
        public void stop(){
            videoTHREAD.stopThread();
            audioTHREAD.stopThread();
        }
    
        public static class VideoThread extends Thread {
    
            //The video filename and a controller
            String filename = null;
            private volatile boolean active = false;
    
            //Panel to see video
            Player player;
    
            public VideoThread(Player player) {
                this.player = player;
            }
    
            public void setFilename(String filename){
                this.filename = filename;
            }
    
            public void playThread(){
                if(filename != null && active == false){
                    active = true;
                    this.start();
                }
            }
    
            public void stopThread(){
                if(active == true){
                    active = false;
                    this.interrupt();
                }            
            }
    
            public void video() throws JavaAVException, InterruptedException, IOException, UnsupportedAudioFileException{            
                Demuxer demuxer = new Demuxer();
                demuxer.open(filename);
    
                MediaFrame mediaFrame;
                while (active && (mediaFrame = demuxer.readFrame()) != null) {
                    if (mediaFrame.getType() == MediaFrame.Type.VIDEO) {
    
                        VideoFrame videoFrame = (VideoFrame) mediaFrame;
    
                        player.setImage(Image.createImage(videoFrame, BufferedImage.TYPE_3BYTE_BGR));
    
                        double FPS = demuxer.getFrameRate() * 1000d;
                        long ms = (long)(1000d / FPS);
                        System.out.println("FPS = " + FPS + " ; Milliseconds = " + ms);
                        java.util.concurrent.TimeUnit.MILLISECONDS.sleep(ms);
                    }
                }
                demuxer.close();
            }
    
            @Override
            public void run() {
                if(filename != null){
                    try {
                        video();
                    } catch (JavaAVException | InterruptedException | IOException | UnsupportedAudioFileException ex) {
                           Logger.getLogger(Player.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
    
        }
    
        public static class AudioThread extends Thread {
    
            //The video filename and a controller
            String filename = null;
            private volatile boolean active = false;
    
            //Audio
            AudioFormat format = new AudioFormat(44000, 16, 2, true, false);
            AudioInputStream ais;
            DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
            SourceDataLine soundLine;
    
            public AudioThread() {            
            }
    
            public void setFilename(String filename){
                this.filename = filename;
            }
    
            public void playThread(){
                if(filename != null && active == false){
                    active = true;
                    soundON();
                    this.start();
                }
            }
    
            public void stopThread(){
                if(active == true){
                    active = false;
                    soundOFF();
                    this.interrupt();
                }            
            }
    
            public void audio() throws JavaAVException, IOException {            
                Demuxer demuxer = new Demuxer();
                demuxer.open(filename);
    
                MediaFrame mediaFrame;
                while (active && (mediaFrame = demuxer.readFrame()) != null) {
                    if (mediaFrame.getType() == MediaFrame.Type.AUDIO) {
                        AudioFrame audioFrame = (AudioFrame) mediaFrame;
                        byte[] bytes = Audio.getAudio16(audioFrame);
    
                        try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes)) {
                            ais = new AudioInputStream(bais, format, bytes.length / format.getFrameSize());
                            try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
                                int nBufferSize = bytes.length * format.getFrameSize();
                                byte[] abBuffer = new byte[nBufferSize];
    
                                while (true){
                                    int nBytesRead = ais.read(abBuffer);
                                    if (nBytesRead == -1)
                                        break;
    
                                    baos.write(abBuffer, 0, nBytesRead);
                                }
    
                                byte[] abAudioData = baos.toByteArray();
                                soundLine.write(abAudioData, 0, abAudioData.length);
                            }
                            ais.close();
                        }
    
                    }
                }
    
                demuxer.close();
            }
    
            @Override
            public void run() {
                if(filename != null){
                    try {
                        audio();
                    } catch (JavaAVException | IOException ex) {
                        Logger.getLogger(Player.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
    
            private void soundON(){
                try {
                    soundLine = (SourceDataLine) AudioSystem.getLine(info);
                    soundLine.open(format);
                    soundLine.start();
                } catch (LineUnavailableException ex) {
                    Logger.getLogger(Player.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
    
            private void soundOFF(){
                soundLine.drain();
                soundLine.stop();
                soundLine.close();
            }
    
        }
    
    }