2

I have a video stream I captured with VLC and saved as a TS file. The codecs within the file are h.264/AAC, so I thought it would be trivial to use ffmpeg to convert the file from a TS container to MP4 container, so that I can play the file in QuickTime. I used the following command:

ffmpeg -i vlc-output.ts -acodec copy -vcodec copy car-free\ tourism.mp4

All seemed fine, but whilst the resulting file can be opened in QuickTime, after playing 1s of the file, it jumps back to the beginning and then plays the audio only, with the video staying black. The video plays fine in VLC and MPlayerX. I can't understand why QuickTime won't play the file. The codecs look compatible, and the file length looks fine. Am I doing something wrong? Is there additional metadata that QuickTime needs?

I somehow suspect that the issue lies with a lack of complete bit rate metadata, but am out of my depth.

Thanks for any help.

The output from ffprobe for both files is as follows:

vlc-output.ts

[~/Desktop] 113: ffprobe vlc-output.ts                                                   10:51:13 
ffprobe version 3.3.3 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vlc-output.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    creation_time   : 2015-06-23T20:48:30.000000Z
    playback_requirements: QuickTime 6.0 or greater
    playback_requirements-eng: QuickTime 6.0 or greater
    encoder         : vlc 2.2.1 stream output
    encoder-eng     : vlc 2.2.1 stream output
  Duration: 00:01:50.09, start: 0.000000, bitrate: 1149 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1051 kb/s, 25 fps, 25 tbr, 1000k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : SoundHandler

car-free tourism.mp4

[~/Desktop] 114: ffprobe car-free\ tourism.mp4                                           10:51:36 
ffprobe version 3.3.3 Copyright (c) 2007-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'car-free tourism.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
  Duration: 00:01:50.09, start: 0.000000, bitrate: 1150 kb/s
    Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1051 kb/s, 25 fps, 25 tbr, 1000k tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

When I use the -report option when running the rewrap command, I get the following log file:

ffmpeg-20170824-164217.log

ffmpeg started on 2017-08-24 at 16:42:17
Report written to "ffmpeg-20170824-164217.log"
Command line:
ffmpeg -i vlc-output.ts -acodec copy -vcodec copy -report "car-free tourism.mp4"
ffmpeg version 3.3.3 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Splitting the commandline.
Reading option '-i' ... matched as input url with argument 'vlc-output.ts'.
Reading option '-acodec' ... matched as option 'acodec' (force audio codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-vcodec' ... matched as option 'vcodec' (force video codec ('copy' to copy stream)) with argument 'copy'.
Reading option '-report' ... matched as option 'report' (generate a report) with argument '1'.
Reading option 'car-free tourism.mp4' ... matched as output url.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option report (generate a report) with argument 1.
Successfully parsed a group of options.
Parsing a group of options: input url vlc-output.ts.
Successfully parsed a group of options.
Opening an input file: vlc-output.ts.
[NULL @ 0x7f8f8e004200] Opening 'vlc-output.ts' for reading
[file @ 0x7f8f8ce00300] Setting default whitelist 'file,crypto'
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] ISO: File Type Major Brand: isom
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Processing st: 0, edit list 0 - media time: 0, duration: 109960000
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Unknown dref type 0x206c7275 size 12
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Processing st: 1, edit list 0 - media time: 0, duration: 4854784
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] Before avformat_find_stream_info() pos: 76497 bytes read:98304 seeks:0 nb_streams:2
[h264 @ 0x7f8f8e008400] nal_unit_type: 9, nal_ref_idc: 0
[h264 @ 0x7f8f8e008400] nal_unit_type: 7, nal_ref_idc: 3
[h264 @ 0x7f8f8e008400] nal_unit_type: 8, nal_ref_idc: 3
[h264 @ 0x7f8f8e008400] nal_unit_type: 6, nal_ref_idc: 0
[h264 @ 0x7f8f8e008400] nal_unit_type: 5, nal_ref_idc: 3
[h264 @ 0x7f8f8e008400] user data:"x264 - core 118 r2085 8a62835 - H.264/MPEG-4 AVC codec - Copyleft 2003-2011 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=5 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=36 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=2 keyint=50 keyint_min=25 scenecut=0 intra_refresh=0 rc_lookahead=40 rc=cbr mbtree=1 bitrate=1200 ratetol=1.0 qcomp=0.60 qpmin=10 qpmax=51 qpstep=4 vbv_maxrate=1200 vbv_bufsize=600 nal_hrd=none ip_ratio=1.40 aq=1:1.00"
[h264 @ 0x7f8f8e008400] Reinit context to 640x368, pix_fmt: yuv420p
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] All info found
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f8f8e004200] After avformat_find_stream_info() pos: 99278 bytes read:131072 seeks:0 frames:2
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'vlc-output.ts':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    creation_time   : 2015-06-23T20:48:30.000000Z
    playback_requirements: QuickTime 6.0 or greater
    playback_requirements-eng: QuickTime 6.0 or greater
    encoder         : vlc 2.2.1 stream output
    encoder-eng     : vlc 2.2.1 stream output
  Duration: 00:01:50.09, start: 0.000000, bitrate: 1149 kb/s
    Stream #0:0(eng), 1, 1/1000000: Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1051 kb/s, 25 fps, 25 tbr, 1000k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng), 1, 1/44100: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : SoundHandler
Successfully opened the file.
Parsing a group of options: output url car-free tourism.mp4.
Applying option acodec (force audio codec ('copy' to copy stream)) with argument copy.
Applying option vcodec (force video codec ('copy' to copy stream)) with argument copy.
Successfully parsed a group of options.
Opening an output file: car-free tourism.mp4.
[file @ 0x7f8f8ce04fe0] Setting default whitelist 'file,crypto'
Successfully opened the file.
Output #0, mp4, to 'car-free tourism.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 0
    compatible_brands: mp41avc1
    encoder         : Lavf57.71.100
    playback_requirements: QuickTime 6.0 or greater
    playback_requirements-eng: QuickTime 6.0 or greater
    Stream #0:0(eng), 0, 1/1000000: Video: h264 (Main) ([33][0][0][0] / 0x0021), yuv420p, 640x360, q=2-31, 1051 kb/s, 25 fps, 25 tbr, 1000k tbn, 1000k tbc (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng), 0, 1/44100: Audio: aac (LC) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 93 kb/s (default)
    Metadata:
      creation_time   : 2015-06-23T20:48:30.000000Z
      handler_name    : SoundHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
cur_dts is invalid (this is harmless if it occurs once at the start per stream)
No more output streams to write to, finishing.
frame= 2749 fps=0.0 q=-1.0 Lsize=   15455kB time=00:01:50.04 bitrate=1150.5kbits/s speed= 588x    
video:14120kB audio:1258kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.503515%
Input file #0 (vlc-output.ts):
  Input stream #0:0 (video): 2749 packets read (14459053 bytes); 
  Input stream #0:1 (audio): 4741 packets read (1287842 bytes); 
  Total: 7490 packets (15746895 bytes) demuxed
Output file #0 (car-free tourism.mp4):
  Output stream #0:0 (video): 2749 packets muxed (14459053 bytes); 
  Output stream #0:1 (audio): 4741 packets muxed (1287842 bytes); 
  Total: 7490 packets (15746895 bytes) muxed
0 frames successfully decoded, 0 decoding errors
[AVIOContext @ 0x7f8f8ce050a0] Statistics: 60 seeks, 7583 writeouts
[AVIOContext @ 0x7f8f8ce00480] Statistics: 16617055 bytes read, 17 seeks

The video file I'm trying to rewrap is an STV news report stream specified in an m3u8 file, which I captured with VLC. I've put a copy of it here.

0

1 Answer 1

5

Update: The VLC TS is malformed.

First run

ffmpeg -i vlc-output.ts -c copy ffmpeg-output.ts

and then

ffmpeg -i ffmpeg-output.ts -c copy working.mp4

The main thing that looks off is the timebase 1000k tbn.

Try

ffmpeg -i vlc-output.ts -c copy -video_track_timescale 90k car-free\ tourism.mp4
9
  • Thanks for the suggestion, unfortunately it has the same result (except that the video stream says 90k tbn: Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360, 1051 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc (default)
    – jzw
    Aug 24, 2017 at 18:21
  • Then try with a low number, like, say 600.
    – Gyan
    Aug 24, 2017 at 18:36
  • That didn't make a difference to the result. However, I have also realised that the -report option produces a log file (hadn't seen that before), so I've updated the question with the contents of this file from when you first asked me to run the rewrap with a report. Maybe the contents from that file could help identify what's going on? I really appreciate your help, thanks.
    – jzw
    Aug 25, 2017 at 8:39
  • Or another approach: is there some way for me to analyse the .ts file and determine what the timescale should be?
    – jzw
    Aug 25, 2017 at 8:40
  • 1
    Sorry, I only just noticed that you updated this answer. Thanks so much, first copying to a new TS file worked! No need for me to mess with the timebase, when I followed your instruction to copy to a new TS file, then copy from that to an MP4, all works well. So good to finally have this archived properly, your help is much appreciated.
    – jzw
    Jun 5, 2018 at 10:58

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