LordH3lmchen / TwitchDownloader

A download tool for past broadcasts.
GNU General Public License v3.0
67 stars 9 forks source link

TS files can be concatenated after download #2

Closed 13k closed 9 years ago

13k commented 9 years ago

Hey, very useful project, thanks for sharing it!

I recently downloaded a 10 hours stream session and as you can imagine, it is long. Playing the playlist works, but it's very annoying to have glitches, specially in audio, every 3 seconds, so I tried to convert it using the ffmpeg method in the app, but for some reason ffmpeg was taking almost or even the actual duration time of the video to convert everything. I don't know if it has to "playback", or transcode, or if it's the nature of the process (very large number of very small files).

Anyway, I went searching for alternatives to using ffmpeg and its concat filter and some people were saying in forums that you can simply physically concatenate all the files. I tried, and guess what, it worked (it is played by VLC).

I simply wrote a script to go over the ffmpeg playlist and concatenate all those files into a single big .ts file.

So I'd suggest that the app do the same, or offer the option, to generate a single .ts file at the end of the download.

LordH3lmchen commented 9 years ago

plz send me the script i try to implement this in the next version.

13k commented 9 years ago

it has no algorithm, it simply creates a new destination file (say "output.ts") and iterates over all files in the playlist, reading their whole content and appending to the "output.ts" file. something like this in Unix shells:

for i in *.ts; do
  cat "$i" >> "output.ts"
done

or python:

import glob

with open("output.ts", "wb") as outputf:
  for input in glob.glob("*.ts"):
    with open(input, "rb") as inputf:
      outputf.write(inputf.read())
LordH3lmchen commented 9 years ago

I did some research. You are right, ts containers can be cat together.

https://en.wikipedia.org/wiki/MPEG_transport_stream

I've implemented that. So when all parts are downloaded, the program starts cat the parts together and removes them.

I parse the API response of the video playlist from Twitch (instead of simple using it) to download parts that are as big as possible. 120sec instead of 3 sec. A 10 hour streaming session should now use about 300 Files (12000 Files before)

So ffmpeg isn needed anymore. And it shoudnt hang that often when you watch the video while downloading.

Twitch also changed the API again. Source Quality should work again.

13k commented 9 years ago

thanks man!

fabd commented 9 years ago

Hey thanks, great tool and the UI is really nice too. This works way better than the earlier version and I get a better quality video as well.

Do you think it's possible to download just up to X amount of time? (doesn't have to be super precise). Reason is because sometimes I want to save the chit chat part of some favorite streams which is often at the beginning, but is part of a several hours stream. So for example I would say "up to 20 min" and it would stop downloading and concatenate whatever is downloaded up to that point.

13k commented 9 years ago

I think it would be a good addition. Also pause/resume features, I think it's technically possible.

But they should deserve new issues here in github for each one as well.