Commit Graph

277 Commits

Author SHA1 Message Date
wm4 cb45b1c65b Cleanup some include statements 2013-07-12 22:16:26 +02:00
wm4 a522483629 demux: remove facility for partial packet reads
Partial packet reads were needed because the video/audio parsers were
working on top of them. So it could happen that a parser read a part of
a packet, and returned that to the decoder. With libavformat/libavcodec,
packets are already parsed, and everything is much simpler.

Most of the simplifications in ad_spdif could have been done earlier.
Remove some other stuff as well, like the questionable slave mode start
time reporting (could be replaced by proper code, but we don't bother).
Remove the unused skip_audio_frame() functionality as well (it was used
by old demuxers). Some functions become private to demux.c, like
demux_fill_buffer(). Introduce new packet read functions, which have
simpler semantics. Packets returned from them are owned by the caller,
and all packets in the demux.c packet queue are considered unread.
Remove special code that dropped subtitle packets with size 0. This
used to be needed because it caused special cases in the old code.
2013-07-11 19:10:33 +02:00
wm4 31f685040b Merge branch 'master' into remove_old_demuxers
Conflicts:
	DOCS/man/en/changes.rst
	DOCS/man/en/options.rst
2013-07-08 21:55:44 +02:00
Martin Herkt c7f631e2c0 sub: Do not use deprecated “Sans” fontconfig alias 2013-07-08 18:02:46 +02:00
wm4 af0c41e162 Remove old demuxers
Delete demux_avi, demux_asf, demux_mpg, demux_ts. libavformat does
better than them (except in rare corner cases), and the demuxers have
a bad influence on the rest of the code. Often they don't output
proper packets, and require additional audio and video parsing. Most
work only in --no-correct-pts mode.

Remove them to facilitate further cleanups.
2013-07-07 23:54:11 +02:00
wm4 588eef86c2 sd_lavc: respect forced subs only setting for DVD subs
Like the old spudec.c code did. Untested, I (probably) don't have a
sample with subtitles that have this flag set.
2013-06-29 22:58:14 +02:00
wm4 ada06703fb sd_ass: convert pts to integer for get_text()
Gives more consistent rounding, which makes sub_step behave better.
2013-06-29 22:58:14 +02:00
wm4 e5c0947541 dec_sub: introduce sub_control(), use it for sub_step
This means the direct libass usage can be removed from command.c, and no
weird hacks for retrieving the ASS_Track are needed.

Also fix a bug when using this feature with ordered chapters.
2013-06-29 22:58:14 +02:00
wm4 f1fc60b32d sub: update subtitle time offset even if paused
This was changed as part of commit b44202b as an intended
simplification, but it's actually nicer to have the subtitles
update immediately even if paused.
2013-06-29 22:58:14 +02:00
wm4 ac79eb7337 core: rename mplayer.h and quvi.c
mplayer.h used to be used for much more stuff, but all what is left are
quvi related definitions. Rename quvi.c as well to make its purpose
clearer.
2013-06-28 15:40:28 +02:00
wm4 398722c5a6 dec_sub: fix memory leak when using subtitle codepage conversion 2013-06-28 14:22:53 +02:00
wm4 4c0896de53 dec_sub: don't print sub charset of it's empty 2013-06-28 14:22:41 +02:00
wm4 403a266d46 Merge branch 'sub_mess2'
...the return.
2013-06-25 00:43:04 +02:00
wm4 00de44eec9 options: add -sub-speed option
Should we actually get into trouble for unproper handling of
frame-based subtitle formats, this might be the simplest way to
work this around. Also is a bit more intuitive than -subfps, which
might use an unknown, misdetected, or non-sense video FPS.
Still pretty silly, though.
2013-06-25 00:34:58 +02:00
wm4 125c20bd08 dec_sub: add hack to display last MicroDVD subtitle event
The old subreader.c infrastructure handled this in a similar way.
2013-06-25 00:11:57 +02:00
wm4 709389ce65 sub: add hack for Libav SRT demuxer
Before this commit, SRT demuxing and display actually happened to work
on Libav. But it was using the libavcodec srt converter (which is
essentially unmaintained in Libav), and timing postprocessing didn't
work. For some background explanations see sd_lavf_srt.c.
2013-06-25 00:11:57 +02:00
wm4 0b2e073853 dec_sub: allow postprocessing between decoders
Until now, timing and charset recoding postprocessing was applied on
packets as they were output by the demuxer, and then passed to the
decoders. Make it so that postprocessing can happen after some decoders
in special situations.
2013-06-25 00:11:57 +02:00
wm4 74c56309a3 dec_sub: change sublist memory allocation 2013-06-25 00:11:57 +02:00
wm4 5dcae2481d dec_sub: move code around 2013-06-25 00:11:56 +02:00
wm4 29cec6f98b sub: prevent subtitle conversion if subs are known UTF-8
Currently this happens only in an obscure case (reading UTF-16 files
with the old subreader).
2013-06-25 00:11:56 +02:00
wm4 f735a03346 sub: add subtitle charset conversion
This code was once part of subreader.c, then traveled to libass, and now
made its way back to the fork of the fork of the original code, MPlayer.

It works pretty much the same as subreader.c, except that we have to
concatenate some packets to do auto-detection. This is rather annoying,
but for all we know the actual source file could be a binary format.

Unlike subreader.c, the iconv context is reopened on each packet. This
is simpler, and with respect to multibyte encodings, more robust.
Reopening is probably not a very fast, but I suspect subtitle charset
conversion is not an operation that happens often or has to be fast.

Also, this auto-detection is disabled for microdvd - this is the only
format we know that has binary data in its packets, but is actually
decoded to text. FFmpeg doesn't really allow us to solve this properly,
because a) the input packets can be binary, and b) the output will be
checked whether it's UTF-8, and if it's not, the output is thrown away
and an error message is printed. We could just recode the decoded
subtitles before sd_ass if it weren't for that.
2013-06-25 00:11:56 +02:00
wm4 feb64c2717 sub: attempt to use video FPS for frame based subtitle formats
This only affects demux_subreader.c for now. Maybe there is some hope
this can be used for libavformat demuxers too, but I'm not sure yet.
2013-06-25 00:11:56 +02:00
wm4 cfa45c40dc sub: add demux_libass wrapper, drop old hacks
demux_libass.c allows us to make subtitle format detection part of the
normal file loading process. libass has no probe function, but trying to
load the start of a file (the first 4 KB) is good enough. Hope that
libass can even handle random binary input gracefully without printing
stupid log messages, and that the libass parser doesn't accept too many
non-ASS files as input.

This doesn't handle the -subcp option correctly yet. This will be fixed
later.
2013-06-25 00:11:56 +02:00
wm4 98388c0c07 subreader: turn into actual demuxer
subreader.c (before this commit renamed to demux_subreader.c) was
special cased to the -sub option. The plan is using the normal demuxer
codepath for all subtitle formats (so we can prefer libavformat demuxers
for most formats).

There are some subtle changes. The probe size is restricted to 32 KB
(instead of unlimitted + giving up after 100 lines of input). For
formats like MicroDVD, the video FPS isn't used anymore, because it's
not available on the subtitle demuxer level. Instead, hardcode it to
23.976 FPS (libavformat seems to do the same). The user can probably
still use -sub-fps to fix the timing. Checking the file extension for
".utf"/".utf8"/".utf-8" is simply removed (seems worthless, was in the
way, and I've never seen this anywhere).
2013-06-25 00:11:56 +02:00
wm4 db2e1ef4d2 Move/rename subreader.c 2013-06-25 00:11:54 +02:00
wm4 2cd53d449a sd_ass: fix nonsense
Actually check the newly added text for whitespace, and not the
uninitialized buffer after it. Also, if an even is only whitespace,
don't add it at all.
2013-06-25 00:11:54 +02:00
wm4 7e033da892 sd_ass: disable special handling of subtitles with duration 0
sd_ass contains some code that treats subtitle events with duration 0
specially, and adjust their duration so that they will disappear with
the next event.

This is most likely not needed anymore. Some subtitle formats allow
omitting the duration so that the event is visible until the next one,
but both subreader.c as well as libavformat subtitle demuxers already
handle this.

Subtitles embedded in mp4 files (movtext) used to trigger this code. But
these files appear to export subtitle duration correctly (at least
libavcodec's movtext decoder is using this assumption). Since commit
6dbedd2 changed demux_lavf to actually copy the packet duration field,
the code removed with this commit isn't needed anymore for correct
display of movtext subtitles. (The change in sd_movtext is for dropping
empty subtitle events, which would now be "displayed" - libavcodec does
the same.)

On the other hand, this code incorrectly displayed hidden events in .srt
subtitles. See for example the first event in SubRip_capability_tester.srt
(part of FFmpeg's FATE). These intentionally have a duration of 0, and
should not be displayed. (As of with this commit, they are still
displayed in external .srt subs because of subreader.c hacks.)

However, we can't be 100% sure that this code is really unneeded, so
just comment the code. Hopefully it can be removed if there are no
regressions after some weeks or months.
2013-06-25 00:11:54 +02:00
wm4 1058d80a5e sd_ass: handle libavformat ASS comment packets as well
Currently, we are filtering libavformat style ASS packets by checking
whether they are prefixed "Dialogue: ". Unfortunately, comment packets
are demuxed too. These start with "Comment: ", so they are not caught.

Change the filtering, and use the codec ID instead. libavformat uses
"ssa" as codec ID for ASS subtitles, while mpv uses "ass". Also, at
least FFmpeg will change the ASS packet format to the same format mpv
and Matroska use, and identify these with "ass" as codec ID, so this is
works out nicely.
2013-06-23 22:34:00 +02:00
wm4 bd45eb468c subreader: remove overlap handling code
Some of this (fixing timing) is now done in dec_sub.c (although it's
not active for subreader.c code yet - this will be fixed when
subreader.c subs are read through a demuxer wrapper).

Another reason to remove this is that this code doesn't do much good
anymore. libass does handle overlap, and trying to fold overlapping
lines into single subtitle events will prevent libass from handling
this properly.
2013-06-23 22:34:00 +02:00
wm4 64b1374a44 sub: do some timing postprocessing on preloaded subs
This fixes the -subfps option (which unfortunately is still useful),
and fixes minor annoying timing errors (which unfortunately still
happen).

Note that none of these affect ASS or image subtitles. ASS is specially
handled: libass loads subtitles as ASS_Track. There are no actual
packets passed around, and sd_ass just uses the ASS_Track.

Disable the --sub-no-text-pp option. It's misleading now and always was
completely useless.
2013-06-23 22:33:59 +02:00
wm4 a70d575291 sub: preload external text subtitles
If a subtitle is external, read it completely and add all subtitle
events in advance when the subtitle track is selected. This is done
for text subtitles only. (Note that subreader.c and subtitles loaded
with libass are different and don't have anything to do with this
commit.)
2013-06-23 22:33:59 +02:00
wm4 4f5e12136d stream: remove padding parameter from stream_read_complete()
Seems like a completely unnecessary complication. Instead, always add a
1 byte padding (could be extended if a caller needs it), and clear it.

Also add some documentation. There was some, but it was outdated and
incomplete.
2013-06-23 22:33:59 +02:00
wm4 e8ae0b9852 sd_srt: handle '<font color="##FFA500">'
Wow this is stupid.
2013-06-18 02:19:15 +02:00
wm4 1c35794efd stream: remove stream_reset()
This function was called in various places. Most time, it was used
before a seek. In other cases, the purpose was apparently resetting
the EOF flag. As far as I can see, this makes no sense anymore. At
least the stream_reset() calls paired with stream_seek() are completely
pointless. A seek will either seek inside the buffer (and reset the
EOF flag), or do an actual seek and reset all state.
2013-06-16 22:05:09 +02:00
wm4 f3871193fc sd_srt, sd_microdvd: set ASS script resolution
Both converters can output \pos and deal with font sizes, so they assume
a specific script resolution (PlayResX/PlayResY). The implicit
assumption was that a specific resolution was guaranteed. The
MP_ASS_FONT_PLAYRESY constant is connected to this.

Better make it explicit, so that the implicit dependency on
MP_ASS_FONT_PLAYRESY is removed. (Unfortunately, libavcodec sub
converters still don't set PlayResX/PlayResY explicitly, so the value
set by that constant can't be declared as arbitrary yet.)

PlayResY=288 is most likely the SSA natural script resolution (or
something like this?), as well as the libass and VSFilter default.
PlayResX=384 is the fallback value set by libass if PlayResY is set to
288, and PlayResX is unset.
2013-06-03 23:00:39 +02:00
wm4 61dfe12179 sub: add name field to all sub decoders
Might help with debugging.
2013-06-03 22:40:32 +02:00
wm4 3289be9a28 sd_ass: add default style if there aren't any styles
The default style is added by mp_ass_default_track(), but not by
ass_new_track(). Considering this, the previous condition at this point
didn't make much sense anymore: the actual (converted) subtitle format
doesn't matter much for what styling should be applied. What matters is
if the subtitle was originally ASS, or if it was converted to it.

Change the code such that the default style is added if there aren't
any, even after reading sub extradata. (The extradata contains the ASS
header, including the style section.) This might change behavior with
scripts that don't define any styles. The change is either with this
commit or with an earlier commit in this branch, depending on the
situation - there are multiple places where default styles are added
in libass API functions, and it's all a big mess.

Other than with very old or broken files (where different behavior
doesn't matter much), the current code should be pretty safe, though.
2013-06-03 22:40:31 +02:00
wm4 8c63b318dc ass_mp: provide function to add default styles 2013-06-03 22:40:07 +02:00
wm4 9f4261de65 core: add common function to initialize AVPacket
Audio and video had their own (very similar) functions to initialize an
AVPacket (ffmpeg's packet struct) from a demux_packet (mplayer's packet
struct). Add a common function for these.

Also use this function for sd_lavc_conv. This is actually a functional
change, as some libavfilter subtitle demuxers add weird out-of-band
stuff as side-data.
2013-06-03 22:40:07 +02:00
wm4 5d517184f5 sub: never set VSFilter aspect if the ASS subtitle is converted
When e.g. converting SRT to ASS, we certainly don't want them stretched
by video aspect ratio, even if that's necessary for native ASS
subtitles.

Annoying weird details...
2013-06-03 22:40:07 +02:00
wm4 3913e3e383 sub: don't check for duplicates on sub conversion
This mirrors commit "sub: remove check_duplicate_plaintext_event()".
That code was basically duplicated. In general, this code is still
needed when doing conversion during demuxing (mostly because you can
seek during demuxing, which will cause duplicate events by replaying).
2013-06-03 22:40:07 +02:00
wm4 5e2c211a4e sd_lavc_conv: strip style header
Normally, libavcodec subtitle converters will output a style header like
this as part of the extradata:

    Style: Default,Arial,16,&Hffffff,&Hffffff,&H0,&H0,0,0,0,1,1,0,2,10,10,10,0,0

We don't want that, so use some bruteforce to get rid of them.
2013-06-03 22:40:07 +02:00
wm4 74e3ac8bf8 sd_lavc_conv: add hack if AV_CODEC_PROP_TEXT_SUB is not available
Otherwise this could happily open decoders for image subtitles or even
audio/video decoders. AV_CODEC_PROP_TEXT_SUB is a preprocessor symbol,
but it's still better to detect this properly instead of using #ifdef,
because these flags might as well be changed into enums sooner or later.
2013-06-03 22:40:06 +02:00
wm4 e42a771413 sd_ass: strip empty/whitespace lines in -no-ass mode
Will just destroy output. In some cases empty newlines might be used by
bad scripts for spacing; too bad for them.
2013-06-03 22:40:06 +02:00
wm4 b11bd1fe5e sub: make use of libavcodec subtitle converters
This allows using some formats that were not supported until now, like
WebVTT.

We still prefer the internal subtitle reader (subreader.c), because
1. Libav, and 2. random things which we probably want to keep, such as
control over formatting, codepage stuff, or various mysterious
postprecessing done in that code.
2013-06-03 22:40:06 +02:00
wm4 e19ffa02aa sub: turn subassconvert_ functions into sub converters
This means subassconvert.c is split in sd_srt.c and sd_microdvd.c. Now
this code is involved in the sub conversion chain like sd_movtext is.
The invocation of the converter in sd_ass.c is removed.

This requires some other changes to make the new sub converter code work
with loading external subtitles. Until now, subtitles loaded via
subreader.c was assumed to be in plaintext, or for some formats, in ASS
(except in -no-ass mode). Then these were added to an ASS_Track. Change
this so that subtitles are always in their original format (as far as
decoders/converters for them are available), and turn every sub event
read by subreader.c as packet to the dec_sub.c subtitle chain.

This removes differences between external/demuxed and -ass/-no-ass code
paths further.
2013-06-03 22:40:02 +02:00
wm4 14dd951548 sub: split subassconvert.c into sd_microdvd.c and sd_srt.c 2013-06-03 02:09:07 +02:00
wm4 3000df35d3 sub: basic subtitle converters
Add a basic infrastructure for subtitle converters. These converters
work sort-of like decoders, except that they produce packets instead
of subtitle bitmaps. They are put in front of actual decoders.

Start with sd_movtext. 4 lines of code are blown up to a 55 lines file,
but fortunately this is not going to be that bad for the following
converters.
2013-06-03 02:09:07 +02:00
wm4 02ce316ade sub: refactor
Make the sub decoder stuff independent from sh_sub (except for
initialization of course). Sub decoders now access a struct sd only,
instead of getting access to sh_sub. The glue code in dec_sub.c is
similarily independent from osd.

Some simplifications are made. For example, the switch_id stuff is
unneeded: the frontend code just has to make sure to call osd_changed()
any time subtitles are switched.

This is also preparation for introducing subtitle converters. It's much
cleaner to completely separate demuxer header/renderer glue/decoders
for this purpose, especially since sub converters might completely
change how demuxer headers have to be interpreted.

Also pass data as demux_packets. Currently, this doesn't help much, but
libavcodec converters might need scary stuff like packet side data, so
it's perhaps better to go with passing packets.
2013-06-01 19:44:16 +02:00
wm4 27d383918a core: add demux_sub pseudo demuxer
Subtitle files are opened in mplayer.c, not using the demuxer
infrastructure in general. Pretend that this is not the case (outside of
the loading code) by opening a pseudo demuxer that does nothing. One
advantage is that the initialization code is now the same, and there's
no confusion about what the difference between track->stream,
track->sh_sub and mpctx->sh_sub is supposed to be.

This is a bit stupid, and it would be much better if there were proper
subtitle demuxers (there are many in recent FFmpeg, but not Libav). So
for now this is just a transition to a more proper architecture. Look
at demux_sub like an artifical limb: it's ugly, but don't hate it - it
helps you to get on with your life.
2013-06-01 19:43:11 +02:00