mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
27.83k stars 2.87k forks source link

[feature request] make frame-type property available #2444

Closed j77h closed 8 years ago

j77h commented 8 years ago

Can't see anywhere that mpv/libmpv provides the frame type: I-frame/key-frame, P-frame, B-frame.

Tell me if it's there, but if not, could you make a frame-type property accessible, perhaps in the same way as time-pos is provided now.

Use case example: When making a list of cut-points for removing ads from PVR files, it would help to know which frames are I-frames.

I'm starting to make a little mpv-based app, to write the time of each chosen cut-point to a file (marking each as a start or end point). Can make the app anyway, but if it can show frame-type it will be better.

If mpv won't provide frame-type I'll try ffplay instead, but it looks a bit scary -- I'm not a C programmer, I use Python3, and I'm trying ctypes for the first time.

mia-0 commented 8 years ago

Hint: Try ffms2. It has a straightforward API and indexes files in advance, which means you can easily get a list of all frames of a particular type.

ghost commented 8 years ago

Codecs are more complicated than this. Just because there's an I-frame it doesn't mean you can actually cut it there, at least with h264/hevc.

j77h commented 8 years ago

@lachs0r: I was hoping not to have to make an index first. It would be good to make a cut list almost as quickly as skipping through a video in mpv. @wm4: Australian DVB-T is mpeg2 (or now mheg, whatever that is). If I cut h.264, it's stuff i encoded myself (from the mpeg2). So far I've always been able to cut on i-frames without recoding.

There are 2 ways I tend to cut: 1 - before/when transcoding. filter_complex has to re-encode anyway, so finding key-frames is not essential. Even so, there's a key frame every 12 or 13 frames, so there'd be a good chance of finding an acceptable one if they were identifiable. 2 - after transcoding. If i don't have time to cut before i run short of space I transcode first. I set scene-change detection fairly high (60 or more) to improve the chance of getting a key frame in every black sequence. Cutting this h264 is when i most need to find a key frame, as there are fewer of them, and i don't want to re-encode the whole thing. It's said that FFmpeg can do 'smart encoding' -- just the frames between a cut and a key frame -- but i haven't tested to prove it yet. If it works well, identifying key frames would not be essential, but it would still be good to be able to choose a key frame when there is one in the black.

Years ago i used MpegStreamclip (closed source, Apple-based, win/mac only, no mkv) with which i could very quickly find a place to cut: first skip in 1-min jumps; when i see an ad, skip on key frames to the black frames at start and end of ad break, then use single-frame-step to make sure this black key-frame is really at the start or end of the ads, then mark it as an 'in' or 'out' point.

Haven't found anything (free) that works so well, and i've searched on and off for the last few years. Some free video editors might do it, but they'll recode only with standard parameters, and i want to use more efficient x264 options (vbr), and sometimes non-standard frame-sizes such as 768x432 or 960x540. DVB-Cut sometimes works, but it doesn't keyboard-skip on every key frame, the gui control needs a lot of slow clumsy mousing, and it cuts only mpeg, not mkv or mp4.

So we really need a 'simple' video cutter that opens mkv as well, and is efficient to use. Would like to use mpv to find the cut points, as it's so neat and quick. It's not essential to see frame types, but if it's not too much trouble, it would be great.

Just realized that skipping on key frames without missing any is also part of doing this job quickly, and mpv doesn't do that either... Can this be feature-request part 2 ?