-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"copy" output codecs when encoding #728
Comments
This sounds very hard and non-trivial. There are various problems with it, most of all that the playback core is designed to actually decode the video/audio data. If you feel very adventurous, you can try it, but I'm not sure what's the best approach.
No more to decode is considered EOF, and the player will quit. |
@divVerent: cc |
Hi, stream copy is simply not implemented yet due to quite high complexity. Maybe you want to take a look at how ffmpeg.c/avconv.c do this - there are Nevertheless, patches for this are always welcome, and we won't reject them However, you may rather want to consider a restricted copy mode that only We already support raw AC3 and MPEG2 streams (IIRC that includes MP3 audio, A next step then could be adding more raw audio formats, especially AAC Best regards, Rudolf
|
Careful about this. Raw AC3 etc. does actually not work - you'll lose A/V sync quickly, because everything in the mpv audio chain actually expects to samples (instead of compressed packets) too. The way it works is that uncompressed audio is put into SPDIF frames (or whatever the proper term is), which basically adds a header and pads the raw packet with zero bytes. So, it's not that easy. But yes, we can follow that approach if a maximum compressed packet size is known. ad_spdif supports a number of codecs, so I expect all these can be safely transferred. Other codecs might have unbounded packet sizes. |
Clarification: it padds the packets with zero to a maximum size, so that the average bitrate remains constant. This way SPDIF pretends to be PCM audio. I've thought more than once to change the internal workings of the audio chain to use frames instead of bytes. Maybe this would make it easier for raw passthrough. But that'd be a big change, so the suggested approach might be preferable. For video, this will be much easier, because there's already a mechanism for complicated passthrough of opaque data (used for hw decoding). |
So, do you want to work on this? I don't think anyone else has an interest in adding this feature, although there are probably many who'd want this feature. |
Well, if I knew how, probably yes. The approach @divVerent suggested only works on audio streams I think, and I'm not sure if it's really worth it (at least in my case it isn't, since I'd like to copy video too). My latest approach was to simply hide the avpacket inside an mp_image , but that didn't go very far either (arguably I didn't try very hard though), and after that I kinda gave up. AFAICT, avconv does the AVPacket -> AVFrame -> AVPacket dance, and simply skips the AVFrame part when it copies, which is what I tried to replicate. but it seems this model isn't really applicable here. |
If you want to copy both streams, why not just use avconv then? Or do you want to filter audio only?
|
Sounds like a reasonable approach. Hardware decoding already does something similar (i.e. keep a pointer to a complicated data structure, instead of image data). |
That's what I'm doing. But why does mpv even support encoding if everyone can use avconv/ffmpeg instead? As far as I'm concerned avconv (or ffmpeg for that matter) has an horrible interface, so I try to avoid it, and having to use it only for the copy feature seems a bit silly if it can be implemented in mpv.
Interesting, I did not think of that. It seems that, while the data in the hwdec mp_image is "dummy", the other parameters (e.g. width and height) have valid values. Are those important? In any case, I'm going to have a more in-depth look at this in the the next few days. |
Well, typically,
Yes. As far as hardware decoding is concerned, these values are important for e.g. determining correct scaling of the output. For this hypothetical "copy" encoding, I'm not sure how much it will matter (other than displaying the information on the terminal). Of course vo_lavc currently uses the image dimensions to initialize the encoder, but you'd hack using encoders out of the copy code path. Anyway, the really hard part is remuxing itself. For example, h264 in mkv is actually not the same as h264 in mp4, and you need a "bitstream filter" (some obscure ffmpeg API) to convert them. (Or maybe it wasn't mkv and mp4, but another pair.) |
Hi, Oh, that's easy. Even today, ffmpeg doesn't provide some really useful features: subtitle ffmpeg now has a half excuse of the feature that requires the subtitles to Also, ffmpeg lacks a way to select audio/subtitle streams by language. In the end, you can shoehorn all these features (except for the missing Also, mpv has more input sources than ffmpeg (e.g. mpv can read from Now, as for audio, I am not aware of any relevant filters mpv has that mpv's encoding feature was primarily designed to stay stable over time. It Now, the issue with stream copy is that mpv's code makes some assumptions - One thing I wonder though - why don't we just use wrappers to And if we make such wrappers - why not have them in lavc directly? :) Best regards, Rudolf Polzer
|
Sounds like it could work... bonus points if it can use the bitstream filter stuff and all these headaches. |
Ping? |
Nobody even maintains our encoding mode, so I guess this is hopeless anyway. |
avconv supports using the special "copy" audio/video codecs, that simply copy (duh!) the streams from input to output without doing any decoding/encoding, so I've looked into adding something similar for mpv.
My idea was to add acopy/vcopy flags into encode_lavc_context, dec_audio and dec_video so that ad/vd_lavc would stuff the read AVPacket somewhere instead of decoding it, and ao/vo_lavc would read that packet and write it to the output as is.
I haven't done anything yet though, because looking into the code there are a few things that I don't understand. E.g. what happens if audio/video_decode() return an empty buffer?
Or maybe there's a better way to do this...
The text was updated successfully, but these errors were encountered: