FFMPEG - Long pause in av_read_frame - c++

I am trying to write a service that converts a m3u8 link from youtube.
I am loading the stream info then setting all but 1 video and 1 audio stream to AVDISCARD_ALL.
Everything works fine except after several seconds of playing av_read_frame blocks for 30 seconds to a couple minutes.
I'm not the best versed in ffmpeg so I'm not exactly sure what to do from here.
Extracting one of these links into ffplay works fine it seems, but I don't see what they may be doing differently? I'm just hoping someone can point me in the right direction of anything to try.
Attached is a callstack from when this is happening. I am not sure if anything here looks amiss.

Related

GStreamer Tutorial 1 - hear sound but no video

I'm continuing my journey through GStreamer and am stuck once again. I'm running the first tutorial and can hear sound but no video.
The error that I'm seeing is:
gldisplay gstgldisplay_cocoa.m:175:gst_gl_display_cocoa_setup_nsapp: Custom NSApp initialization failed
Am I missing a plugin or some required library here? I'm on an M1 Mac.
I should note, that via the command line everything works just fine.
gst-launch-1.0 playbin uri="file:///Users/vukasin/Downloads/sintel_trailer-480p.webm"
Maybe this is OpenGL related? I'm guessing its trying, and failing to open the video.
I just figured out what was going on with this error after spending hours thinking my system was not setup correctly. This issue is that a GMainLoop must be ran for the windowing to work correctly from the main thread. Interesting enough the tutorial 12 does it correctly and does the same exact thing. https://gstreamer.freedesktop.org/documentation/tutorials/basic/streaming.html?gi-language=c

Is there a way to download a video at the playback rate (a rate that would simulate user watching it)?

So I know that one can adjust the rate of download with youtube-dl using the -r or --limit-rate flags; however, as part of a simulation testing, I am trying to simulate a user watching a video , and so I want to download a video at a rate such that the download would take as long as the video's duration is if one were to watch the video, so that a 2min long video would take 2min to download, and so on and so forth.
I have meticulously reviewed the available options on their github page, but it seems like there are no options natively to do that. But then the next best thing I can think of is to get the video duration in seconds (lets call it t) and the video size in bytes (lets call it s) and then use s/t as a value for the --limit-rate flag.
However now the problem is that there doesn't seem to be any options/flags to get the video file-size in bytes!
Is there anyway I can accomplish what my goal is here? I am open to using other tools/programs if this is outside the capabilities of youtube-dl.
To be more specific, I am working in linux server environment (no video-card and needs to be able headlessly), and the videos I'm dealing with are MPEG Dash videos from an MPD file, so whatever tool I use needs to be able to parse and work with MPD files.
Thank you for your help,

media foundation H264 decoder not working properly

I'm creating an application for video conferencing using media foundation and I'm having an issue decoding the H264 video frames I receive over the network.
The Design
Currently my network source queues a token on every request sample, unless there is an available stored sample. If a sample arrives over the network and no token is available the sample is stored in a linked list. Otherwise it is queued with the MEMediaSample event. I also have the decoder set to low latency.
My Issue
When running the topology using my network source I immediately see the first frame rendered to the screen. I then experience a long pause until a live stream begins to play perfectly. After a few seconds the stream appears to pause but then you notice that it's just looping through the same frame over and over again adding in a live frame every couple of seconds that then disappears immediately and goes back to displaying the old loop.
Why is this happening? I'm by no means an expert in H264 or media foundation for that matter but, I've been trying to fix this issue for weeks with no success. I have no idea where the problem might be. Please help me!
The time stamp is created by starting at 0 and adding the duration to it for every new sample. The other data is retrieved from a IMFSampleGrabberSinkCallback.
I've also posted some of my MFTrace onto the msdn media foundation forums Link
I mentioned on there that the presentation clock doesn't seem to change on the trace but, I'm unsure if that's the cause or how to fix it.
EDIT:
Could you share the video and a full mftrace log for this issue? It's not clear for me what really happens: do you see the live video after a while?
The current log does not contain enough information to trace sample processing. From your description is looks like that only keyframes are rendered. Plus, duration is weird for the rendered keyframe:
Sample #00A74970, Time 6733ms, Duration 499ms. <- Duration is not 33ms.
I would like to see what happened to that sample.
In any case, if you are using standard encoder and decoder, the issue should be with your media source, and how it buffers frames. Incorrect circular buffer implementation? You may want to try and cache a second or two of samples before starting giving them to the decoder.

FFmpeg 1.0 < causing audio playback issues

I have an audio streamer based on ffplay. It works great using ffmpeg 0.11 but when I use ffmpeg 1.0 or the latest 1.2 release the audio seems to be decoded or played weirdly.
Essentially it sounds like chipmunks with mp3 streams and with aac streams I hear tons of static barely hearing the actual stream and the actual stream sounds slow.
Any ideas the possible changes in ffmpeg that could have caused these types of issues?
Similar issue was posted here but no actual answer about what is going on. Supposedly this code reproduces the same issue.
UPDATE 1:
I have done a step by step copy from ffplay and still no luck! :/ The channel and sampling rate look correct so there must be something internally that is returning a weird decoded format?
pCodecCtx->request_sample_fmt = AV_SAMPLE_FMT_S16
doesn't change the behavior! I didn't find any better solution than using swr_convert to convert audio sample from AV_SAMPLE_FMT_FLT to AV_SAMPLE_FMT_S16.
Found a fix... So initially it sounded like something wasn't matching correctly with the decoded raw PCM data and my PCM player. I took a deeper look at what was being returned by the decoder and any potential differences. Turns out that the default decoded format has changed from AV_SAMPLE_FMT_S16 to AV_SAMPLE_FMT_S16P. The fix was to simply specify pCodecCtx->request_sample_fmt = AV_SAMPLE_FMT_S16; before opening the decoder.
Any feedback if this is a bad idea? I'm concerned if there might be issues with other formats and potential performance issues...

Python audio library for simultaneous audio creation and playback

I'm working on an audio creation framework. It'll be generating large audio files, say 3 minute long audio files that take about 1 minute to generate. So what I want is a system much like streaming audio from the internet, where I play the sound as I generate it.
Pygame's mixer allows me to edit the sound as it's playing. But I cannot figure out how to change the sample rate, sample size, or number of channels.
Snack allows me to edit sounds, as well as their sample rate, sample size, length, and number of channels. But I cannot figure out how to edit sounds as they are playing.
Could anybody point me to a library that allows me to edit a sound as it is playing, as well as configure the number of channels, sample rate, and length (all known ahead of time)? If not, perhaps somebody knows of a tutorial to do this in C++?
[EDIT] Pymedia.audio would work fine for me. However, I can't get it to work under Python 2.6. Any ideas?
pymedia.audio does work with Python 2.6. Take a look at this SO post: Pymedia installation on Windows with Python 2.6
You can append audio to Output objects, as they are playing. So as each sample is generated, it can also be appended to the stream. The example in their documentation shows just how to do this: http://pymedia.org/docs/pymedia.audio.sound.html