Newest 'ffmpeg' Questions - Stack Overflow

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

Les articles publiés sur le site

  • Read all data from pipe

    19 juin 2017, par Maxim Fedorov

    I wrote a wrapper for ffmpeg (с#), the information is transferred and returned through the pipe. How to effectively read all the information from the pipe ? Now I'm using the "Read" method of the NamedPipeServerStream class, reading occurs in a loop with small chunks. Reading ends when the number of bytes read is less than the chunk size. This method seems slow and unreliable

  • Transcoding HD RTP/UDP stream with FFMPEG

    19 juin 2017, par SudoSu

    I've a Tera STI440 streamer with two inputs used (for TV channel streaming). When I watch the source stream it seems allright, but when I start FFMPEG transcoding, the image is going to collapse on random times (probably around every 5-15 sec). The transcoding is okay with SD 480P streams.

    FFPROBE one of my HD stream: `

    Input #0, rtp, from 'rtp://239.192.24.3:1234/':
      Duration: N/A, start: 18002.926656, bitrate: N/A
      Program 202 
        Metadata:
          service_name    : M5 HD
          service_provider: Magyar Televizio
        Stream #0:1: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, top first), 1440x1080 [SAR 4:3 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
        Stream #0:0(hun): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, stereo, s16p, 128 enter code herekb/s
    

    FFPROBE one of my SD stream (Which is working properly):

    Input #0, rtp, from 'rtp://239.192.24.4:1234/':
      Duration: N/A, start: 51003.435044, bitrate: N/A
      Program 203 
        Metadata:
          service_name    : RTL Klub
          service_provider: Magyar RTL Telev�zi� Zrt.
        Stream #0:0: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt470bg, top first), 720x576 [SAR 12:11 DAR 15:11], 25 fps, 25 tbr, 90k tbn, 50 tbc
        Stream #0:1(hun): Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp
    

    I want to do a HLS stream so I ran this script for FFMPEG:

    /usr/bin/ffmpeg -loglevel 16 -i rtp://239.192.24.3:1234/ -s pal -c:v libx264 -c:a libmp3lame -b:v 1000k -b:a 96k -ar 44100 -vf 'yadif=0:-1:1' -preset:v superfast -f hls -hls_time 7 -hls_list_size 10 -hls_wrap 10 -hls_base_url http://10.3.1.3:8080/ts/ -hls_segment_filename /tvman/hls_out/ts/M5_hq_%03d /tvman/hls_out/subplaylist/M5-hq.m3u8
    

    I access the playlist file from NGINX but also tried Apache too. Here's some log from FFMPEG process (loglevel 16)

    I made some diagnostics:

    • Looked for network traffic (it's around 60 mbps, so it should be okay with a 100mbps ethernet
    • CPU & RAM load allright
    • I reduced the network traffic by turning off TV channel streams on streamer. It was around 6-7 mbps.

    If you need any more information, I'll provide it for you. Thanks for the help!

    P.S.: I'm not native English speaker, so sorry for mistakes. :)

  • HLS parallel segment encoding

    19 juin 2017, par gigot

    Having the following ffmpeg config:

    ffmpeg -i input.mp4 -pix_fmt yuv420p -c:v libx264 -profile:v baseline -preset slow -b:v 850000 -maxrate 850000 -bufsize 850000 -vf scale=256:144 -g 48 -keyint_min 48 -sc_threshold 0 -threads 4 -movflags +faststart -c:a libfdk_aac -b:a 128k -r 24 -f ssegment -segment_time 10 -segment_list master.m3u8 -segment_list_size 0 -segment_format mpegts output_%02d.ts
    

    I want to parallelize the encoding of each .ts file, instead of doing inline encoding like the above. Tried to translate it to single .ts config, each segment will be 10 seconds and then just create the m3u8 playlist file automatically.

    ffmpeg -i input.mp4 -pix_fmt yuv420p -c:v libx264 -profile:v baseline -preset slow -b:v 850000 -maxrate 850000 -bufsize 850000 -vf scale=256:144 -g 48 -keyint_min 48 -sc_threshold 0 -threads 4 -c:a libfdk_aac -b:a 128k -r 24 -ss 00:00.000 -t 00:10.000 -segment_format mpegts output_00.ts
    

    For all other segments i just increase the timing by 10 e.g -ss option. Now the problem is that the metadata of all segments is not correct. More precisely the start_pts and start_time is same for all segments:

    ffprobe -v error -select_streams v:0  -print_format json -show_streams -i output_01.ts
    
    ...
                "start_pts": 130180,
                "start_time": "1.446444",
    ...
    

    So what i need is to define somewhere the start pts/time for each segment in my ffmpeg config, but cant find the correct option in docs

  • Encryption of OpenCV VideoWriter output

    19 juin 2017, par Aryan

    In an embedded project I was using opencv cv::VideoWriter to store frames as video files, also utilising lossless compression codecs (e.g.Lagarith). Now I have the requirement to encrypt the video files before storing them.

    1. Is it possible to get the encoded output from cv::VideoWriter so that an encryption step can be applied before writing the frame to disk?

    2. Alternatively, is it possible to make cv::VideoWriter output to a custom output stream? That way encryption steps can be applied on the stream.

    3. If neither of above is possible then is there an alternative to cv::VideoWriter that I can use to get the video format encoding done?

    The end requirement is to write encrypted files which, after only a decryption step, become video files compatible with standard video players.

  • Cutting the stream on local date time when scheduled

    19 juin 2017, par Fearhunter

    I am using a ffmpeg slice commando in my C# code. For example: I scheduled a stream from 12pm till 3 pm. In my if statement I use a condition to compare the local datetime with the time of now.

     DateTime systemDate = DateTime.Now;
     DateTime compareDate = DateTime.Today;
    
      private Process SliceStream(string url)
            {
                if (systemDate < compareDate)
                {
                    return Process.Start(new ProcessStartInfo
                    {
                        FileName = "ffmpeg.exe",
                        Arguments = $"-i \"{url}\"-acodec aac -strict -2 -vcodec libx264 -hls_wrap 100 -f hls -hls_time 20 C:/var/1.m3u8 ",
                        UseShellExecute = false,
                        RedirectStandardOutput = true
    
                    });
                }
                else
                {
                    Thread.Sleep(100);
                    return null;
                }
            }
    

    The problem is it doesn't work when my time on my computer is for example 12pm and he is not cutting the stream.

    What am I doing wrong?