I have a DVR which records over-the-air TV and saves the recordings in the MPEG-TS format, splitting each episode across multiple files, each ~500 MB in size.
To simplify archiving, I have been trying to write a shell script to automate the process of concatenating the files together and transcoding them into a more common video format, like h.264.
Here are the steps I have performed so far:
- I wanted to make sure that the files I was getting were valid in the first place. To test this, each section was transcoded in Handbrake before being merged using ffmpeg's concat command. This worked, but was manual and added an annoying black frame between each section.
- I wrote a shell script to find all the sections of an episode in a folder and put the file names into a text file that the concat demuxer could parse.
- Tested this command:
ffmpeg -hide_banner -f concat -i video_files_tmp.txt -c:v libx264 -pix_fmt yuv420p -c:a aac $2$OUTPUT_FILE_NAME
During the transcode, this would throw many warnings and errors, such as "PES packet size mismatch". At some point, it would warn that more than 1,000 frame were skipped. When the output was played, it would skip frames and result in a file where the video froze partway through but the audio continued playing. I tried adding -vsync 0 to the output as well.
- Then, tried splitting the concatenation and transcode into two steps:
ffmpeg -hide_banner -f concat -i video_files_tmp.txt -c copy output_tmp.ts
ffmpeg -hide_banner -i output_tmp.ts -c:v libx265 -pix_fmt yuv420p -c:a aac $2$OUTPUT_FILE_NAME
This did basically the same thing as before.
- Tried using the libx265 encoder instead. Same result.
- Then, I tried just playing the concatenated MPEG-TS file directly, which also would freeze at some point during the playback.
I was wondering about what ffmpeg flags or options to set to get this working, or other options I could try? Thanks!
cat
. If you want to do it with ffmpeg you can use the concat protocol like:ffmpeg -i "concat:input1.ts|input2.ts|input3.ts"
. See the wiki for differences between the concat demuxer and protocol. – aergistal