Transcoding MPEG .ts results in slow playback speed

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Transcoding MPEG .ts results in slow playback speed

Peter B.
Hi everyone :)

I have a tricky source video:
====================
It's an MPEG TS file, that regardless of what I try to transcode it to,
the resulting file has its duration doubled.
The resulting file plays back to slow (at only half the normal speed).


I've tried transcoding to FFV1, and Huffyuv: Same behavior - so I
presume it's the source.
The exact details of how the source was created are not known, but I'm
pretty sure it was done using some "regular" tool designed for home
video editing. No "AV-nerd" or expert involved.

Mediainfo says 25fps for the source, but when I transcode it to e.g.
FFV1, Mediainfo shows no value for framerate at all and says it's
variable framerate. Whereas VLC or ffprobe say it's 25fps... Seems odd.
If I rewrap to MKV in an extra step before, and then transcode (using
same command!), timing seems to be fine.


Any ideas what's happening here, and how to skip that extra rewrapping step?

Thank you very much in advance for any ideas/help :)
Peter B.



I've created a sample (with "dd") of the first few MB to recreate the issue:
http://download.das-werkstatt.com/pb/contribs/files/bad_timing-MPEGTS.tar.bz2

Commandline and complete, uncut console output here:


Original Transcode (produces wrong timing in target):
// -----------------------------------
$ ffmpeg-git -i bad_timing.ts -c:v ffv1 -c:a copy out/too_slow.mkv
// -----------------------------------
ffmpeg version N-93022-g260f196 Copyright (c) 2000-2019 the FFmpeg
developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree
--enable-version3 --enable-postproc --enable-ffplay --enable-swscale
--enable-avfilter --enable-pthreads --enable-bzlib --enable-zlib
--enable-decoder=png --enable-encoder=png --samples=../fate-suite
--enable-libfreetype --enable-libopenjpeg --disable-decoder=jpeg2000
--enable-libvpx --enable-libvorbis --enable-libx264 --enable-libx265
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 44.100 / 58. 44.100
  libavformat    58. 26.100 / 58. 26.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mpegts, from 'bad_timing.ts':
  Duration: 00:00:07.28, start: 0.000000, bitrate: 9114 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] /
0x0002), yuv420p(tv, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps,
25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> ffv1 (native))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
Output #0, matroska, to 'out/too_slow.mkv':
  Metadata:
    encoder         : Lavf58.26.100
    Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 1920x1080
[SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 1k tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.44.100 ffv1
    Stream #0:1: Audio: mp2 (P[0][0][0] / 0x0050), 48000 Hz, stereo,
fltp, 256 kb/s
[mpeg2video @ 0x381e3c0] ac-tex damaged at 114 400:00:12.68
bitrate=10608.3kbits/s speed=8.32x   
[mpeg2video @ 0x381e3c0] Warning MVs not available
[mpeg2video @ 0x381e3c0] concealing 3296 DC, 3296 AC, 3296 MV errors in
P frame
frame=  182 fps= 88 q=-0.0 Lsize=   36255kB time=00:00:14.36
bitrate=20681.3kbits/s speed=6.98x   
video:36024kB audio:226kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.013793%



Rewrapping intermediate step:
// --------------------------------
$ ffmpeg-git -i bad_timing.ts -c copy rewrap.mkv
// --------------------------------

ffmpeg version N-93022-g260f196 Copyright (c) 2000-2019 the FFmpeg
developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree
--enable-version3 --enable-postproc --enable-ffplay --enable-swscale
--enable-avfilter --enable-pthreads --enable-bzlib --enable-zlib
--enable-decoder=png --enable-encoder=png --samples=../fate-suite
--enable-libfreetype --enable-libopenjpeg --disable-decoder=jpeg2000
--enable-libvpx --enable-libvorbis --enable-libx264 --enable-libx265
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 44.100 / 58. 44.100
  libavformat    58. 26.100 / 58. 26.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mpegts, from 'bad_timing.ts':
  Duration: 00:00:07.28, start: 0.000000, bitrate: 9114 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: mpeg2video (Main) ([2][0][0][0] /
0x0002), yuv420p(tv, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps,
25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz,
stereo, fltp, 256 kb/s
Output #0, matroska, to 'rewrap.mkv':
  Metadata:
    encoder         : Lavf58.26.100
    Stream #0:0: Video: mpeg2video (Main) (mpg2 / 0x3267706D),
yuv420p(tv, top first), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 25
tbr, 1k tbn, 90k tbc
    Stream #0:1: Audio: mp2 (P[0][0][0] / 0x0050), 48000 Hz, stereo,
fltp, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=  182 fps=0.0 q=-1.0 Lsize=    7891kB time=00:00:07.22
bitrate=8948.3kbits/s speed= 159x   
video:7660kB audio:226kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.061223%



Transcoding from intermediate, rewrapped MKV (produces correct timing):
// --------------------------------
$ ffmpeg-git -i rewrap.mkv -c:v ffv1 -c:a copy out/rewrap.mkv
// --------------------------------
ffmpeg version N-93022-g260f196 Copyright (c) 2000-2019 the FFmpeg
developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
  configuration: --prefix=/usr/local --enable-gpl --enable-nonfree
--enable-version3 --enable-postproc --enable-ffplay --enable-swscale
--enable-avfilter --enable-pthreads --enable-bzlib --enable-zlib
--enable-decoder=png --enable-encoder=png --samples=../fate-suite
--enable-libfreetype --enable-libopenjpeg --disable-decoder=jpeg2000
--enable-libvpx --enable-libvorbis --enable-libx264 --enable-libx265
  libavutil      56. 26.100 / 56. 26.100
  libavcodec     58. 44.100 / 58. 44.100
  libavformat    58. 26.100 / 58. 26.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 48.100 /  7. 48.100
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, matroska,webm, from 'rewrap.mkv':
  Metadata:
    ENCODER         : Lavf58.26.100
  Duration: 00:00:07.28, start: 0.000000, bitrate: 8879 kb/s
    Stream #0:0: Video: mpeg2video (Main), yuv420p(tv, top first),
1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc (default)
    Metadata:
      DURATION        : 00:00:07.280000000
    Stream #0:1: Audio: mp2, 48000 Hz, stereo, s16p, 256 kb/s (default)
    Metadata:
      DURATION        : 00:00:07.248000000
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> ffv1 (native))
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
Output #0, matroska, to 'out/rewrap.mkv':
  Metadata:
    encoder         : Lavf58.26.100
    Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), yuv420p, 1920x1080
[SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 1k tbn, 25 tbc (default)
    Metadata:
      DURATION        : 00:00:07.280000000
      encoder         : Lavc58.44.100 ffv1
    Stream #0:1: Audio: mp2 (P[0][0][0] / 0x0050), 48000 Hz, stereo,
s16p, 256 kb/s (default)
    Metadata:
      DURATION        : 00:00:07.248000000
[mpeg2video @ 0x3dea640] ac-tex damaged at 114 400:00:06.52 bitrate=  
1.1kbits/s speed=4.25x   
[mpeg2video @ 0x3dea640] Warning MVs not available
[mpeg2video @ 0x3dea640] concealing 3296 DC, 3296 AC, 3296 MV errors in
P frame
frame=  182 fps= 92 q=-0.0 Lsize=   36255kB time=00:00:07.24
bitrate=41017.0kbits/s speed=3.66x   
video:36024kB audio:226kB subtitle:0kB other streams:0kB global
headers:0kB muxing overhead: 0.013798%
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Transcoding MPEG .ts results in slow playback speed

Carl Eugen Hoyos-2
2019-01-25 16:16 GMT+01:00, Peter B. <[hidden email]>:
> I've created a sample (with "dd") of the first few MB to recreate the issue:
> http://download.das-werkstatt.com/pb/contribs/files/bad_timing-MPEGTS.tar.bz2

(Please do not compress compressed files and no, I don't think
an md5 sum is necessary in this case, if it is necessary you can
put it in your email)

How did you create this file?
The file looks as if you used FFmpeg to cut instead of dd...

If this is the original file, it is most likely broken but I must say
it could be interesting to find out what happened...
(The file was created with FFmpeg.)

You can "fix" it by forcing the input frame rate to "25" but this
often has unintended side-effects (like desync), setpts should
have the same effect but may be more difficult to tune.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Transcoding MPEG .ts results in slow playback speed

Peter B.
Hi Carl Eugen :)


On 25/01/2019 20:12, Carl Eugen Hoyos wrote:
> (Please do not compress compressed files and no, I don't think
> an md5 sum is necessary in this case, if it is necessary you can
> put it in your email)

You're absolutely right of course.

I usually don't compress compress files (no size gain), but I wanted to
provide a hashcode.
And since I usually leave the samples on my server "forever" I thought a
package might be convenient to keep it tidier (though tar would have
sufficed).


Anyways:
> How did you create this file?
> The file looks as if you used FFmpeg to cut instead of dd...

Not this time :D
We spoke about this last time, so I used dd:

$ dd if=ORIGINAL.ts of=short.ts bs=1k count=8100


> If this is the original file, it is most likely broken but I must say
> it could be interesting to find out what happened...

I'm also curious.
Unfortunately, this file was provided by some private individual to the
archive, so this part of the story is unknown.
But I'll try to find out, as I'm curious how files like these are
created with "regular" workflows :P


> (The file was created with FFmpeg.)

I saw that in the metadata, too:
"service_provider: FFmpeg"
And was surprised, because I'm pretty sure they created it using a GUI.


> You can "fix" it by forcing the input frame rate to "25" but this
> often has unintended side-effects (like desync), setpts should
> have the same effect but may be more difficult to tune.

Interesting!

Works with added "-r 25" before "-i":
$ ffmpeg-git -r 25 -i ORIGINAL.ts -c:v ffv1 -c:a copy out/test-fps25.avi

But how come it requires the 25fps information, when ffprobe, mediainfo
and VLC all say that the source already has 25fps set anyways?

I'm currently reading the docs [1] for setpts... :D


Thanks so far for all your answers,
Peter


== References:
[1] https://ffmpeg.org/ffmpeg-filters.html#setpts_002c-asetpts
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: Transcoding MPEG .ts results in slow playback speed

Carl Eugen Hoyos-2
2019-01-28 8:39 GMT+01:00, Peter B. <[hidden email]>:

> Works with added "-r 25" before "-i":
> $ ffmpeg-git -r 25 -i ORIGINAL.ts -c:v ffv1 -c:a copy out/test-fps25.avi
>
> But how come it requires the 25fps information

Afaict, because the file has broken timestamps.

The most important question would be how it was created...

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".