by umvi · 6y ago · 0 comments
import json
json.loads('{"That": "was easy"}')
(To be fair, knowing ffmpeg exists doesn't mean I'd be able to easily write a video player with it without a lot of research. For that reason I find this tutorial is still quite interesting and valuable.)That seems to imply that, in 1kLoC of C, you should be able to write a complete video player for MPEG-1, and not much more beyond that. If you're even the slightest bit interested in video compression, I'd recommend giving it a try starting with '261 --- it's not as difficult as it sounds at first glance, and the results are very visible.
(When I have the time, I plan to continue this exercise with H.263, MPEG-4 ASP, and then H.264.)
The maths has actually gotten simpler; the predecessors are all traditional DCT-based (JPEG-like) codecs while H.264 uses a simple integer approximation. Regardless, from a decoder implementation perspective, the theory behind it all is not that important; the spec tells you exactly what you need to do, and the increase in complexity is mainly reflected in needing to write more code to handle the larger number of cases.
H.261 is simple because it has a choice of only two resolutions, one framerate, two frame types (I and P), and 10 macroblock types.
H.262/MPEG-2 is already a significant increase in complexity since it supports a varying set of resolutions, framerates, interlacing, and chroma subsampling, has 3 frame types (I, P, B), 20 macroblock types (dependent on frame type), and more complex motion compensation.
H.263 has no interlacing but adds optional intra prediction, more advanced motion vector encoding, and a few other features.
H.264 has about 50 macroblock types, even more complex intra prediction, and motion compensation has a larger choice of which frames to predict from.
Don't get me wrong, this is a cool SDL <> ffmpeg integration tutorial.
[1] https://developer.apple.com/documentation/avkit/avplayerview...
It's fine if you are in the Apple ecosystem but many formats from Windows or Linux will fail with it.
The tutorial is still 1000 lines of C, involving SDL, ffmpeg and threads.
Yikes :)
Last time I did something like this (a UI that among other things, played a live stream from a cheapo IP camera), I used python and the libvlc python bindings. Creating a bare bones media player with it was trivial and it worked very well for what I needed. The only complaint I had at the time was that the documentation was absolutely terrible. A cursory look today reveals that they seem to have improved it, so yay?
And yes, the end result in my case came out MUCH smaller than 1000 lines (but lines of code is a shitty metric anyway).
If you "just" need a media player, IMHO, libvlc is not an awful option (in Python, at least - I have no experience with other bindings): https://wiki.videolan.org/LibVLC/
The equivalent to what you're saying would be if he'd just used the HTML5 <video> tag.
This is actually a great article, it taught me a little bit more about FFMPEG under the hood, and knowledge is power.
I also like that it just used C.