2

I see here (How to convert .ts file into a mainstream format losslessly?) that MKV is recommended for that purpose (ffmpeg -i input -map 0 -c copy output.mkv), but not MP4, which is said to involve re-encoding the video.

(Based on that, I use sh -c 'ffmpeg -i "$0" -map 0 -c copy "${0%%.*}".mkv' %f in a context menu action as said here.)

Here (How to convert .mkv file into .mp4 file losslessly?) I see that converting MKV to MP4 without re-encoding is very easy (ffmpeg -i input.mkv -codec copy output.mp4), by simply changing the container.

If TS->MKV->MP4 conversion-without-recoding is possible, shouldn't TS->MP4 be possible directly too?


I have added to my file manager context menu the command sh -c 'ffmpeg -i "$0" -map 0 -c copy "${0%%.*}".mp4' %f and it works without problems for .ts files just like for .mkv .

Checking with Mediainfo the two resulting MP4 files (the TS->MP4 and the TS->MKV->MP4, where -> is the aforementioned command) I see basically the same info about their video content.

enter image description here

The rest is the same:

Encoding settings : cabac=1 / ref=1 / deblock=1:0:0 / analyse=0x3:0x3 / me=dia / subme=3 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=0 / 8x8dct=1 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=0 / threads=8 / lookahead_threads=2 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=0 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=250 / keyint_min=25 / scenecut=40 / intra_refresh=0 / rc_lookahead=0 / rc=crf / mbtree=0 / crf=24.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / vbv_maxrate=3000 / vbv_bufsize=3000 / crf_max=0.0 / nal_hrd=none / filler=0 / ip_ratio=0.71 / pb_ratio=1.30 / aq=1:1.00

3

TS > MP4? It Depends™

Yes, TS video be converted (re-muxed) directly to MP4 video without re-encoding if the video and audio formats are compatible. Your video is H.264 which is currently the most common and most compatible video format in MP4, so copying it from the TS to the MP4 will be no problem.

Arbitrary formats

TS supports more formats than MP4. If you try to mux arbitrary formats into MP4 the possible results are:

  • Success - the formats are supported by the FFmpeg MP4 muxer and your player/device.

  • Partial success - the formats are supported by the FFmpeg MP4 muxer, but not supported by your player/device. This could be the case for less common or legacy formats supported by MP4.

  • Failure - the formats are not supported and the muxer will give you an error message such as Could not find tag for codec foo in stream #0, codec not currently supported in container

Recommended procedure

So for full compatibility I recommend re-encoding if the formats are not the common and widely supported H.264 or H.265/HEVC video + AAC audio.

For automation you can use ffprobe to determine the formats. See Is there a way to use ffmpeg to determine the encoding of a file before transcoding? for an example. Then use an if/then statement in your script to execute the correct command.

Subtitles

The main exception is subtitles. MP4 doesn't have good subtitle support. If your TS contains text subtitles (ASS/SSA, SRT) then you can convert them to timed text (-c:s mov_text), but support for timed text subtitles among players is not universal. Image based subtitles will have to be excluded, such as with negative mapping -map 0 -map -0:s.

4
  • Is it then true that TS->MKV is less problematic or not at all? (In which case a simple way is TS->MKV->MP4?) – cipricus Mar 4 '20 at 23:45
  • 1
    @cipricus No, there is no reason to do TS->MKV->MP4. I'm not sure where this notion originated. You can do TS->MP4 directly as long as the formats are supported. – llogan Mar 4 '20 at 23:49
  • That idea (the need for TS->MKV->MP4) was in case TS->MKV and MKV->MP4 would have always worked. But now I understand that is not the case. When it works, like in this case, it's because the MKV file there contains h.264 video; I guess what you say about "Arbitrary formats" in TS applies to MKV too (MKV supports more formats than MP4). — What about TS->MKV? Is TS supporting more formats than MKV? – cipricus Mar 5 '20 at 12:43
  • 1
    Yes, MKV supports more formats than MP4. MKV can handle so many formats that TS->MKV should likely not be problematic, but of course there will always be exceptions. – llogan Mar 5 '20 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.