Newest 'ffmpeg' Questions - Stack Overflow

Articles published on the website

  • how to create a radio or video "station" continuous TS stream with ffmpeg

    25 February, by Zibri

    I can't find any answer to this scenarios:

    Produce a continuous ts file that initially contains silence (or blank video), and as I add files to a text file I wish them to be queued in the output ts stream. Think of it as a radio or tv station. I found everything on how to stream anything to anything, but not a tv/radio broadcast like stream.

    A good start seems to be this:

    ffmpeg -re -y -nostats -nostdin -hide_banner -loglevel quiet -fflags +genpts -f concat -i list.txt -map 0:a? -map 0:v? -map 0:s? -strict -2 -dn -c copy -hls_flags delete_segments -hls_time 10 -hls_list_size 6 /var/www/html/showname_.m3u8

    list.txt example

    file '/mnt/vusolo-tv/show/Season 1/S01E01.mp4'
    file '/mnt/vusolo-tv/show/Season 1/S01E02.mp4'

    But i think there can be better ways...

    This is not a good answer either: From multiple video files to single output
    because "All files must have streams with identical encoding. Timebase for streams should be the same. Duration of all streams within a file should be the same, in order to maintain sync." And I want to be able to add arbitrary files and produce a TS stream playable by any TV (once broadcasted in dvb).

  • ffmpeg 4 or higher c++ code equivalence of this command?

    25 February, by Aintsoa

    I want the equivalence of this command on c++ code:

    ffmpeg -i input -i logo -filter_complex 'overlay=10:main_h-overlay_h-10' output

    I know that to make it we must use ffmpegcpp::Filter class like:

    Filter* filter = new Filter("scale=640:150,transpose=cclock,vignette", encoder)

    It's for rotate but for the overlay? thanks!!

  • FFMPEG: Youtube streaming quality and speed issues

    25 February, by Alex Paramonov

    I am trying to make a reliable stream from my Icecast/Shoutcast servers to Youtube live. The command that I use is:

    ffmpeg -v verbose -framerate 30 -loop 1 -i /var/image.jpg -re -i -c:v libx264 -preset ultrafast -b:v 2250k -maxrate 6000k -bufsize 6000k -c:a copy -ab 128k -s 1920x1080 -framerate 30 -g 60 -keyint_min 60 -f flv  rtmp://

    As you can see I am using recommended bitrate for Youtube, insert keyframes every 2 seconds and streaming at 30 frames per second. The stream is working but after running for some time two thing are happening:

    1. FFMPEG speed falls from 1x to something like 0.998x
    2. Youtube starts complaining that video stream speed is slow, markes the quality as bad and sometimes video starts buffering.

    Why is this happening? CPU load is normal, connectivity is ok (the stream is running on a 1Gg/s dedicated server).

    Since in my example above I am streaming a single image as a logo of the stream I also tried to generate a short 30 seconds video with that image and broadcast that video instead of an image, but that did not help as well.

    The command I used for conversion:

    ffmpeg -framerate 30 -loop 1 -i /var/image.jpg -c:v libx264 -preset ultrafast -tune stillimage  -b:v 2250k -minrate 2250k -maxrate 6000k -bufsize 6000k -framerate 30 -g 60 -keyint_min 60 -t 30 out4.mp4

    And broadcast with

    ffmpeg -stream_loop -1 -i out4.mp4  -re -i -c:v copy -c:a copy  -framerate 30 -g 60 -keyint_min 60 -f flv  rtmp://

    ffmpeg version is 4.1.1

  • How to combine two ffmpeg bin script into one script

    25 February, by Muhammad Naeem


    cmd="ffmpeg -re -i -vcodec copy -acodec copy -f mpegts udp://" until $cmd > /dev/null 2>&1 < /dev/null; do echo "restarting ffmpeg command..." sleep 2

    cmd="ffmpeg -re -i -vcodec copy -acodec copy -f mpegts udp://" until $cmd > /dev/null 2>&1 < /dev/null; do echo "restarting ffmpeg command..." sleep 2 done

  • how to create Codec specific Data ( csd ) for h264 in MediaCodec?

    24 February, by Ahmed

    Hi i have android project that i have to receive audio and video from server via socket, the audio part run perfect. but the video part is not working i do not know what the reason because the decoder did not show any error when decoding video packets . the video codec that i use is H.264/AVC from ffmepeg encoder with the following settings :-

    tune = zerolatency

    profile = baseline

    level = 3

    Width = 320

    Height = 240

    frameRate = 30

    GOPSize = 30

    i found that i have to add CSD-0 and CSD-1 to MediaCodec config but i do not know how to add H.264 SPS/PPS data to the configurations

    this is code i was found , but it's not wokring with me ,

    byte[] header_sps = { 0, 0, 0, 1, 103, 100, 0, 40, -84, 52, -59, 1, -32, 17, 31, 120, 11, 80, 16, 16, 31, 0, 0, 3, 3, -23, 0, 0, -22, 96, -108 };
    byte[] header_pps = { 0, 0, 0, 1, 104, -18, 60, -128 };
    MediaFormat videoFormat = MediaFormat.createVideoFormat(MediaFormat.MIMETYPE_VIDEO_AVC , 320 , 240 );
    videoFormat.setInteger(MediaFormat.KEY_MAX_INPUT_SIZE  , 100000);
    videoFormat.setByteBuffer("csd-0", ByteBuffer.wrap(header_sps));
    videoFormat.setByteBuffer("csd-1", ByteBuffer.wrap(header_pps));
    MediaCodec videoDecoder = MediaCodec.createDecoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
    videoDecoder.configure(videoFormat , surface , null , 0);

    if some one know what the correct way to decode H.264 in this case this will be helpfull