Opened 6 years ago

Closed 5 years ago

Last modified 4 years ago

#3353 closed defect (invalid)

Transcode to .ts format gives unexpected video start time

Reported by: wdelstrother Owned by:
Priority: normal Component: undetermined
Version: unspecified Keywords: mpegts
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

I am trying to transcode video to .ts format, but the start time on the output video is always non-zero.

I've generated the input video from a raw video format, so it should have no start time information. If I transcode to .avi, .flv or .mp4 format, the reported start time is zero, as expected. However, if I transcode to .ts format, the start time is (repeatably) 1.43333s.

I've seen this with various files, using various codec, and using the "-f ssegment -initial_offset" option, and have seen the same problem each time. For this bug report, to keep things simple, I'm not using any codec specifications.

ffmpeg pulled from Git development branch, 27th Jan 2014, (6369766f015f930ea0fc86a2d425fe7fc4f95ed9).

I generated the ts file as follows:

%ffmpeg -i input_with_zero_start_time.avi -an -y output_with_nonzero_start_time.ts
ffmpeg version N-60202-g6369766 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 27 2014 08:55:15 with gcc 4.6 (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04)
  configuration: 
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 49.100 / 55. 49.100
  libavformat    55. 26.100 / 55. 26.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  1.101 /  4.  1.101
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
Input #0, avi, from 'input_with_zero_start_time.avi':
  Metadata:
    encoder         : Lavf55.26.100
  Duration: 00:00:05.00, start: 0.000000, bitrate: 484 kb/s
    Stream #0:0: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 480x270 [SAR 1:1 DAR 16:9], 30 tbr, 30 tbn, 30 tbc
Output #0, mpegts, to 'output_with_nonzero_start_time.ts':
  Metadata:
    encoder         : Lavf55.26.100
    Stream #0:0: Video: mpeg2video, yuv420p, 480x270 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 90k tbn, 30 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg4 -> mpeg2video)
Press [q] to stop, [?] for help
frame=  150 fps=0.0 q=31.0 Lsize=     337kB time=00:00:04.96 bitrate= 556.6kbits/s    
video:294kB audio:0kB subtitle:0 global headers:0kB muxing overhead 14.672569%

Input file information:

%ffmpeg -v 9 -loglevel 99 -i input_with_zero_start_time.avi 
ffmpeg version N-60202-g6369766 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 27 2014 08:55:15 with gcc 4.6 (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04)
  configuration: 
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 49.100 / 55. 49.100
  libavformat    55. 26.100 / 55. 26.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  1.101 /  4.  1.101
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-i' ... matched as input file with argument 'input_with_zero_start_time.avi'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Successfully parsed a group of options.
Parsing a group of options: input file input_with_zero_start_time.avi.
Successfully parsed a group of options.
Opening an input file: input_with_zero_start_time.avi.
[avi @ 0x2310180] Format avi probed with size=2048 and score=100
[avi @ 0x2310800] use odml:1
[avi @ 0x2310180] Before avformat_find_stream_info() pos: 5674 bytes read:103112 seeks:4
[avi @ 0x2310180] All info found
[avi @ 0x2310180] After avformat_find_stream_info() pos: 24335 bytes read:103112 seeks:4 frames:1
Input #0, avi, from 'input_with_zero_start_time.avi':
  Metadata:
    encoder         : Lavf55.26.100
  Duration: 00:00:05.00, start: 0.000000, bitrate: 484 kb/s
    Stream #0:0, 1, 1/30: Video: mpeg4 (Simple Profile) (FMP4 / 0x34504D46), yuv420p, 480x270 [SAR 1:1 DAR 16:9], 1/30, 30 tbr, 30 tbn, 30 tbc
Successfully opened the file.
At least one output file must be specified
[AVIOContext @ 0x2318860] Statistics: 103112 bytes read, 4 seeks

Output file information:

%ffmpeg -v 9 -loglevel 99 -i output_with_nonzero_start_time.ts 
ffmpeg version N-60202-g6369766 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jan 27 2014 08:55:15 with gcc 4.6 (Ubuntu/Linaro 4.6.4-1ubuntu1~12.04)
  configuration: 
  libavutil      52. 63.100 / 52. 63.100
  libavcodec     55. 49.100 / 55. 49.100
  libavformat    55. 26.100 / 55. 26.100
  libavdevice    55.  5.102 / 55.  5.102
  libavfilter     4.  1.101 /  4.  1.101
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
Splitting the commandline.
Reading option '-v' ... matched as option 'v' (set logging level) with argument '9'.
Reading option '-loglevel' ... matched as option 'loglevel' (set logging level) with argument '99'.
Reading option '-i' ... matched as input file with argument 'output_with_nonzero_start_time.ts'.
Finished splitting the commandline.
Parsing a group of options: global .
Applying option v (set logging level) with argument 9.
Successfully parsed a group of options.
Parsing a group of options: input file output_with_nonzero_start_time.ts.
Successfully parsed a group of options.
Opening an input file: output_with_nonzero_start_time.ts.
[mpegts @ 0x27c7180] Format mpegts probed with size=2048 and score=100
[mpegts @ 0x27c7180] stream=0 stream_type=2 pid=100 prog_reg_desc=
[mpegts @ 0x27c7180] Before avformat_find_stream_info() pos: 0 bytes read:32768 seeks:0
[mpegts @ 0x27c7180] All programs have pmt, headers found
[mpegts @ 0x27c7180] All info found
[mpegts @ 0x27c7180] After avformat_find_stream_info() pos: 0 bytes read:345544 seeks:1 frames:21
Input #0, mpegts, from 'output_with_nonzero_start_time.ts':
  Duration: 00:00:04.97, start: 1.433333, bitrate: 556 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100], 21, 1/90000: Video: mpeg2video (Main) ([2][0][0][0] / 0x0002), yuv420p(tv), 480x270 [SAR 1:1 DAR 16:9], 1/60, max. 104857 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc
Successfully opened the file.
At least one output file must be specified
[AVIOContext @ 0x27cf8c0] Statistics: 345544 bytes read, 1 seeks

Note the small change in duration, and very large change in start time.

Attachments (1)

input_with_zero_start_time.avi (296.0 KB) - added by wdelstrother 6 years ago.
Input video file

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by wdelstrother

Input video file

comment:1 Changed 6 years ago by cehoyos

  • Keywords mpegts added; ts timestamp start time removed

What is wrong with the output file?

comment:2 follow-up: Changed 6 years ago by wdelstrother

The output file plays correctly, but the start time (as reported by ffmpeg -i ...) is non-zero, and actually quite large compared to the video duration. This isn't a problem for a single file, but for the application I am developing I need to manually construct videos to form an m3u8 playlist, where errors in the start time are obviously more significant.

comment:3 in reply to: ↑ 2 Changed 6 years ago by cehoyos

Replying to wdelstrother:

This isn't a problem for a single file, but for the application I am developing I need to manually construct videos to form an m3u8 playlist, where errors in the start time are obviously more significant.

Do you mean you can reproduce an actual problem with -f hls?

comment:4 Changed 6 years ago by wdelstrother

I am not using -f hls, because I don't have a single input file to break down into segments.

The problem that I am seeing is simply that the start time in the .ts file is non-zero, when (as far as I can tell) there is no reason why it should be.

I think I might need to give some more context to what I'm actually trying to do; in my application, I'm receiving a sequence of 5 second files from a 3rd party, and I'm using ffmpeg to transcode each one into a .ts file (with libx264 / aac) with the appropriate start time. I also generate an m3u8 playlist outside of ffmpeg at run-time so that the 'chunked' video can be restreamed in near-real-time.

The only way I've found to set the start time of a .ts file was to use the 'initial_offset' option to ssegment (even though I'm only producing a single segment). So my command line for a single transcode actually looks something like:

%ffmpeg -loglevel warning -i input.avi -c:a aac -strict -2 -ac 2 -ar 44100 -b:a 128k -c:v libx264 -profile:v main -level:v 4.1 -x264opts keyint=60 -r 30 -b:v 400k -vf scale=426:240 -f ssegment -map 0 -segment_time 100 -initial_offset 100 output%03d.ts

%mv output000.ts output.ts

In that line, I request a start time of 100s, but the start time which is actually put into the file is a few seconds off from that. When I attempt to play the video from the playlist, these start time errors result in discontinuities, so the video jumps and/or hangs.

I recognise that the above is rather convoluted, so I've tried to simplify the problem for this bug report. Exactly the same problem (the start time of a .ts file being offset) happens when we just do a simple 'ffmpeg -i input output.ts', which is why I provided this example.

comment:5 Changed 5 years ago by michael

  • Resolution set to invalid
  • Status changed from new to closed

you need -mpegts_copyts 1 to avoid this offset.
that still leaves a few milliseconds of offset though, if thats a problem for your use case please reopen this ticket

comment:6 Changed 4 years ago by needkane

Can you provide your input file

Note: See TracTickets for help on using tickets.