-1

I have >1000s of small .ts files from a DLINK camera of a theft that occured. I first tried to merge the ts files into bigger files so that I could look for the audio where the relevant event occurred. Then in Premiere I looked for the highest sustained audio peaks (it was someone using a saw to cut out a catalytic converter). Then, I isolated the relevant 200 files where things happened on the timeline. But now, I want to export the 20 minutes of the incident with the least compression (or no compression). Apparently Adobe Premiere can export the whole timeline containing these clips, but will compress them. I have not edited any of the files, so I don't want any rendering. I just want them strung together in a "well-known" format so I can send the files to the insurance company and authorities.

I used an answer from here but there were audio gaps. Some of the files had no audio, causing the problem when I first merged the files with:

 for i in `\ls *.ts | sort -V`; do echo "file '$i'"; done >> mylist.txt;ffmpeg -f concat -i mylist.txt -c copy -bsf:a aac_adtstoasc video.mp4
anjchang
  • 483
  • 1
  • 7
  • 14
  • 2
    ts files can simply be concatenated using the `cat` shell utility. some programs support stream-copy editing (no transcoding). – Christoph Rackwitz Jun 13 '22 at 06:50
  • Thanks @ChristophRackwitz for the comment. The problem I'm running into now is that it seems some of the audio in some of the files is not as long as the video in the files. So I am still getting gaps. – anjchang Jun 13 '22 at 14:42
  • Also, it seems that although I have combined the files without re-encoiding-- when I look at the original smalelr ts, I found that the audio is often at inconsistent sampling (17kbps-30kbps). So I still get audio gaps. – anjchang Jun 13 '22 at 15:15
  • 1
    "doesn't seem to work"? can you explain what you mean by that? that post you linked... I don't know what's confusing you about that. concatenating ts files does a specific thing. it does not do other things. it's that simple. bitrate has nothing to do with time. I hope you aren't expecting to calculate an amount of bytes given a time length. you have to edit audio/video properly, with the proper tools. – Christoph Rackwitz Jun 13 '22 at 15:22
  • 'cat' doesn't seem to work because the audio and video get out of sync https://superuser.com/a/1377739/210400 The files were created by a DLINK camera that saved the streams at the same time into the same file. – anjchang Jun 13 '22 at 15:57
  • 1
    then those files weren't created from the same audio/video stream, but muxed to have their own timestamps. -- don't simply believe the assertions of a random person on the internet (I mean the answer you linked there) – Christoph Rackwitz Jun 13 '22 at 15:58
  • The link here shows how the files were created from the same events, but I am not sure how to join the files so audio is consistent in one output file that has minimal (or no compression) https://stackoverflow.com/questions/72605364/combine-ts-files-with-inconsistent-audio-kb-s-into-one-file-with-consistent-audi Thank you @ChristophRackwitz, I do appreciate your advice – anjchang Jun 13 '22 at 16:05
  • that just links back to here for the "background", and all you're saying is that it's a "DLINK" camera. -- honestly, just give the court/police/investigators those file pieces. they can deal with that. – Christoph Rackwitz Jun 13 '22 at 16:10
  • The ts files containing the audio and video were created from the same "stream of events" by the DLINK camera. The picture in the post shows what the streams look like. In one view, the audio gets "smoothed out" so that the duration of audio and video are synced. In the bottom view, the audio is compressed at the front of each clip. I want to combine all the ts files into one so that each audio clip gets "smoothed out" across the whole file. But OK, I'll send all these 200 files to the insurance and authorities and trust they can handle them. – anjchang Jun 13 '22 at 16:15
  • 1
    the shotcut visualization may just be a bug in shotcut. don't put too much stock in what it shows. I'd trust Premiere more. – Christoph Rackwitz Jun 13 '22 at 16:30
  • @ChristophRackwitz Thank you! Shotcut has noticeable audio gaps when listening to it. Premiere has portions of audio with gaps where it doesn't sense there's audio. After trying to run cat in many different ways, I ended up merging the files together with cat using `xargs cat >catout.ts ` and then `ffmpeg -i catout.ts -map 0 -c copy catout.mp4` is exactly what I wanted. I still get an error `cat: file: No such file or directory` but there is consistent and clear audio that you can see/hear the sequence of the suspect during the theft. – anjchang Jun 13 '22 at 16:36
  • 1
    xargs expects a simple list of files. `mylist.txt` contains a format that ffmpeg wants, which introduces each file with `file ` – Christoph Rackwitz Jun 13 '22 at 17:11
  • Thanks @ChristophRackwitz I removed the prefix 'file' from each line in mylist.txt and there were no errors making the list `xargs cat < barelist.txt >>barecatout.ts` or creating the ts file `ffmpeg -i barecatout.ts -map 0 -c copy barecatout.mp4` File size is smaller now, but the AV quality seems fine. Thank you so much again for helping take a bite out of crime! – anjchang Jun 13 '22 at 19:32

2 Answers2

1

This worked for me, and I'm sending it along to help the investigation.

xargs cat <mylist.txt >>catout.ts

ffmpeg -i catout.ts -map 0 -c copy catout.mp4
anjchang
  • 483
  • 1
  • 7
  • 14
0

I had >200 .ts files from a DLINK security camera I needed to stitch up losslessly for the authorities (insurance).

After looking around on Stackoverflow, here's what I did. First create a list of the ts files to combine:

for i in `\ls *.ts | sort -V`; do echo "file '$i'"; done >> mylist.txt;

Merge them into one ts:

ffmpeg -f concat -safe "0" -i mylist.txt -c copy merge.ts

Then convert the ts directly and losslessly to a well known format for the authorities

ffmpeg -i merge.ts -map 0 -c copy output.mp4
anjchang
  • 483
  • 1
  • 7
  • 14
  • 2
    With current ffmpeg, you may find the concatf protocol better for TS inputs. http://www.ffmpeg.org/ffmpeg-protocols.html#concatf – Gyan Jun 13 '22 at 11:26
  • @Gyan Thank you for the comment. I could not figure out how to concatf the files. can you give me an example? I tried `ffmpeg concatf:mylist.txt -map 0:v -map 1:a -c copy concatf_out.ts` and got the following error: Unable to find a suitable output format for 'concatf:mylist.txt' concatf:mylist.txt: Invalid argument – anjchang Jun 13 '22 at 15:05
  • 1
    ah! "While the demuxer works at the stream level, the concat protocol works at the file level." so that is the difference between `-i concatf:list.txt` (concatf *protocol*) and `-f concat -i list.txt` (concat *demuxer*) https://trac.ffmpeg.org/wiki/Concatenate – Christoph Rackwitz Jun 13 '22 at 15:35
  • Thanks @ChristophRackwitz I tried `ffmpeg -i concatf:mylist.txt -map 0:v -map 1:a -c copy concatf_out.ts`. but it says `concatf:mylist.txt: Protocol not found Did you mean file:concatf:mylist.txt?` And mylist.txt exists and is the file I've been using... – anjchang Jun 13 '22 at 15:40