immstudios / conti

minimalistic playout server
GNU General Public License v3.0
40 stars 7 forks source link

UnicodeDecodeError - video/audio sync issue #3

Open michaeltoohig opened 5 years ago

michaeltoohig commented 5 years ago

When playing certain files I get an error which causes either a BrokenPipeError or the following:

DEBUG       Executing ffmpeg -hide_banner -i data/Jesus Christ Bruce...-oLMkUKAiVDY.mp4 -filter:a [in]apad[out] -s 12
80x720 -pix_fmt yuv420p -r 25 -ar 48000 -t 13.978411 -c:v rawvideo -c:a pcm_s16le -max_interleave_delta 400000 -f avi
 -
DEBUG       Appending <Conti source: Jesus Christ Bruce...-oLMkUKAiVDY> to playlist
ERROR       Exception!

    Traceback (most recent call last):
      File "/mnt/c/Projects/telsat/channel/conti/conti/__init__.py", line 115, in progress_thread
        ch = decode_if_py3(source.proc.stderr.read(1))
      File "/mnt/c/Projects/telsat/channel/conti/.venv/lib/python3.6/site-packages/nxtools/common.py", line 36, in <l
ambda>
        decode_if_py3 = lambda x, enc="utf-8": x.decode(enc)
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte

ERROR       Exception!

    Traceback (most recent call last):
      File "/mnt/c/Projects/telsat/channel/conti/conti/__init__.py", line 115, in progress_thread
        ch = decode_if_py3(source.proc.stderr.read(1))
      File "/mnt/c/Projects/telsat/channel/conti/.venv/lib/python3.6/site-packages/nxtools/common.py", line 36, in <l
ambda>
        decode_if_py3 = lambda x, enc="utf-8": x.decode(enc)
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0x99 in position 0: invalid start byte

INFO        Starting clip <Conti source: Jesus Christ Bruce...-oLMkUKAiVDY>

Play continues but these files can cause video/audio sync problems which can be very small or adds up over an hour or two to be noticeable.

All files were downloaded with youtube-dl and I was just playing them in a loop to see if this type of error would occur; only a few of the files seem to cause the error.

michaeltoohig commented 5 years ago

Actually I'm finding even with 4 videos in a loop that produce no visible errors as above there still is a video/audio sync issue after a couple of hours. Each video is just about 10 to 30 seconds playing from a local folder.

I'm on a computer that has more than enough RAM and CPU to handle the job. Is this a problem you ever experienced?

UPDATE

I've since taken the four videos and passed them all through ffmpeg as seen below to set them all to the same frame rate, audio sample rate, etc. I used your themis2 project with a few modifications.

DEBUG       Executing ffmpeg -hide_banner -y -i /mnt/Transcoding/Channel/Input/jazz.mp4 -filter_complex [0:0]scale=1920:1080[outv0] -map [outv0] -map 0:1 -r 25 -pix_fmt yuv420p -b:v 2M -g 80 -preset:v fast -profile:v main -c:v libx264 -x265-params keyint=80:min-keyint=80:scenecut=-1 -video_track_timescale 25 -c:a libfdk_aac -ar 48000 -b:a 192k /mnt/Transcoding/Channel/Output/.creating.jazz.mov

Now all the files that originally would cause immediate problems no long do; but, the audio and video de-sync after only 30 minutes or so.

Is this me and my files or something about conti that I don't yet grasp and I am using incorrectly? Is there any other info that would help?

martastain commented 5 years ago

The unicode decode error seems to be caused by non-asci character in the filename. Are you using python2 or python3 btw?

Async issue is expected and so far i haven't found a way how to fix it. AAC codec (and most likely other compressed audio formats) encodes an audio track using packets of 1024 samples, so in most cases video and audio duration slightly differs. Conti uses apad and trim filters to avoid this problem, but so far it works only if audio tracks are PCM.

jb-alvarado commented 5 years ago

You could use mpeg-ts instead of uncompressed/avi for your pre-processing. With this you not even need apad to have a/v sync. I use this in my project ffplayout and it works very well. Here some thought from my research.

martastain commented 5 years ago

We usually use dnxhd mov or mxf files, but - depending on your file ingest platform - sometimes track durations don't match if the original source is for example mp4 with aac audio.

michaeltoohig commented 5 years ago

@martastain I am using python3. I mostly have mp4 files already and have tried using dnxhd but the size of the files is just too much for our current project. I am not very familiar with all the ins-and-outs of ffmpeg and video formats but I'll look into PCM for the audio.

But referring to your second post, are you saying if my original source is mp4/aac then it may not convert to a better format with the correct duration?

@jb-alvarado Thanks for the project link. I'm going to give it a try as well today.