ffmpeg on a Raspberry Pi - Help Required!

Digital ATV - The latest generation, cutting edge ATV - Please discuss it all here.
Forum rules
This forum is run by the BATC (British Amateur Television Club), it is service made freely available to all interested parties, please do not abuse this privilege.

Thank you
Post Reply
G8GKQ
Site Admin
Posts: 2798
Joined: Sun Mar 22, 2009 1:21 pm

ffmpeg on a Raspberry Pi - Help Required!

Post by G8GKQ » Sat Nov 25, 2017 9:11 pm

Hi

The Short Version

I'm using ffmpeg on a RPi3 to generate an H264 transport stream using either libx264 or h264_omx and mpegts. I can get it to work properly with libx264, but the CPU is maxed out. With h264_omx it appears to work, but the resulting TS has an undefined frame rate. VLC will play the TS, but it is unsuitable for transmission using the DVB-S standard. I know that h264_omx is at least functioning, because it works with flv output.

I realise that this a very specialist question and I am not expecting answers - just pointers to where I might find any more information on how to force mpegts to define the frame rate. Google has not been helpful!

Dave

The Long Version

This code to produce a web stream using ffmpeg, libx264 and flv works well but maxes out the CPU:

Code: Select all

/home/pi/rpidatv/bin/ffmpeg \
  -f v4l2 -input_format h264 \
  -i /dev/video0 -thread_queue_size 2048 \
  -f alsa -ac 1 -ar 44100 \
  -i hw:1,0 \
  -framerate 15 -video_size 720x576 -c:v libx264 -b:v 512k -minrate:v 512k -maxrate:v 512k \
  -b:a 22050 -ac 1 \
  -g 25 \
  -f flv rtmp://sitename.org.uk/live/keykey &
Using omx_h264 in this application also works well with much lower CPU usage:

Code: Select all

/home/pi/rpidatv/bin/ffmpeg \
  -f v4l2 -input_format h264 \
  -i /dev/video0 -thread_queue_size 2048 \
  -f alsa -ac 1 -ar 44100 \
  -i hw:1,0 \
  -framerate 15 -video_size 720x576 -c:v h264_omx -b:v 512k -minrate:v 512k -maxrate:v 512k \
  -b:a 22050 -ac 1 \
  -g 25 \
  -f flv rtmp://sitename.org.uk/live/keykey &
So moving on to using mpegts output format. This code works, but maxes out the CPU cores:

Code: Select all

/home/pi/rpidatv/bin/ffmpeg -loglevel debug \
  -f image2 -loop 1 -pix_fmt yuv420p\
  -framerate 25 -pix_fmt yuv420p \
  -i /home/pi/rpidatv/video/tcf.jpg \
  -c:v libx264 -pix_fmt yuv420p \
  -b:v 320600 -minrate:v 320600 -maxrate:v 320600 \
  -f mpegts -blocksize 1880 \
  -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 \
  -mpegts_pmt_start_pid 4095 -streamid 0:256 -streamid 1:257 \
  -metadata service_provider=G8GKQ -metadata service_name=G8GKQ \
  -muxrate 1382352 -y videots &
videots is a fifo that is read by another application that converts the transport stream into I and Q signals for a DVB-S TV transmission.

If I substitute h264_omx for libx264, it runs with lower CPU usage, but produces a non-compliant transport stream with a (video) frame rate undefined:

Code: Select all

/home/pi/rpidatv/bin/ffmpeg -loglevel debug \
  -f image2 -loop 1 -pix_fmt yuv420p\
  -framerate 25 -pix_fmt yuv420p \
  -i /home/pi/rpidatv/video/tcf.jpg \
  -c:v h264_omx -pix_fmt yuv420p \
  -b:v 320600 -minrate:v 320600 -maxrate:v 320600 \
  -f mpegts -blocksize 1880 \
  -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 \
  -mpegts_pmt_start_pid 4095 -streamid 0:256 -streamid 1:257 \
  -metadata service_provider=G8GKQ -metadata service_name=G8GKQ \
  -muxrate 1382352 -y videots &
I have taken the audio codec out of the examples above for clarity. When the audio codec was present, I could decode the audio from the stream.

I also tested with writing the output to a .ts file and using Promax TS Analyser software to look at the stream properties. It said that the (video) frame rate in the h264_omx stream was 0.0 fps. VLC played both files OK, but when checking codec properties, there was no entry for the frame rate in the h264_omx-produced file. In the libx264 file the frame rate was correctly described as 25.0 fps. I think that this is the reason it does not work in my application - so I am looking for a way to make mpegts define the (video) frame rate.

Here is my ffmpeg configuration:

Code: Select all

ffmpeg version 3.3.2 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 4.9.2 (Raspbian 4.9.2-10)
  configuration: --prefix=/home/pi/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/pi/ffmpeg_build/include --extra-ldflags=-L/home/pi/ffmpeg_build/lib --enable-gpl --enable-libfreetype --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-nonfree --enable-mmal --enable-omx --enable-omx-rpi
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
I have played with trying to define a frame rate in just about everywhere in the ffmpeg statement. I'm about to give up on this, but just wondered if anyone had seen anything like it before.

The software is intended to be an enhancement to the Portsdown Transmitter: https://wiki.batc.tv/The_Portsdown_Transmitter The existing code is on GitHub here: https://github.com/BritishAmateurTelevisionClub/rpidatv

Thanks in advance

Dave

g0mjw
Posts: 2329
Joined: Sat Sep 20, 2014 9:15 am

Re: ffmpeg on a Raspberry Pi - Help Required!

Post by g0mjw » Sat Nov 25, 2017 10:17 pm


G8GKQ
Site Admin
Posts: 2798
Joined: Sun Mar 22, 2009 1:21 pm

Re: ffmpeg on a Raspberry Pi - Help Required!

Post by G8GKQ » Sat Nov 25, 2017 11:07 pm

Thanks Mike

I had read that link and think that the problem might be related. However, I have no idea how to access the particular frame rate parameter from the ffmpeg command. The writer is accessing the hardware encoder directly from his application.

I'll keep looking

Dave

g0mjw
Posts: 2329
Joined: Sat Sep 20, 2014 9:15 am

Re: ffmpeg on a Raspberry Pi - Help Required!

Post by g0mjw » Sun Nov 26, 2017 9:25 am

According to this https://ffmpeg.org/ffmpeg.html the parameter for frame rate is -r so -r 25 would give you 25 fps for example. I don't think this is your solution as it would be far too easy and I suspect you have tried this already.


/home/pi/rpidatv/bin/ffmpeg -loglevel debug \
-f image2 -loop 1 -pix_fmt yuv420p\
-r 25 -pix_fmt yuv420p \
-i /home/pi/rpidatv/video/tcf.jpg \
-c:v h264_omx -pix_fmt yuv420p \
-b:v 320600 -minrate:v 320600 -maxrate:v 320600 \
-f mpegts -blocksize 1880 \
-mpegts_original_network_id 1 -mpegts_transport_stream_id 1 \
-mpegts_pmt_start_pid 4095 -streamid 0:256 -streamid 1:257 \
-metadata service_provider=G8GKQ -metadata service_name=G8GKQ \
-muxrate 1382352 -y videots &



Mike

PS - I wonder if the debug option is taking up too much resource?

G8GKQ
Site Admin
Posts: 2798
Joined: Sun Mar 22, 2009 1:21 pm

Re: ffmpeg on a Raspberry Pi - Help Required!

Post by G8GKQ » Mon Nov 27, 2017 10:18 pm

Thanks Mike

Yes, I tried liberally scattering "-r 25"s all over the place, and they made no difference. I suspect that the h264_omx encoder is non-compliant with the full spec and does not define its output frame rate. I'll try reducing the debug, but I'm not cpu resource limited, and the gpu does not seem to produce any debug messages.

For a day or 2 I'm going to concentrate on releasing a new Portsdown software and then I'll get back to this.

Dave

Post Reply

Return to “DATV - Digital ATV”