Project

General

Profile

TVHeadend not using codec copy ?

Added by STREIFF Antoine over 4 years ago

Hey there,

I'm a little bit confused in here. So I've set up a tvheadend on a raspberry pi 4, because I need for my work to record a lot of tv programs. I appreciate TVheadend very much on an other installation, and so are my coworkers who also needs to use it and not a CLI only interface (that's relevant you'll see).

So when I'm using a simple ffmpeg command like this :

ffmpeg -err_detect ignore_err -i http://mystream -to 00:10:00 -codec copy /media/partage/dvr/test.mp4

my cpu usage goes to something like 1 or 2% percent. But when I'm trying to replicate that in tvheadend, the cpu goes to 400%, and clearly it's not the same behavior.

Here my stream configuration :

Here's the result with ffmpeg codec copy :

General
Complete name                            : /Volumes/Share/dvr/test2.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/mp41)
File size                                : 58.3 MiB
Duration                                 : 3mn 20s
Overall bit rate                         : 2 436 Kbps
Writing application                      : Lavf58.20.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : 2 Ref Frames
Format settings, CABAC                   : No
Format settings, ReFrames                : 2 frames
Format settings, GOP                     : M=3, N=50
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 3mn 20s
Bit rate                                 : 2 300 Kbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.100
Stream size                              : 55.0 MiB (94%)
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 3mn 20s
Bit rate mode                            : Constant
Bit rate                                 : 128 Kbps
Channel(s)                               : 1 channel
Channel layout                           : C
Sampling rate                            : 44.1 KHz
Frame rate                               : 43.066 fps (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 3.07 MiB (5%)
Language                                 : French
Default                                  : Yes
Alternate group                          : 1

And the result with tvheadend :

General
Complete name                            : /Volumes/Share/dvr/2020-04-01/BFMTV/Edition-speciale-BFMTV2020-04-0121-00.mp4
Format                                   : MPEG-4
Format profile                           : Base Media
Codec ID                                 : isom (isom/iso2/avc1/iso6/mp41)
File size                                : 8.40 MiB
Duration                                 : 42s 486ms
Overall bit rate                         : 1 659 Kbps
Movie name                               : Edition spéciale
Writing application                      : Lavf58.20.100

Video
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : CABAC / 4 Ref Frames
Format settings, CABAC                   : Yes
Format settings, ReFrames                : 4 frames
Codec ID                                 : avc1
Codec ID/Info                            : Advanced Video Coding
Duration                                 : 40s 512ms
Bit rate                                 : 11.9 Kbps
Nominal bit rate                         : 1 500 Kbps
Width                                    : 1 280 pixels
Height                                   : 720 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Frame rate                               : 25.000 fps
Minimum frame rate                       : 13.885 fps
Maximum frame rate                       : 25.014 fps
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.001
Stream size                              : 58.6 KiB (1%)
Writing library                          : x264 core 155 r2917 0a84d98
Encoding settings                        : cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x3:0x113 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=6 / lookahead_threads=1 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=125 / keyint_min=12 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=abr / mbtree=1 / bitrate=1500 / ratetol=1.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / vbv_maxrate=1875 / vbv_bufsize=5625 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Codec configuration box                  : avcC

Audio
ID                                       : 2
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Codec ID                                 : mp4a-40-2
Duration                                 : 42s 486ms
Bit rate mode                            : Constant
Bit rate                                 : 172 bps
Nominal bit rate                         : 172 Kbps
Channel(s)                               : 1 channel
Channel layout                           : C
Sampling rate                            : 48.0 KHz
Frame rate                               : 46.875 fps (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 915 Bytes (0%)
Language                                 : French
Default                                  : Yes
Alternate group                          : 1

As you can see, Tvheadend is making a variable bitrate and variable framerate file, which is really bad for Premiere Pro (which is the main goal for all this).

My Pi4 is on Raspbian Buster, but I've also tried this with the same unfortunate result on libreelec.

Does anyone has any idea ?


Replies (11)

RE: TVHeadend not using codec copy ? - Added by saen acro over 4 years ago

You try to Trans-MUX or Trans-code?
Both are different.

RE: TVHeadend not using codec copy ? - Added by STREIFF Antoine over 4 years ago

Well it's pretty much transmuxing no ? I don't know I always thought transmuxing would imply a change of container and in that case it would be MP4 -> MP4, but I get your point.

So yeah, I absolutely want to avoid a transcode.

RE: TVHeadend not using codec copy ? - Added by saen acro over 4 years ago

Use MPEG-TS Spawn profile

RE: TVHeadend not using codec copy ? - Added by STREIFF Antoine over 4 years ago

Mmm I don't think I've got this one…

Should I try another build ?

RE: TVHeadend not using codec copy ? - Added by STREIFF Antoine over 4 years ago

Ok… so after a long day, I've managed to install 4.3 on a fresh Ubuntu on a rasp 4. But I've got a new problem. When I'm using this, it's working quite well :

 /usr/bin/ffmpeg -loglevel fatal -i pipe:0 -vcodec copy -acodec copy -metadata service_provider=STRING -metadata service_name=STRING -f mpegts -tune zerolatency pipe:1

But it's not the same as a ffmpeg -i pipe:0 -codec copy output.mp4 would work. the -f mpegts seems to add variable framerate, which is terrible for Premiere.
When I try
/usr/bin/ffmpeg -loglevel fatal -i pipe:0 -codec copy pipe:1

The file is created but stay at 0ko. The console show this :
-04-02 17:41:29.872 dvr: /media/partage/2020-04-02/_FR_-LA-CHAINE-METEO-FHD/L'__dition-du-soir.mp4 from adapter: "IPTV #2", network: "IPTV Automatic Network", mux: "blue.m3u - |FR| LA CHAINE METEO FHD", provider: "FFmpeg", service: "Service01" 
2020-04-02 17:41:29.872 dvr:  #  type              lang  resolution  aspect ratio  sample rate  channels
2020-04-02 17:41:29.872 dvr:  1  H264                    ?           ?                                    
2020-04-02 17:41:29.872 dvr:  2  MPEG2AUDIO        fre                             96000        ?         
2020-04-02 17:41:29.883 spawn: Executing "/usr/bin/ffmpeg" 

Any idea ?

RE: TVHeadend not using codec copy ? - Added by saen acro over 4 years ago

Let's return on what is idea at beginning.
You want to record files or to restram in mp4 containr?

RE: TVHeadend not using codec copy ? - Added by STREIFF Antoine over 4 years ago

Well I want to record the files without any transcoding at all, and the best way to do that would be to replicate the -codec copy option of ffmpeg (which is not the case with -f mpegts . Maybe if I find the right option for my file ? Usually -f is quite optional…

edit : something strange, when I add -f mp4 , the file stay at 0ko... strange right ? But it is working with ffmpeg

RE: TVHeadend not using codec copy ? - Added by saen acro over 4 years ago

So record with regular pass profile,
else use post processing.


No need to make live harder because you can.

RE: TVHeadend not using codec copy ? - Added by STREIFF Antoine over 4 years ago

I think I found the answer.

So TvHeadend is using pipe:// , which is streaming. So, according to the ffmpeg doc, you can't use mp4 but TS and FLV. So basically I've made a post-record process : ffmpeg -i "%f" -map 0 -c copy /media/partage/dvr/%b
And that's doing the job, with 1 or 2% CPU usage

RE: TVHeadend not using codec copy ? - Added by STREIFF Antoine over 4 years ago

So I'm almost done with that setup ! Right now I've got two m3u and one dvb-t . The HD flux of the m3us are fine, but the fhd, 265 and dvbt streams are giving me variable framerates. It's mandatory for premiere to have constant framerate.

So I thought that my trick with -map 0 would do the job, but no.

So I was wondering : is there any way to force constant framerate through pipe:// ?

RE: TVHeadend not using codec copy ? - Added by saen acro over 4 years ago

Only with transcoding.

    (1-11/11)