[mythtv-users] Recording from input video on demand, no tuner; update: troubles capturing video using RPI4
Jay Harbeston
jharbestonus at gmail.com
Wed Mar 1 20:58:13 UTC 2023
> On Mar 1, 2023, at 1:12 PM, Peter Bennett <pb.mythtv at gmail.com> wrote:
>
>
> On 3/1/23 11:00, Jay Harbeston wrote:
>> I did check out your lean capture page, and I used the test on it to see how it fared as far as cpu usage, and the RPI4 stinks in comparison to what you are using. The events per second for the RPi 4 processor is 393, so that is a non starter for trying to use transcode with H264.
>>
>> I did try just copying to mpegts , but I couldn’t view video using it, either with vlc or mythtv.
>>
>> The best success I have had is creating an mkv, or an avi, but have not been able to get mythtv to accept it via a pipe.
>>
>> Looks like I am SOL then when using the RPI4 as the capture for the USB HDMI .
>>
>> UNLESS there is some other magic!?
>>
>> Some of the other experiments I tried were to treat it as a v4l2 capture device(there look like there are a couple of choices as tuners in Mythtv) since it is v4l2 video, but that was also a fail. I’m guessing the v4l2 driver is only looking for 640x480 video likes old school analog tv?
>>
> Did you try using ffmpeg using copy to prevent encoding and specifying ts output, something like this -
>
> ffmpeg -hide_banner -loglevel error -f v4l2 -thread_queue_size 256 -input_format mjpeg \
> -framerate 60 -video_size 1280x720 \
> -use_wallclock_as_timestamps 1 \
> -i /dev/video0 -f alsa -ac 2 -ar 48000 -thread_queue_size 1024 \
> -itsoffset 0.150 -i hw:2.0 \
> -c:v copy -vf format=yuv420p -c:a copy \
> -f mpegts outfile.ts
>
> This may not work if ts format does not support mjpeg or the audio format.
>
> The alsa audio requires you to find the correct audio device and to disable pulseaudio. I have a script to find the alsa device.
I am using fixes/32.0-40 from the mythtv lite packages from Peter if that makes a difference regarding how mythtv accepts the output.
I tried the above example, modified slightly to suit my command, and the following occurred:
The only big change to your command was to use pulse default instead of also as the input for audio. I also used 1920x1080 resolution and 30 fps frame rate.
ffmpeg -f pulse -thread_queue_size 1024 -i default -f v4l2 -thread_queue_size 1024 -input_format mjpeg -video_size 1920x1080 -framerate 30 -use_wallclock_as_timestamps 1 -i /dev/video0 -f mpegts -c:v yuv420p -c:a copy ~/outfile.ts
The output encoder is having troubles as shown in the error:
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
Guessed Channel Layout for Input Stream #0.0 : stereo
Input #0, pulse, from 'default':
Duration: N/A, start: 1677702787.763392, bitrate: 1536 kb/s
Stream #0:0: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
[mjpeg @ 0x1606550] EOI missing, emulating
Input #1, video4linux2,v4l2, from '/dev/video0':
Duration: N/A, start: 1677702788.117759, bitrate: N/A
Stream #1:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1920x1080, 30 fps, 30 tbr, 1000k tbn, 1000k tbc
Unknown encoder 'yuv420p'
Here is what I am using that gives me audio and video that can be played by vlc. The bit rate for mkv is around 10,000kbps less than the avi.
The bit rate for mkv is ~34,000 kbps while Avi below is ~45,000kbps.
###################################################################################
ffmpeg to create mkv stream that works correctly, including being able to watch using vlc while recording:
ffmpeg -f pulse -thread_queue_size 1024 -i default -f v4l2 -thread_queue_size 1024 -input_format mjpeg -video_size 1920x1080 -framerate 30 -i /dev/video0 -f matroska -codec copy pipe:1 > ~/file.mkv
ffprobe file.mkv
libavutil 56. 51.100 / 56. 51.100
libavcodec 58. 91.100 / 58. 91.100
libavformat 58. 45.100 / 58. 45.100
libavdevice 58. 10.100 / 58. 10.100
libavfilter 7. 85.100 / 7. 85.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 7.100 / 5. 7.100
libswresample 3. 7.100 / 3. 7.100
libpostproc 55. 7.100 / 55. 7.100
[mjpeg @ 0x16e0c60] EOI missing, emulating
[matroska,webm @ 0x16de540] Estimating duration from bitrate, this may be inaccurate
Input #0, matroska,webm, from 'file.mkv':
Metadata:
ENCODER : Lavf58.45.100
Duration: 01:25:19.33, start: 0.000000, bitrate: 1536 kb/s
Stream #0:0: Video: mjpeg (Baseline), yuvj422p(pc, bt470bg/unknown/unknown), 1920x1080, 30 fps, 30 tbr, 1k tbn, 1k tbc (default)
Stream #0:1: Audio: pcm_s16le, 48000 Hz, 2 channels, s16, 1536 kb/s (default)
#######################################################################################
ffmpeg to create avi stream that works correctly including being able to watch using vlc while recording:
ffmpeg -f v4l2 -thread_queue_size 1024 -input_format mjpeg -video_size 1920x1080 -framerate 30 -i /dev/video0 -f pulse -thread_queue_size 1024 -i default -codec copy vid_1080p_30.avi
I have had no dropouts using the above methods, and ffmpeg uses ~15% of cpu according to top while capturing with either of the above.
Regards!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mythtv.org/pipermail/mythtv-users/attachments/20230301/6a98f44e/attachment-0001.htm>
More information about the mythtv-users
mailing list