Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • LIVE555 how to use h264 framer class to get nal units for ffmpeg

    18 octobre 2016, par Aleksey

    I'm trying to create a small app which will save frames from inoming h264 stream. I took a testRTSP programm as example and made several changes in DummySink::afterGettingFrame function to decode frames with the help of ffmpeg library. As I understand from frameSize, my first two frames are SPS units, so I concatenate them with my third frame and then send new big frame to ffmpeg decoder. But that doesnt work. ffmpeg tells me that my first frame is too big for SPS and then it tells me that there is no frame... I dont know what I need to change here.

    void DummySink::afterGettingFrame(unsigned frameSize, unsigned numTruncatedBytes,
    struct timeval presentationTime, unsigned /*durationInMicroseconds*/)
    {
    u_int8_t start_code[4] = { 0x00, 0x00, 0x00, 0x01 };
    int stCodeLen = 4;
    
    if (frameSize == 50)
    {
        //add start code
        memcpy(bufferWithStartCode, start_code, stCodeLen);
        shiftPtr += stCodeLen;
        memcpy(bufferWithStartCode + shiftPtr, fReceiveBuffer, frameSize);
        shiftPtr += frameSize;
    }
    else if (frameSize == 4)
    {
        memcpy(bufferWithStartCode + shiftPtr, fReceiveBuffer, frameSize);
        shiftPtr += frameSize;
    }
    else
    {
        if (shiftPtr == 0)
        {
            memcpy(bufferWithStartCode, start_code, stCodeLen);
            shiftPtr += stCodeLen;
        }
        memcpy(bufferWithStartCode + shiftPtr, fReceiveBuffer, frameSize);
        avpkt.size = frameSize + shiftPtr;
        avpkt.data = bufferWithStartCode;
        shiftPtr = 0;
        if (!avcodec_send_packet(cContext, &avpkt))
        {
            envir() << "error sending to decoder";
    
        }
        if (!avcodec_receive_frame(cContext, picture))
        {
            envir() << "error rx from decoder";
        }
        if (picture)
        {
            FILE *f;
            char buffer[32]; // The filename buffer.
            snprintf(buffer, sizeof(char) * 32, "file%i.txt", frame_num);
            f = fopen(buffer, "w");
            fprintf(f, "P5\n%d %d\n%d\n", fSubsession.videoWidth(), fSubsession.videoHeight(), 255);
            for (int i = 0;i < fSubsession.videoHeight();i++)
                fwrite(picture->data[0] + i * (picture->linesize[0]), 1, fSubsession.videoWidth(), f);
            fclose(f);
        }
    }
    
    envir() << frameSize << "\n";
    
    
    frame_num++;
    
    // Then continue, to request the next frame of data:
    continuePlaying();
    
  • ffmpeg stucks while converting live stream to hls

    18 octobre 2016, par Arya Same

    Hi i am converting a live stream into hls stream by ffmpeg on windows.

    i have such .bat file

    SETLOCAL
    set bitrate=900k
    :loop
    
    ffmpeg -i "http://x.com/stream.ts" -i logo.png -filter_complex "overlay=main_w-overlay_w-65:50,fps=30" -strict -2 -vcodec libx264 -preset veryfast -maxrate %bitrate% -minrate %bitrate% -minrate %bitrate% -r 30 -g 60 -c:a aac -b:a 128k -ar 44100 -f segment -hide_banner -loglevel panic -hls_flags delete_segments -segment_list "C:\nginx\html\hls\lig1.m3u8" -segment_time 5 -segment_list_size 5 -segment_list_entry_prefix "../ts/" "C:\nginx\html\ts\lig1-%%3d.ts" > trash/trash.txt
    
    goto loop
    

    but after a while ffmpeg just stucks , process doesnt end or doesnt continue to streaming just stucks i have no idea what i am doing wrong,if process fails or crashes .bat script will just restart it , but it just stucks not sure why.

  • Compiling ffmpeg to support libx264 encoder

    18 octobre 2016, par Nooruddin Lakhani

    I am using ffmpeg library for video compression. I am using the sample code from ffmpeg4android_lib and the following command to compress the video.

    String[] complexCommand = new String[]{ "ffmpeg", "-y", "-i",
                "/sdcard/videokit/in.mp4", "-strict", "experimental",
                "-vcodec", "mpeg4", "-b:v", "500k",
                "-acodec", "aac", "-ar", "48000", "-ac", "1",
                "-b:a", "96k", "-s", "480x360", "/sdcard/videokit/out.mp4" };
    

    in.mp4 video file is recorded from camera which is originally 46 mb. It convert video file size to 1.7 mb with better quality. When I select another video from Whatsapp Gallery which is already compressed by Whatsapp like I have a Whatsapp video which is 6 min duration and 9.8 mb in size, when I select this video to compress with the same command, It's size becomes 26 mb which is larger than original. When I decrease the video bit rate from 500k to 150k then output file size becomes smaller but quality becomes poor which cannot be acceptable.

    I have found people are using libx264 encoder to find better quality with minimum file size. I have changed my compress command to use this encoder.

    String[] complexCommand = new String[]{ "ffmpeg", "-y", "-i",
            "/sdcard/videokit/in.mp4", "-strict", "experimental",
                "-vcodec", "libx264", "-preset", "medium", "-b:v", "500k",
                "-crf", "26", "-acodec", "aac", "-ar", "48000", "-ac", "1",
                "-b:a", "96k", "-s", "480x360", "/sdcard/videokit/out.mp4" };
    

    But the above command is not working with ffmpeg library. I am getting the following issue which write log in vk.log file

    Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'libx264'.
    Reading option '-preset' ...Unrecognized option 'preset'.
    Error splitting the argument list: Option not found
    ffmpeg4android: ffmpeg_parse_options not passed
    exit_program: 1
    

    I am trying to use the encoder libx264, but ffmpeg not compiled to support this encoder. How can I configure libx264 with ffmpeg ? I have found the following references to configure ffmpeg With libx264

    1- ffmpeg on Heroku: unrecognized option 'preset'

    2- http://blog.oneiroi.co.uk/linux/ffmpeg-install-with-libx264-h264/

    3- http://writingminds.github.io/ffmpeg-android/

    Should I have to download NDK and will have to configure It through libx264 commands as defined in above references. I am not getting how to configure it through commands because I have to configure it in Android Studio with ffmpeg and I am using windows not ubuntu or Linux. Please suggest me how can i achieve this ?

  • Multiplex a HEVC-Video into a MPEG-Transportstream with FFMPEG

    18 octobre 2016, par checkThisOut

    I would like to multiplex a HEVC coded video into a MPEG-Transportstream.

    I have a Video coded with the x265 Encoder.

    x265 raw.y4m --output coded.hevc
    

    I want to multiplex this Video into an MPEG Transportstream. I tried it among other things this way:

    ffmpeg -fflags +genpts -i coded.hevc -c:v copy -f mpegts transportstream.ts 
    

    Unfortunately this error message shows up and the transportstream.ts is empty.

    [mpegts @ 0x1fa76a0] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
    [mpegts @ 0x1fa76a0] first pts value must be set
    av_interleaved_write_frame(): Invalid data found when processing input
    

    For my purpose, it is necessary to do the two steps separate. Could you help me please to find out the correct parameters to multiplex the Video?

    Thanks in advance.

  • Permission denied with JAVE on OSX

    18 octobre 2016, par clankill3r

    I try to convert video to audio using jave on OSX.

    http://www.sauronsoftware.it/projects/jave/manual.php

    As the documentation states

    ...You can even build it by yourself getting the code (and the documentation to build it) on the official ffmpeg site. Once you have obtained a ffmpeg executable suitable for your needs, you have to hook it in the JAVE library. That's a plain operation.

    I builded ffmpeg, but running the code I get a Permission denied error. I even changed all file permissions to 777 recursive. Hope someone can help, the documentation and error messages are very unclear.

    public class Mp4ToSoundTest {
    
    
        public static void main(String[] args) {
            Mp4ToSoundTest a = new Mp4ToSoundTest();
            a.setup();
        }
    
        void setup() {
    
            File source = new File("/Users/doekewartena/Downloads/vids_future_proj/VID_20160523_180100.mp4");
    
            System.out.println(source.exists());
    
            FFMPEGLocator my_ffmpeg_locator = new FFMPEGLocator() {
                @Override
                protected String getFFMPEGExecutablePath() {
                    return "/Users/doekewartena/Downloads/ffmpeg-3.1.4";
                }
            };
    
    
            File target = new File("/Users/doekewartena/Downloads/vids_future_proj/VID_20160523_180100.mp3");
            AudioAttributes audio = new AudioAttributes();
            audio.setCodec("libmp3lame");
            audio.setBitRate(128000);
            audio.setChannels(2);
            audio.setSamplingRate(44100);
            EncodingAttributes attrs = new EncodingAttributes();
            attrs.setFormat("mp3");
            attrs.setAudioAttributes(audio);
            Encoder encoder = new Encoder(my_ffmpeg_locator);
    
            // The source file can't be decoded. It occurs when the source file container, the video stream format or the
            // audio stream format are not supported by the decoder. You can check for supported containers and plugged
            // decoders calling the encoder methods getSupportedDecodingFormats(), getAudioDecoders() and getVideoDecoders().
            try {
                String[] r = encoder.getSupportedDecodingFormats();
                System.out.println("a");
                for (String s : r) {
                    System.out.println(s);
                }
                System.out.println("b");
    
                System.out.println();
                System.out.println(encoder.getAudioDecoders());
    
            } catch (EncoderException e) {
                e.printStackTrace();
            }
    
    
    
            try {
                encoder.encode(source, target, attrs);
            } catch (EncoderException e) {
                e.printStackTrace();
            }
            System.out.println("done");
    
        }
    
    }