pl_mpeg icon indicating copy to clipboard operation
pl_mpeg copied to clipboard

Player doesn't play 22050 Hz audio

Open malespiaut opened this issue 1 year ago • 3 comments

Hello,

As the title implies, I've encoded a MPEG1 video using the FFMpeg command-line listed in the README, with the additional option -ar 22050.

The produced video file plays fine using ffplay but your player doesn't play the audio track.

I don't know if this is intentional or a bug.

Best regards.

malespiaut avatar Mar 16 '24 23:03 malespiaut

Without testing it, I suspect that audio decoding works just fine, but playing doesn't. pl_mpeg_player does not include a resampler; it attempts to create an SDL Audio Context with the given samplerate (here), which probably fails for 22050hz.

You need to resample the audio from pl_mpeg to a samplerate supported by SDL and the underlying audio driver.

phoboslab avatar Mar 22 '24 06:03 phoboslab

I don't know if my issue is related to this one, but in my case I have some old mpeg1 videos where the audio is also not working with the player. When debugged, it seems to be because self->num_audio_streams = plm_buffer_read(self->buffer, 6) returns 0. If just after that line of code I hard code self->num_audio_streams = 1 then the audio plays fine. It also works when played with other players like windows media player, ffmpeg, etc,.. Here is the video/streams info from ffmpeg for one of those videos:

Input #0, mpeg, from 'Merlin's Prologue.mpg':
  Duration: 00:00:29.91, start: 0.710456, bitrate: 1176 kb/s
  Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv, progressive), 640x480 [SAR 200:219 DAR 800:657], 104857 kb/s, 29.97 fps, 59.94 tbr, 90k tbn
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 311296 vbv_delay: N/A
  Stream #0:1[0x1c0]: Audio: mp2, 44100 Hz, stereo, s16p, 224 kb/s

If I just ffmpeg -i "Merlin's Prologue.mpg" -c:v mpeg1video -q:v 0 -c:a mp2 -format mpeg fixed_audio_video.mpg then the audio works on the new video and here is the ffmpeg info:

Input #0, mpeg, from 'fixed_audio_video.mpg':
  Duration: 00:00:29.91, start: 0.522456, bitrate: 2060 kb/s
  Stream #0:0[0x1e0]: Video: mpeg1video, yuv420p(tv, progressive), 640x480 [SAR 200:219 DAR 800:657], 104857 kb/s, 29.97 fps, 59.94 tbr, 90k tbn
      Side data:
        cpb: bitrate max/min/avg: 0/0/0 buffer size: 49152 vbv_delay: N/A
  Stream #0:1[0x1c0]: Audio: mp2, 44100 Hz, stereo, s16p, 384 kb/s

So I supposed something is just wrong with the header of those old videos

I provided two of those videos in the zip in attachement if that can help finding an issue somewhere else

audio_videos.zip

Kolfering avatar Sep 15 '24 15:09 Kolfering

Yeah, some MPG files (particularly from VCDs) don't correctly state the number of streams in the header. Use plm_probe() to search for them. More info in issue https://github.com/phoboslab/pl_mpeg/issues/25 and in the description of plm_probe().

phoboslab avatar Sep 16 '24 09:09 phoboslab