Search code examples
ffmpegyoutubehttp-live-streaming

ffmpeg youtube livestream stops after a while


I'll update this question

ffmpeg -version

ffmpeg -version
ffmpeg version 4.3.1-4ubuntu1 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 10 (Ubuntu 10.2.0-9ubuntu2)

I run this command to use ffmpeg to stream to youtube ;

ffmpeg -y -threads 12 \
-loop 1 -framerate 30 -re \
-i ./1280x720.jpg \
-i ./audio.mp3 \
-video_size 1280x720 \
-vcodec libx264 -pix_fmt yuv420p \
-b:v 4500k -maxrate 5500k -bufsize 22000k \
-preset ultrafast -crf 23 -tune stillimage \
-b:a 128k -ar 44100 -ac 2 -acodec aac \
-filter_complex "dynaudnorm=f=150:g=15" \
-r 30 -g 60 \
-f flv rtmp://a.rtmp.youtube.com/live2/xxxx 2>&1 | tee _LOG

The stream is excellent for 45-53 minutes then i'll get an error like this from ffmpeg:

[flv @ 0x56077027cd80] Delay between the first packet and last packet in the muxing queue is 10034000 > 10000000: forcing output

then youtube starts to say, no data being received and the stream will end, which it does.

This is the full log: http://0x0.st/-zUH.txt


Solution

  • Your MP3 duration is 00:49:57.42 so the stream messes up after it ends. Loop the audio with -stream_loop -1 and add -re for real-time reading of the input:

    ffmpeg -y \
    -loop 1 -framerate 30 -re -i ./1280x720.jpg \
    -re -stream_loop -1 -i ./audio.mp3 \
    -c:v libx264 -pix_fmt yuv420p \
    -b:v 4500k -maxrate 5500k -bufsize 22000k \
    -preset ultrafast -tune stillimage \
    -b:a 128k -ar 44100 -ac 2 -c:a aac \
    -filter_complex "dynaudnorm=f=150:g=15" \
    -g 60 -f flv rtmp://a.rtmp.youtube.com/live2/xxxx
    

    Alternatively, remove -re -stream_loop -1 and add the output option -shortest if you want the stream to end when the audio ends.

    Unrelated changes:

    • No need to set -threads. Let ffmpeg auto choose.
    • -video_size 1280x720 is an input option for certain demuxers and does nothing in your command. Removed. Your input is already 1280x720 anyway: otherwise, see Resizing videos with ffmpeg to fit a specific size.
    • -b:v and -crf are mutually exclusive. In your case -b:v is being ignored. For streaming you probably want to use -b:v. Removed -crf.
    • You already set the frame rate with -framerate 30 so -r 30 is not needed. Removed.
    • Recommend using the slowest -preset that still encodes fast enough.