Log in

View Full Version : Keeping Text Track in Encode


Google
6th October 2014, 06:47
Quick question. I have .ts files with text tracks (usually closed captioning) that I want to transfer over into the encoded file. Usually its just one text track, but I've seen anywhere from 1-4 in a raw stream. What would be a working Avisynth script to transfer over the text files from the raw into the final file during the encoding process?

feisty2
6th October 2014, 08:07
what an adorable id u got, :D

colours
6th October 2014, 13:54
Let me just preemptively state that doing this in Avisynth is a terrible idea, in case someone is going to write a transport stream parser in GScript.

The easiest way would be to use some other software to extract the captions (Google is your friend), then shift them so that they sync with the audio/video. Shifting might or might not be necessary; this depends on how the caption extractor works.

If your final file is going to be Matroska or a similarly flexible format, you can just mux the captions into it after everything else is done. If it's not, you'll have to figure out what subtitle formats are allowed in your use case and adapt the process accordingly.

creaothceann
6th October 2014, 19:10
(Google is your friend)

You can be friends with yourself? :)

Google
6th October 2014, 22:26
Let me just preemptively state that doing this in Avisynth is a terrible idea, in case someone is going to write a transport stream parser in GScript.

The easiest way would be to use some other software to extract the captions (Google is your friend), then shift them so that they sync with the audio/video. Shifting might or might not be necessary; this depends on how the caption extractor works.

If your final file is going to be Matroska or a similarly flexible format, you can just mux the captions into it after everything else is done. If it's not, you'll have to figure out what subtitle formats are allowed in your use case and adapt the process accordingly.I'm just looking to move the text track from the raw to the encoded mkv. Essentially, just having some sort of script in the encoder I use (StaxRip) would probably do it. So I'm just looking for that script. I don't need to move any captions around or use other software because I've been told it can be done right in the encoding process.

colours
6th October 2014, 22:38
If you're looking for a certain pre-existing script, try mentioning that next time. But even if it existed, it sure as hell can't be an Avisynth script unless it also hardsubs. (Or if someone really wrote a transport stream parser.)

That still doesn't discount the fact that extracting the captions from the transport stream to mux later is a viable option if you'd stop being obstinate about not using any other software.

Google
6th October 2014, 23:27
If you're looking for a certain pre-existing script, try mentioning that next time. But even if it existed, it sure as hell can't be an Avisynth script unless it also hardsubs. (Or if someone really wrote a transport stream parser.)

That still doesn't discount the fact that extracting the captions from the transport stream to mux later is a viable option if you'd stop being obstinate about not using any other software.
lol, okay. Yes, I'm looking for a pre-existing script to keep text tracks from a raw into the encode.

qyot27
7th October 2014, 00:08
AviSynth doesn't do direct stream copy (and the attempts to make it do it really only applied to video streams). AviSynth scripts aren't shell scripts, and can't execute themselves - it needs an encoder.

It is possible, however, to do this in some encoding programs by giving the program both the AviSynth script and the original source file, using the script as source for the video/audio and the original file as the source for subtitles. FFmpeg can do this with the -map option and hooking it into the codec selectors (https://trac.ffmpeg.org/wiki/How%20to%20use%20-map%20option). This is assuming the subtitle track's timecodes don't get completely screwed up by doing so, and that the subtitle stream is not in some exotic format FFmpeg can't read. I just tried doing this with a test file I had laying around, and while it's an MKV with ASS subtitles, the concept is the same.

>ffmpeg -i test.avs -i test.mkv -map 0:0 -map 0:1 -map 1:3 -c:v:0:0 mjpeg -c:a:0:1 pcm_s16le -c:s:1:3 copy output2.mkv
This takes the script's video (0:0) and audio (0:1), and the MKV file's subtitles (1:3), encodes the video and audio to mjpeg and pcm, while copying the subs over into the output MKV. In order to prove that the video did come from the script, I inserted Subtitle("avisynth") into the script.

The result: the video clearly came from the script due to the presence of the yellow 'avisynth' in the top left corner, while having a discrete subtitle track that could be turned on and off in the player.

>ffmpeg -i test.avs -i test.mkv -map 0:0 -map 0:1 -map 1:3 -c:v:0:0 mjpeg -c:a:0:1 pcm_s16le -c:s:1:3 copy output2.mkv
ffmpeg version r66668 git-acdbe90 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct 6 2014 12:38:51 with gcc 4.9.1 (GCC)
libavutil 54. 9.100 / 54. 9.100
libavcodec 56. 3.100 / 56. 3.100
libavformat 56. 7.104 / 56. 7.104
libavdevice 56. 1.100 / 56. 1.100
libavfilter 5. 1.102 / 5. 1.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.100 / 3. 1.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 1.100 / 53. 1.100
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, avisynth, from 'test.avs':
Duration: 00:05:00.47, start: 0.000000, bitrate: 0 kb/s
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 848x480, 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
Stream #0:1: Audio: pcm_f32le, 44100 Hz, 2 channels, flt, 2822 kb/s
Input #1, matroska,webm, from 'test.mkv':
Metadata:
encoder : libebml v1.3.0 + libmatroska v1.4.1
creation_time : 2013-07-26 22:04:24
Duration: 00:05:00.47, start: 0.000000, bitrate: 1438 kb/s
Stream #1:0(eng): Video: h264 (High), yuv420p, 848x480, SAR 1:1 DAR 53:30, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (
default) (forced)
Stream #1:1(eng): Audio: aac, 44100 Hz, stereo, fltp (default) (forced)
Stream #1:2: Subtitle: subrip (default) (forced)
Metadata:
title : Dummy Subtitles
Stream #1:3(eng): Subtitle: ass
Metadata:
title : Karaoke Subtitles [ASS]
Stream #1:4: Attachment: ttf
Metadata:
filename : Ubuntu-R.ttf
mimetype : application/x-truetype-font
Stream #1:5: Attachment: text
Metadata:
filename : knife.txt
mimetype : text/plain
Stream #1:6: Attachment: png
Metadata:
filename : release_poster.png
mimetype : image/png
File 'output2.mkv' already exists. Overwrite ? [y/N] y
[swscaler @ 03f5bee0] deprecated pixel format used, make sure you did set range correctly
Output #0, matroska, to 'output2.mkv':
Metadata:
encoder : Lavf56.7.104
Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj420p, 848x480, q=2-31, 200 kb/s, 23.98 fps, 1k tbn, 23.98 tbc
Metadata:
encoder : Lavc56.3.100 mjpeg
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s
Metadata:
encoder : Lavc56.3.100 pcm_s16le
Stream #0:2(eng): Subtitle: ass
Metadata:
title : Karaoke Subtitles [ASS]
encoder : Lavc56.3.100 ass
Stream mapping:
Stream #0:0 -> #0:0 (rawvideo (native) -> mjpeg (native))
Stream #0:1 -> #0:1 (pcm_f32le (native) -> pcm_s16le (native))
Stream #1:3 -> #0:2 (ass (native) -> ass (native))
Press [q] to stop, [?] for help
frame= 3512 fps= 11 q=24.8 Lsize= 67292kB time=00:02:28.98 bitrate=3700.2kbits/s
video:41864kB audio:25226kB subtitle:18kB other streams:0kB global headers:5kB muxing overhead: 0.275500%

>mpv output2.mkv
Playing: output2.mkv
[stream] Video (+) --vid=1 (mjpeg)
[stream] Audio (+) --aid=1 (*) (pcm_s16le)
[stream] Subs (+) --sid=1 --slang=eng (*) 'Karaoke Subtitles [ASS]' (ass)
File tags:
ENCODER: Lavf56.7.104
AO: [dsound] 44100Hz stereo 2ch s16
VO: [opengl-old] 848x480 => 848x480 yuv420p
AV: 00:00:55 / 00:02:33 (35%) A-V: 0.004
fontconfig_select: Using default font: (Ubuntu, 80, 0) -> C:/Program Files/mpv-player/mpv/subfont.ttf, 0
AV: 00:01:01 / 00:02:33 (39%) A-V: 0.002
[osd/libass] fontconfig_select: Using default font: (sans-serif, 80, 0) -> C:/Program Files/mpv-player/mpv/subfont.ttf,
AV: 00:01:01 / 00:02:33 (39%) A-V: 0.001
[osd/libass]
AV: 00:01:07 / 00:02:33 (44%) A-V: 0.013


Exiting... (Quit)