Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • non monotonically increasing dts to muxer in stream

    2 décembre 2013, par Yuvraj Kakkar

    Trying to publishlive streaming video via incoming live stream via rtmp.But the video's pixel get breakdown when played live.Error generates non monotonically increasing dts to muxer in stream. I am using xuggler api.

     import com.xuggle.xuggler.ICodec;
        import com.xuggle.xuggler.IContainer;
        import com.xuggle.xuggler.IContainerFormat;
        import com.xuggle.xuggler.IPacket;
        import com.xuggle.xuggler.IRational;
        import com.xuggle.xuggler.IStream;
        import com.xuggle.xuggler.IStreamCoder;
        import com.xuggle.xuggler.IVideoPicture;
    
    public class XugglerRecorder
    {   
    
    
         public static void main(String[] args)
        {
            String url = "rtmp://localhost:1935/live2/16_8_2013_10_0_0";
            IContainer readContainer = IContainer.make();
           // readContainer.setInputBufferLength();
            IContainer writeContainer=IContainer.make();
            //writeContainer.setInputBufferLength(0);
            IContainerFormat containerFormat_live = IContainerFormat.make();
            containerFormat_live.setOutputFormat("flv","rtmp://localhost:1935/live/abc", null);
           int retVal= writeContainer.open("rtmp://localhost:1935/live/abc", IContainer.Type.WRITE, containerFormat_live);
            //writeContainer.setInputBufferLength(0);
            if (retVal < 0) {
                System.err.println("Could not open output container for live stream");
                System.exit(1);
            }
            if (readContainer.open(url, IContainer.Type.READ, null, true, false) < 0) {
                throw new RuntimeException("unable to open read container");
            }
            IStream video = writeContainer.addNewStream(0);
            if (video == null) {
                throw new RuntimeException("unable to add video stream");
            }
            IPacket packet = IPacket.make();
            while (readContainer.readNextPacket(packet) >= 0 && !packet.isKeyPacket()) {}         
            IStreamCoder inVideoCoder = null;
            int videoStreamId = -1;
            for (int i = 0; i < readContainer.getNumStreams(); ++i) {
                IStream stream = readContainer.getStream(i);
                IStreamCoder coder = stream.getStreamCoder();
                if (coder.getCodecType() == ICodec.Type.CODEC_TYPE_VIDEO) {
                    inVideoCoder = coder;
                    videoStreamId = i;
                    if (inVideoCoder.open(null, null) < 0) {
                        throw new RuntimeException("Unable to open input video coder");
                    }
                    //for getting frame params need to decode at least one key frame
                    IVideoPicture picture = IVideoPicture.make(inVideoCoder.getPixelType(), 0, 0);
                    int bytesDecoded = inVideoCoder.decodeVideo(picture, packet, 0);
                    if (bytesDecoded < 0) {
                        throw new RuntimeException("Unable to decode video packet");
                    }
                 }
            }
    
            if (videoStreamId == -1) {
                throw new RuntimeException("unable to find video stream");
            }        
    
            IStreamCoder outVideoCoder = video.getStreamCoder();
            ICodec codec = ICodec.findEncodingCodec(ICodec.ID.CODEC_ID_H264);
            outVideoCoder.setCodec(codec);
          //  outVideoCoder.setCodec(inVideoCoder.getCodec());
            outVideoCoder.setHeight(inVideoCoder.getHeight());
            outVideoCoder.setWidth(inVideoCoder.getWidth());
            outVideoCoder.setPixelType(inVideoCoder.getPixelType());
            outVideoCoder.setBitRate(200000);
            outVideoCoder.setAutomaticallyStampPacketsForStream(true);
            outVideoCoder.setChannels(inVideoCoder.getChannels());
            outVideoCoder.setFrameRate(inVideoCoder.getFrameRate());
            outVideoCoder.setTimeBase(inVideoCoder.getTimeBase());
            if (outVideoCoder.open(null, null) < 0) {
                throw new RuntimeException("unable to open output video coder");
            }
            if (writeContainer.writeHeader() < 0) {
                throw new RuntimeException("unable to write header");
            }
           Thread1 t1= new Thread1(readContainer, packet, writeContainer);
           t1.start();
            try {
            } catch (Exception e) {
                e.printStackTrace();
            } 
        }
    }
    
        class Thread1 extends Thread
        {
            IContainer readContainer;
            IPacket packet;
            IContainer writeContainer;
            Thread1(IContainer readContainer, IPacket packet,IContainer writeContainer)
            {
               this.readContainer=readContainer;
               this.packet=packet;
               this.writeContainer=writeContainer;
            }
    
         public void run()
         {
             try{
                doit(readContainer, packet, writeContainer);
                        }catch(Exception e){e.printStackTrace();}
        }  
    
        private  void doit(IContainer readContainer, IPacket packet, IContainer writeContainer) throws InterruptedException {
                int i = 0;
                if(packet==null)
                {
                    //System.out.println("Packet nulll");   
                    doit(readContainer, packet, writeContainer);
                }
                while (readContainer.readNextPacket(packet) >= 0) {
                    if(readContainer.readNextPacket(packet)==-1 ){
                        System.out.println("Packet is absent"); 
                    }
                    if (packet.getStreamIndex() != 0) {
                        continue;
                    }
                    if(writeContainer.writePacket(packet)==0){
                           continue;                    
                    }else{
                    if (writeContainer.writePacket(packet) < 0) {
                        try{
                            System.out.println("packet sleep");
                            //TimeUnit.SECONDS.sleep(5);
                            doit(readContainer, packet, writeContainer);
                        }catch(Exception e){e.printStackTrace();}
                    }             
                    }
                  if (writeContainer.writeTrailer() < 0) {
                      throw new RuntimeException("unable to write trailer");
                  }        
                }     
            } 
        }
    
  • ffmpeg deocde without producing output file

    2 décembre 2013, par Xin He

    I want to use ffmpeg to decode a h264 file.

    Since I just want to measure the decoding time, the output file creation will spend a lot of time and time measurement will be not so accurate.

    So could anyone help to solve this problem?

    I use "ffmpeg -i blue_sky.h264 output.yuv "to decode.

    Thanks in advance!

  • Python threading module on windows after session logout

    1er décembre 2013, par e271p314

    I wrote a code which starts to record screen capture from the second it identifies mouse movement until it identifies the mouse didn't move for a predefined time (10 seconds). In python, on windows, how to wait until mouse moves? If, I'm logged in to the session the code works fine, i.e. it starts and stops on time and records the screen capture. But, if I logout, I expect the script to identify that the mouse doesn't move and stop recording. Instead, the code doesn't stop and when I login again (long after the 10 seconds passed), the screen capture (from the previous session) keeps running, yelling the rt buffer is full and it keeps running until I close the cmd console even I expect it to work for 10 seconds (at least when I'm logged in). Any idea what is the issue? I feel like it is something between the threading module and the session logout but I could be completely wrong about this.

  • How to lower the volume in a specific time interval with ffmpeg.exe [on hold]

    1er décembre 2013, par user1604523

    I am trying to lower the volume in a specific time interval with ffmpeg.exe . Let's say I have a 5 minutes long video and I want to lower the volume between 00:01:30 and 00:02:00. I read that we can use different parameters at the same time but I couldn't figure it out.

    Any help would be greatly appreciated.

  • Loss of audio when using concat demuxer

    1er décembre 2013, par HarryChil

    I'm trying to simply add a .mp4 introduction to a .mp4 video using concat demuxer:

    input.txt:

    file 'C:\Vid\UT.mp4'
    
    file 'C:\Vid\1.mp4'
    

    script.bat

    ffmpeg -f concat -i input.txt -codec copy output.mp4
    

    When I run the .bat, I loose the audio of '1.mp4'. Also, is there a way to process a batch of videos this way? i.e. add 'UT.mp4' to '1.mp4' and '2.mp4' and '3.mp4' (and so on) in one batch...

    Many thanks, Harry