feek404
Posts: 3
Joined: Mon Aug 27, 2018 8:36 am

Raspivid + ffmpeg streaming stops after a random interval

Mon Aug 27, 2018 8:44 am

I'm trying to follow this tutorial on making an infrared bird box:

https://projects.raspberrypi.org/en/pro ... d-bird-box

However my stream to Youtube always stop after seemingly random intervals of 1-20 hours. Has anyone has success with long term streaming using raspivid and ffmpeg? The only way I think of is to make the Pi restart every hour of so - not very elegant of a solution...

This is the command I'm using:

raspivid -o - -t 0 -w 1280 -h 720 -fps 25 -b 4000000 -g 50 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/****-****-****-****

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 25045
Joined: Sat Jul 30, 2011 7:41 pm

Re: Raspivid + ffmpeg streaming stops after a random interval

Mon Aug 27, 2018 9:35 am

We really need to figure out why it's stopping whether it's something to is ffmpeg, the camera or actually the ethernet connection itself.

Have you tried SSH into the pi once it stops, or dmesg?
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I own the world’s worst thesaurus. Not only is it awful, it’s awful."

feek404
Posts: 3
Joined: Mon Aug 27, 2018 8:36 am

Re: Raspivid + ffmpeg streaming stops after a random interval

Thu Sep 06, 2018 8:54 am

SSH and Ethernet work seemingly fine, I can reach the Raspberry Pi after the stream stops. I wonder what makes the interval so random.

I'm going to try dmesg and I'll post the result...

feek404
Posts: 3
Joined: Mon Aug 27, 2018 8:36 am

Re: Raspivid + ffmpeg streaming stops after a random interval

Fri Sep 28, 2018 5:39 pm

Sorry for the delay, here is the output from dmesg:

Code: Select all

[    0.000000] Booting Linux on physical CPU 0x0
[    0.000000] Linux version 4.14.52+ ([email protected]) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1123 Wed Jun 27 17:05:32 BST 2018
[    0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d
[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT nonaliasing instruction cache
[    0.000000] OF: fdt: Machine model: Raspberry Pi Model B Plus Rev 1.2
[    0.000000] Memory policy: Data cache writeback
[    0.000000] cma: Reserved 8 MiB at 0x17400000
[    0.000000] On node 0 totalpages: 98304
[    0.000000] free_area_init_node: node 0, pgdat c09c04f8, node_mem_map d7c8a500
[    0.000000]   Normal zone: 864 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 98304 pages, LIFO batch:31
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 97440
[    0.000000] Kernel command line: bcm2708_fb.fbwidth=640 bcm2708_fb.fbheight=480 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000  dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait splash plymouth.ignore-serial-consoles
[    0.000000] PID hash table entries: 2048 (order: 1, 8192 bytes)
[    0.000000] Dentry cache hash table entries: 65536 (order: 6, 262144 bytes)
[    0.000000] Inode-cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Memory: 370300K/393216K available (6422K kernel code, 587K rwdata, 1988K rodata, 440K init, 677K bss, 14724K reserved, 8192K cma-reserved)
[    0.000000] Virtual kernel memory layout:
                   vector  : 0xffff0000 - 0xffff1000   (   4 kB)
                   fixmap  : 0xffc00000 - 0xfff00000   (3072 kB)
                   vmalloc : 0xd8800000 - 0xff800000   ( 624 MB)
                   lowmem  : 0xc0000000 - 0xd8000000   ( 384 MB)
                   modules : 0xbf000000 - 0xc0000000   (  16 MB)
                     .text : 0xc0008000 - 0xc064ddac   (6424 kB)
                     .init : 0xc08ca000 - 0xc0938000   ( 440 kB)
                     .data : 0xc0938000 - 0xc09cae90   ( 588 kB)
                      .bss : 0xc09d07d0 - 0xc0a79d1c   ( 678 kB)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] ftrace: allocating 24096 entries in 71 pages
[    0.000000] NR_IRQS: 16, nr_irqs: 16, preallocated irqs: 16
[    0.000031] sched_clock: 32 bits at 1000kHz, resolution 1000ns, wraps every 2147483647500ns
[    0.000073] clocksource: timer: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 1911260446275 ns
[    0.000165] bcm2835: system timer (irq = 27)
[    0.000723] Console: colour dummy device 80x30
[    0.001308] console [tty1] enabled
[    0.001359] Calibrating delay loop... 697.95 BogoMIPS (lpj=3489792)
[    0.060338] pid_max: default: 32768 minimum: 301
[    0.060854] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.060907] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.062223] Disabling memory control group subsystem
[    0.062443] CPU: Testing write buffer coherency: ok
[    0.063568] Setting up static identity map for 0x8200 - 0x8238
[    0.064848] devtmpfs: initialized
[    0.073721] random: get_random_u32 called from bucket_table_alloc+0x88/0x1c4 with crng_init=0
[    0.074684] VFP support v0.3: implementor 41 architecture 1 part 20 variant b rev 5
[    0.075127] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.075198] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.076540] pinctrl core: initialized pinctrl subsystem
[    0.077930] NET: Registered protocol family 16
[    0.080975] DMA: preallocated 1024 KiB pool for atomic coherent allocations
[    0.087422] hw-breakpoint: found 6 breakpoint and 1 watchpoint registers.
[    0.087493] hw-breakpoint: maximum watchpoint size is 4 bytes.
[    0.087640] Serial: AMBA PL011 UART driver
[    0.090553] bcm2835-mbox 2000b880.mailbox: mailbox enabled
[    0.130435] bcm2835-dma 20007000.dma: DMA legacy API manager at d880d000, dmachans=0x1
[    0.132874] SCSI subsystem initialized
[    0.133143] usbcore: registered new interface driver usbfs
[    0.133293] usbcore: registered new interface driver hub
[    0.133527] usbcore: registered new device driver usb
[    0.140807] raspberrypi-firmware soc:firmware: Attached to firmware from 2018-07-03 14:21
[    0.142886] clocksource: Switched to clocksource timer
[    0.231330] VFS: Disk quotas dquot_6.6.0
[    0.231509] VFS: Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)
[    0.231830] FS-Cache: Loaded
[    0.232211] CacheFiles: Loaded
[    0.249326] NET: Registered protocol family 2
[    0.250562] TCP established hash table entries: 4096 (order: 2, 16384 bytes)
[    0.250698] TCP bind hash table entries: 4096 (order: 2, 16384 bytes)
[    0.250815] TCP: Hash tables configured (established 4096 bind 4096)
[    0.250994] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.251053] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.251437] NET: Registered protocol family 1
[    0.252173] RPC: Registered named UNIX socket transport module.
[    0.252230] RPC: Registered udp transport module.
[    0.252256] RPC: Registered tcp transport module.
[    0.252280] RPC: Registered tcp NFSv4.1 backchannel transport module.
[    0.254332] hw perfevents: no irqs for PMU, sampling events not supported
[    0.254459] hw perfevents: enabled with armv6_1176 PMU driver, 3 counters available
[    0.258111] workingset: timestamp_bits=14 max_order=17 bucket_order=3
[    0.270165] FS-Cache: Netfs 'nfs' registered for caching
[    0.271540] NFS: Registering the id_resolver key type
[    0.271633] Key type id_resolver registered
[    0.271664] Key type id_legacy registered
[    0.271712] nfs4filelayout_init: NFSv4 File Layout Driver Registering...
[    0.276474] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
[    0.276955] io scheduler noop registered
[    0.277005] io scheduler deadline registered (default)
[    0.277544] io scheduler cfq registered
[    0.277592] io scheduler mq-deadline registered
[    0.277620] io scheduler kyber registered
[    0.279900] BCM2708FB: allocated DMA memory 57500000
[    0.280013] BCM2708FB: allocated DMA channel 0 @ d880d000
[    0.288807] Console: switching to colour frame buffer device 80x30
[    0.300328] bcm2835-rng 20104000.rng: hwrng registered
[    0.303746] vc-mem: phys_addr:0x00000000 mem_base=0x1ec00000 mem_size:0x20000000(512 MiB)
[    0.310796] vc-sm: Videocore shared memory driver
[    0.314770] gpiomem-bcm2835 20200000.gpiomem: Initialised: Registers at 0x20200000
[    0.339777] brd: module loaded
[    0.355121] loop: module loaded
[    0.358284] Loading iSCSI transport class v2.0-870.
[    0.362156] usbcore: registered new interface driver smsc95xx
[    0.365406] dwc_otg: version 3.00a 10-AUG-2012 (platform bus)
[    0.596875] Core Release: 2.80a
[    0.599968] Setting default values for core params
[    0.603123] Finished setting default values for core params
[    0.806537] Using Buffer DMA mode
[    0.809585] Periodic Transfer Interrupt Enhancement - disabled
[    0.812576] Multiprocessor Interrupt Enhancement - disabled
[    0.815640] OTG VER PARAM: 0, OTG VER FLAG: 0
[    0.818707] Dedicated Tx FIFOs mode
[    0.822601] WARN::dwc_otg_hcd_init:1046: FIQ DMA bounce buffers: virt = 0xd7514000 dma = 0x57514000 len=9024
[    0.829141] FIQ FSM acceleration enabled for :
               Non-periodic Split Transactions
               Periodic Split Transactions
               High-Speed Isochronous Endpoints
               Interrupt/Control Split Transaction hack enabled
[    0.844985] dwc_otg: Microframe scheduler enabled
[    0.845240] WARN::hcd_init_fiq:459: FIQ on core 0 at 0xc049a438
[    0.848394] WARN::hcd_init_fiq:460: FIQ ASM at 0xc049a714 length 36
[    0.851475] WARN::hcd_init_fiq:486: MPHI regs_base at 0xd88a5000
[    0.854620] dwc_otg 20980000.usb: DWC OTG Controller
[    0.857646] dwc_otg 20980000.usb: new USB bus registered, assigned bus number 1
[    0.863684] dwc_otg 20980000.usb: irq 56, io mem 0x00000000
[    0.866873] Init: Port Power? op_state=1
[    0.869914] Init: Power Port (0)
[    0.873351] usb usb1: New USB device found, idVendor=1d6b, idProduct=0002
[    0.876503] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[    0.882548] usb usb1: Product: DWC OTG Controller
[    0.885682] usb usb1: Manufacturer: Linux 4.14.52+ dwc_otg_hcd
[    0.888806] usb usb1: SerialNumber: 20980000.usb
[    0.893042] hub 1-0:1.0: USB hub found
[    0.896229] hub 1-0:1.0: 1 port detected
[    0.900206] dwc_otg: FIQ enabled
[    0.900218] dwc_otg: NAK holdoff enabled
[    0.900225] dwc_otg: FIQ split-transaction FSM enabled
[    0.900280] Module dwc_common_port init
[    0.900754] usbcore: registered new interface driver usb-storage
[    0.904504] mousedev: PS/2 mouse device common for all mice
[    0.907558] IR NEC protocol handler initialized
[    0.910480] IR RC5(x/sz) protocol handler initialized
[    0.913495] IR RC6 protocol handler initialized
[    0.916469] IR JVC protocol handler initialized
[    0.919345] IR Sony protocol handler initialized
[    0.922217] IR SANYO protocol handler initialized
[    0.925106] IR Sharp protocol handler initialized
[    0.927916] IR MCE Keyboard/mouse protocol handler initialized
[    0.930756] IR XMP protocol handler initialized
[    0.934841] bcm2835-wdt 20100000.watchdog: Broadcom BCM2835 watchdog timer
[    0.938402] bcm2835-cpufreq: min=700000 max=700000
[    0.941888] sdhci: Secure Digital Host Controller Interface driver
[    0.944870] sdhci: Copyright(c) Pierre Ossman
[    0.948354] sdhost-bcm2835 20202000.mmc: could not get clk, deferring probe
[    0.951588] sdhci-pltfm: SDHCI platform and OF driver helper
[    0.955388] ledtrig-cpu: registered to indicate activity on CPUs
[    0.958606] hidraw: raw HID events driver (C) Jiri Kosina
[    0.961792] usbcore: registered new interface driver usbhid
[    0.964819] usbhid: USB HID core driver
[    0.968625] vchiq: vchiq_init_state: slot_zero = d7580000, is_master = 0
[    0.973616] [vc_sm_connected_init]: start
[    0.984000] [vc_sm_connected_init]: end - returning 0
[    0.988180] Initializing XFRM netlink socket
[    0.991283] NET: Registered protocol family 17
[    0.994464] Key type dns_resolver registered
[    0.999151] registered taskstats version 1
[    1.010069] uart-pl011 20201000.serial: cts_event_workaround enabled
[    1.013468] 20201000.serial: ttyAMA0 at MMIO 0x20201000 (irq = 81, base_baud = 0) is a PL011 rev2
[    1.923717] console [ttyAMA0] enabled
[    1.934209] sdhost: log_buf @ d7513000 (57513000)
[    2.022963] mmc0: sdhost-bcm2835 loaded - DMA enabled (>1)
[    2.033178] of_cfs_init
[    2.039015] of_cfs_init: OK
[    2.066139] Waiting for root device /dev/mmcblk0p7...
[    2.075323] Indeed it is in host mode hprt0 = 00021501
[    2.145103] random: fast init done
[    2.201270] mmc0: host does not support reading read-only switch, assuming write-enable
[    2.218341] mmc0: new high speed SDHC card at address 0007
[    2.228291] mmcblk0: mmc0:0007 SD8GB 7.42 GiB
[    2.243712]  mmcblk0: p1 p2 < p5 p6 p7 >
[    2.276683] EXT4-fs (mmcblk0p7): INFO: recovery required on readonly filesystem
[    2.290415] EXT4-fs (mmcblk0p7): write access will be enabled during recovery
[    2.300953] usb 1-1: new high-speed USB device number 2 using dwc_otg
[    2.313497] Indeed it is in host mode hprt0 = 00001101
[    2.553558] usb 1-1: New USB device found, idVendor=0424, idProduct=9514
[    2.564099] usb 1-1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    2.576350] hub 1-1:1.0: USB hub found
[    2.586021] hub 1-1:1.0: 5 ports detected
[    2.913162] usb 1-1.1: new high-speed USB device number 3 using dwc_otg
[    3.053499] usb 1-1.1: New USB device found, idVendor=0424, idProduct=ec00
[    3.064108] usb 1-1.1: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[    3.081680] smsc95xx v1.0.6
[    3.181915] smsc95xx 1-1.1:1.0 eth0: register 'smsc95xx' at usb-20980000.usb-1.1, smsc95xx USB 2.0 Ethernet, b8:27:eb:28:33:32
[    4.243116] Under-voltage detected! (0x00050005)
[    4.372591] EXT4-fs (mmcblk0p7): recovery complete
[    4.390183] EXT4-fs (mmcblk0p7): mounted filesystem with ordered data mode. Opts: (null)
[    4.405449] VFS: Mounted root (ext4 filesystem) readonly on device 179:7.
[    4.417374] devtmpfs: mounted
[    4.426418] Freeing unused kernel memory: 440K
[    4.434515] This architecture does not have kernel memory protection.
[    5.125662] systemd[1]: System time before build time, advancing clock.
[    5.339247] NET: Registered protocol family 10
[    5.349826] Segment Routing with IPv6
[    5.384972] ip_tables: (C) 2000-2006 Netfilter Core Team
[    5.413200] random: systemd: uninitialized urandom read (16 bytes read)
[    5.433175] systemd[1]: systemd 232 running in system mode. (+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
[    5.463243] systemd[1]: Detected architecture arm.
[    5.497280] systemd[1]: Set hostname to <raspberrypi>.
[    5.603133] random: systemd: uninitialized urandom read (16 bytes read)
[    5.853606] random: systemd-sysv-ge: uninitialized urandom read (16 bytes read)
[    5.881915] uart-pl011 20201000.serial: no DMA platform data
[    6.767265] systemd[1]: Listening on Syslog Socket.
[    6.782157] systemd[1]: Listening on udev Control Socket.
[    6.798033] systemd[1]: Set up automount Arbitrary Executable File Formats File System Automount Point.
[    6.820305] systemd[1]: Listening on udev Kernel Socket.
[    6.834896] systemd[1]: Listening on fsck to fsckd communication Socket.
[    6.890829] systemd[1]: Listening on Journal Socket.
[    6.905647] systemd[1]: Started Forward Password Requests to Wall Directory Watch.
[    7.221364] i2c /dev entries driver
[   28.263551] EXT4-fs (mmcblk0p7): re-mounted. Opts: (null)
[   28.646932] systemd-journald[87]: Received request to flush runtime journal from PID 1
[   31.298263] snd_bcm2835: module is from the staging directory, the quality is unknown, you have been warned.
[   31.366544] bcm2835_alsa bcm2835_alsa: card created with 8 channels
[   36.526110] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
[   37.923176] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0x51E1
[   38.839083] random: crng init done
[   38.839111] random: 7 urandom warning(s) missed due to ratelimiting
[   39.912819] Adding 102396k swap on /var/swap.  Priority:-2 extents:1 across:102396k SSFS
[   58.749285] fuse init (API version 7.26)
[   93.955875] EXT4-fs (mmcblk0p5): mounted filesystem with ordered data mode. Opts: (null)
[   97.263250] Bluetooth: Core ver 2.22
[   97.263460] NET: Registered protocol family 31
[   97.263471] Bluetooth: HCI device and connection manager initialized
[   97.263506] Bluetooth: HCI socket layer initialized
[   97.263526] Bluetooth: L2CAP socket layer initialized
[   97.263590] Bluetooth: SCO socket layer initialized

Tomtom428
Posts: 1
Joined: Sun Jan 19, 2020 7:50 pm

Re: Raspivid + ffmpeg streaming stops after a random interval

Sun Jan 19, 2020 8:24 pm

I've had the same problem with Youtube live streaming using ffmpeg on Raspberry Pi Zero W.

After a period of time, queue overflows and speed-level did fall below 1 (e.g. speed=0.98) - simultaneously an interruption in the data stream towards Youtube appears.

Error message:
queue overflow / thread_queue_size exceeded

In general:
"dropping frames on buffer queue overflow" is a known issue of some versions of ffmpeg - also every real-time stream can fail due to different reasons (network outage, buffer overrun etc.)

Solution:
- error handling with ffmpeg's "fifo"
- recover streaming indefinitely by adding fifo-commands to your ffmpeg-code
Source: https://ffmpeg.org/ffmpeg-formats.html#fifo-1

Benefits:
- streaming output can be transparently restarted with configurable delay between retries based on real time or time of the processed stream.
- encoding can be blocked during temporary failure, or continue transparently dropping packets in case fifo queue fills up.


• Example #1 (taken from ffmpeg.org):
Stream something to rtmp server, continue processing the stream at real-time rate even in case of temporary failure (network outage) and attempt to recover streaming every second indefinitely.

Code: Select all

ffmpeg -re -i ... -c:v libx264 -c:a aac -f fifo -fifo_format flv -map 0:v -map 0:a -drop_pkts_on_overflow 1 -attempt_recovery 1 -recovery_wait_time 1 rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]

• Example #2 (referring to your code snippet):

Code: Select all

raspivid -o - -t 0 -w 1280 -h 720 -fps 25 -b 4000000 -g 50 | ffmpeg -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f fifo -fifo_format flv -map 2:v -map 1:a -drop_pkts_on_overflow 1 -attempt_recovery 1 -recovery_wait_time 1 -recover_any_error 1 rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]
Hint:
In my case stream-numbers were:
video-stream no. 2: -map 2:v
audio-stream no. 1: -map 1:a


Alternatively you can use another package, e.g. avconv instead of ffmpeg

Whole tutorial:
https://www.makeuseof.com/tag/live-stre ... spberry-pi

Installation:
- most recent versions of Raspbian have avconv preinstalled
- otherwise set it up with libav-tools

Code: Select all

sudo apt install libav-tools


• Example #3 streaming to Youtube with avconv (taken from makeuseof.com):

Code: Select all

raspivid -o - -t 0 -vf -hf -fps 30 -b 6000000 | avconv -re -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -i - -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]

• Example #4 adapted to my needs, works flawless for hours so far:

Code: Select all

raspivid -o - -t 0 -w 1280 -h 720 -fps 25 -b 3500000 -g 50 | avconv -r 25 -ar 44100 -ac 2 -acodec pcm_s16le -f s16le -ac 2 -i /dev/zero -f h264 -thread_queue_size 512 -i - -maxrate 3500k -bufsize 7000k -vcodec copy -acodec aac -ab 128k -g 50 -strict experimental -f flv rtmp://a.rtmp.youtube.com/live2/[your-secret-key-here]
Hint:
Your individual code (raspivid/avconv options) may vary from example above.


Maybe this helps ;-)

Return to “Camera board”