Twinklebear / fbed

Python FFmpeg Batch Encoding Dashboard
MIT License
125 stars 14 forks source link

Bitrate errore with tvheadend recordings #1

Closed BarnOwlDown closed 3 years ago

BarnOwlDown commented 3 years ago

This is what command tells me:

[matt@rpi3bp MattHDD]$ ./fbed.py 1 TV/A-Team-Iris.mkv
Collecting input video list...
Traceback (most recent call last):
  File "./fbed.py", line 284, in <module>
    manager = EncodingManager(all_files, parallel_encodes, frame, todo_list, active_list, completed_list)
  File "./fbed.py", line 158, in __init__
    bitrate = float(video_stream["bitrate"]) / 1000
KeyError: 'bitrate'

Here's media information:

[matt@rpi3bp MattHDD]$ mediainfo TV/A-Team-Iris.mkv
General
Unique ID                                : 261086048781300974404954431405333131508 (0xC46B580C83DE3464D19C09880FEBB0F4)
Complete name                            : TV/A-Team-Iris.mkv
Format                                   : Matroska
Format version                           : Version 2
File size                                : 918 MiB
Duration                                 : 46 min 0 s
Overall bit rate mode                    : Variable
Overall bit rate                         : 2 791 kb/s
Movie name                               : A-Team
Writing application                      : Tvheadend 4.3-1916~g1884300f0-dirty
Writing library                          : Tvheadend Matroska muxer
Original source form                     : TV
DATE_BROADCASTED                         : 2020-12-07 06:20:00
SUMMARY                                  : Il nipote di un boss della malavita e' un appassionato di corse d'auto, che vuole vincere con ogni mezzo. Alla prossima corsa partecipa il nipote di Hannibal. /  / VISIONE ADATTA A TUTTI.
TVCHANNEL                                : Iris

Video
ID                                       : 1
Format                                   : MPEG Video
Format version                           : Version 2
Format profile                           : Main@Main
Format settings                          : CustomMatrix / BVOP
Format settings, BVOP                    : Yes
Format settings, Matrix                  : Custom
Format settings, GOP                     : Variable
Format settings, picture structure       : Frame
Codec ID                                 : V_MPEG2
Codec ID/Info                            : MPEG 1 or 2 Video
Duration                                 : 46 min 0 s
Bit rate mode                            : Variable
Bit rate                                 : 2 479 kb/s
Maximum bit rate                         : 15.0 Mb/s
Width                                    : 720 pixels
Height                                   : 576 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant
Frame rate                               : 25.000 FPS
Standard                                 : PAL
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Interlaced
Scan order                               : Top Field First
Compression mode                         : Lossy
Bits/(Pixel*Frame)                       : 0.239
Stream size                              : 816 MiB (89%)
Language                                 : English
Default                                  : Yes
Forced                                   : No

Audio #1
ID                                       : 2
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Codec ID                                 : A_MPEG/L2
Codec ID/Hint                            : MP2
Duration                                 : 46 min 0 s
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Compression mode                         : Lossy
Delay relative to video                  : -515 ms
Stream size                              : 42.1 MiB (5%)
Language                                 : Italian
Default                                  : Yes
Forced                                   : No

Audio #2
ID                                       : 3
Format                                   : MPEG Audio
Format version                           : Version 1
Format profile                           : Layer 2
Codec ID                                 : A_MPEG/L2
Codec ID/Hint                            : MP2
Duration                                 : 46 min 0 s
Bit rate mode                            : Constant
Bit rate                                 : 128 kb/s
Channel(s)                               : 2 channels
Sampling rate                            : 48.0 kHz
Compression mode                         : Lossy
Delay relative to video                  : -414 ms
Stream size                              : 42.1 MiB (5%)
Language                                 : English
Default                                  : Yes
Forced                                   : No

Text
ID                                       : 4
Format                                   : UTF-8
Codec ID                                 : S_TEXT/UTF8
Codec ID/Info                            : UTF-8 Plain Text
Language                                 : Italian
Default                                  : Yes
Forced                                   : No
Twinklebear commented 3 years ago

That's odd, it seems like it's not reading the bitrate when doing the ffprobe. Could you add a print(probe) on line 156 and paste the output here?

BarnOwlDown commented 3 years ago
[matt@rpi3bp MattHDD]$ ./fbed.py 1 TV/A-Team-Iris.mkv
Collecting input video list...
{'streams': [{'index': 0, 'codec_name': 'mpeg2video', 'codec_long_name': 'MPEG-2 video', 'profile': 'Main', 'codec_type': 'video', 'codec_time_base': '1/25', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'width': 720, 'height': 576, 'coded_width': 0, 'coded_height': 0, 'closed_captions': 0, 'has_b_frames': 1, 'sample_aspect_ratio': '64:45', 'display_aspect_ratio': '16:9', 'pix_fmt': 'yuv420p', 'level': 8, 'color_range': 'tv', 'chroma_location': 'left', 'field_order': 'tt', 'refs': 1, 'r_frame_rate': '25/1', 'avg_frame_rate': '25/1', 'time_base': '1/1000', 'start_pts': 595, 'start_time': '0.595000', 'disposition': {'default': 1, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}, 'tags': {'language': 'eng'}, 'side_data_list': [{'side_data_type': 'CPB properties'}]}, {'index': 1, 'codec_name': 'mp2', 'codec_long_name': 'MP2 (MPEG audio layer 2)', 'codec_type': 'audio', 'codec_time_base': '1/48000', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'sample_fmt': 's16p', 'sample_rate': '48000', 'channels': 2, 'channel_layout': 'stereo', 'bits_per_sample': 0, 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/1000', 'start_pts': 0, 'start_time': '0.000000', 'bit_rate': '128000', 'disposition': {'default': 1, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}, 'tags': {'language': 'ita'}}, {'index': 2, 'codec_name': 'mp2', 'codec_long_name': 'MP2 (MPEG audio layer 2)', 'codec_type': 'audio', 'codec_time_base': '1/48000', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'sample_fmt': 's16p', 'sample_rate': '48000', 'channels': 2, 'channel_layout': 'stereo', 'bits_per_sample': 0, 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/1000', 'start_pts': 101, 'start_time': '0.101000', 'bit_rate': '128000', 'disposition': {'default': 1, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}, 'tags': {'language': 'eng'}}, {'index': 3, 'codec_name': 'subrip', 'codec_long_name': 'SubRip subtitle', 'codec_type': 'subtitle', 'codec_time_base': '0/1', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'r_frame_rate': '0/0', 'avg_frame_rate': '0/0', 'time_base': '1/1000', 'start_pts': 0, 'start_time': '0.000000', 'duration_ts': 2760195, 'duration': '2760.195000', 'disposition': {'default': 1, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}, 'tags': {'language': 'ita'}}], 'format': {'filename': 'TV/A-Team-Iris.mkv', 'nb_streams': 4, 'nb_programs': 0, 'format_name': 'matroska,webm', 'format_long_name': 'Matroska / WebM', 'start_time': '0.000000', 'duration': '2760.195000', 'size': '962951918', 'bit_rate': '2790967', 'probe_score': 100, 'tags': {'title': 'A-Team', 'encoder': 'Tvheadend Matroska muxer', 'DATE_BROADCASTED': '2020-12-07 06:20:00', 'ORIGINAL_MEDIA_TYPE': 'TV', 'TVCHANNEL': 'Iris', 'SUMMARY': "Il nipote di un boss della malavita e' un appassionato di corse d'auto, che vuole vincere con ogni mezzo. Alla prossima corsa partecipa il nipote di Hannibal.\n\nVISIONE ADATTA A TUTTI.", 'SUMMARY-ita': "Il nipote di un boss della malavita e' un appassionato di corse d'auto, che vuole vincere con ogni mezzo. Alla prossima corsa partecipa il nipote di Hannibal.\n\nVISIONE ADATTA A TUTTI."}}}
Traceback (most recent call last):
  File "./fbed.py", line 284, in <module>
    manager = EncodingManager(all_files, parallel_encodes, frame, todo_list, active_list, completed_list)
  File "./fbed.py", line 158, in __init__
    bitrate = float(video_stream["bitrate"]) / 1000
KeyError: 'bitrate'
Twinklebear commented 3 years ago

Interesting, the video stream doesn't have bit_rate field for this format for some reason. I've added some code in 667c7e0 to check for this case and use the bit_rate from the format field instead. I'm not sure if that includes the audio bitrate as well, but I think for this use case it's close enough. Let me know if that resolves the issue

BarnOwlDown commented 3 years ago

It works! Thank you very much!