Force target DTS == source DTS -- How?
Question: How can I force the target's DTS to be the source's DTS? I'm simply demuxing and remuxing. To make the targets: set FORCE=-bsf:v setts=dts=DTS:pts=PTS set SOURCE=h:\BDMV\STREAM\00305.m2ts : IS: 0, 1044806, 1048560, 3753, 640646, 0x900a1a7a, S=1, 1 ffmpeg -to 39.122 -i %SOURCE% -map 0 -c copy -sn -dn c:\target_1.m2ts : RESULT: 0, 126000, 129754, 3753, 640646, 0x900a1a7a, S=1, 1 ffmpeg -to 39.122 -i %SOURCE% -map 0 %FORCE% -c copy -sn -dn c:\target_2.m2ts : RESULT: 0, 126000, 129754, 3753, 640646, 0x900a1a7a, S=1, 1 Thanks, Mark.
On Wed, Jan 10, 2024 at 12:50 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
Question: How can I force the target's DTS to be the source's DTS?
Add "-copyts" to the front of the command-line as a global option. The ffmpeg application will automatically rebase timestamps to zero after demuxing unless you specify this option (which is further up the pipeline than your bsf, hence the bsf has no effect). Devin -- Devin Heitmueller, Senior Software Engineer LTN Global Communications o: +1 (301) 363-1001 w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com
On 1/10/24 13:21, Devin Heitmueller wrote:
On Wed, Jan 10, 2024 at 12:50 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
Question: How can I force the target's DTS to be the source's DTS?
Add "-copyts" to the front of the command-line as a global option. The ffmpeg application will automatically rebase timestamps to zero after demuxing unless you specify this option (which is further up the pipeline than your bsf, hence the bsf has no effect).
Devin
Thanks, Devin, but nope, they're a lot closer but they're still not the same. set FORCE=-bsf:v setts=dts=DTS:pts=PTS set SOURCE=h:\BDMV\STREAM\00305.m2ts : IS: 0, 1044806, 1048560, 3753, 640646, 0x900a1a7a, S=1, 1 ffmpeg -to 39.122 -i %SOURCE% -map 0 -copyts %FORCE% -c copy -sn -dn c:\target_2.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1 ffmpeg -to 39.122 -i %SOURCE% -map 0 -copyts -c copy -sn -dn c:\target_1.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
Correction... On 1/10/24 13:21, Devin Heitmueller wrote:
On Wed, Jan 10, 2024 at 12:50 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
Question: How can I force the target's DTS to be the source's DTS?
Add "-copyts" to the front of the command-line as a global option. The ffmpeg application will automatically rebase timestamps to zero after demuxing unless you specify this option (which is further up the pipeline than your bsf, hence the bsf has no effect).
Devin
Thanks, Devin, but nope, they're a lot closer but they're still not the same. set FORCE=-bsf:v setts=dts=DTS:pts=PTS set SOURCE=h:\BDMV\STREAM\00305.m2ts : IS: 0, 1044806, 1048560, 3753, 640646, 0x900a1a7a, S=1, 1 ffmpeg -to 39.122 -copyts -i %SOURCE% -map 0 %FORCE% -c copy -sn -dn c:\target_2.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1 ffmpeg -to 39.122 -copyts -i %SOURCE% -map 0 -c copy -sn -dn c:\target_1.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1 Sorry I flubbed the command lines. These are correct.
On Wed, Jan 10, 2024 at 1:42 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
Correction...
On 1/10/24 13:21, Devin Heitmueller wrote:
On Wed, Jan 10, 2024 at 12:50 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
Question: How can I force the target's DTS to be the source's DTS?
Add "-copyts" to the front of the command-line as a global option. The ffmpeg application will automatically rebase timestamps to zero after demuxing unless you specify this option (which is further up the pipeline than your bsf, hence the bsf has no effect).
Devin
Thanks, Devin, but nope, they're a lot closer but they're still not the same.
set FORCE=-bsf:v setts=dts=DTS:pts=PTS set SOURCE=h:\BDMV\STREAM\00305.m2ts : IS: 0, 1044806, 1048560, 3753, 640646, 0x900a1a7a, S=1, 1
ffmpeg -to 39.122 -copyts -i %SOURCE% -map 0 %FORCE% -c copy -sn -dn c:\target_2.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
ffmpeg -to 39.122 -copyts -i %SOURCE% -map 0 -c copy -sn -dn c:\target_1.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
Sorry I flubbed the command lines. These are correct.
While I'm not sure why you're not getting the expected output, you can add "-debug_ts" to your ffmpeg command line as a global option and it will show the timestamps for the packets at every stage (i.e. demux/rebasing/decoding/encoding/muxing). That should allow you to track down where in the pipeline the timestamp is changing. Devin -- Devin Heitmueller, Senior Software Engineer LTN Global Communications o: +1 (301) 363-1001 w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com
On 1/10/24 13:55, Devin Heitmueller wrote:
On Wed, Jan 10, 2024 at 1:42 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
Thanks, Devin, but nope, they're a lot closer but they're still not the same.
set FORCE=-bsf:v setts=dts=DTS:pts=PTS set SOURCE=h:\BDMV\STREAM\00305.m2ts : IS: 0, 1044806, 1048560, 3753, 640646, 0x900a1a7a, S=1, 1
ffmpeg -to 39.122 -copyts -i %SOURCE% -map 0 %FORCE% -c copy -sn -dn c:\target_2.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
ffmpeg -to 39.122 -copyts -i %SOURCE% -map 0 -c copy -sn -dn c:\target_1.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
While I'm not sure why you're not getting the expected output, you can add "-debug_ts" to your ffmpeg command line as a global option and it will show the timestamps for the packets at every stage (i.e. demux/rebasing/decoding/encoding/muxing). That should allow you to track down where in the pipeline the timestamp is changing.
I have some beautified debug to paste in here, but first I need to say that here is where the packet CRCs are really needed. Too bad they're not listed by '-debug_ts'. Here is the first video packet: type pkt_pts pkt_dts duration [vist#0:0/h264...] demuxer video 1048560 1044806 3753 [vist#0:0/h264...] demuxer+tsfixup video 1048560 1044806 3753 demuxer+ffmpeg video 1048560 1044806 3753 off:0 [aost#0:1/copy...] muxer <- audio pkt_pts:1048560 pkt_dts:1048560 duration:960 size:1084 As shown in my previous post, PTS=1048560 is being changed to PTS=1174560 Confirmed: 1048560 is the lowest PTS. Confirmed: 1174560 doesn't appear anywhere. So, the change from 1048560 to 1174560 remains mysterious.
On 1/10/24 15:46, Mark Filipak wrote:
On 1/10/24 13:55, Devin Heitmueller wrote:
On Wed, Jan 10, 2024 at 1:42 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
Thanks, Devin, but nope, they're a lot closer but they're still not the same.
set FORCE=-bsf:v setts=dts=DTS:pts=PTS set SOURCE=h:\BDMV\STREAM\00305.m2ts : IS: 0, 1044806, 1048560, 3753, 640646, 0x900a1a7a, S=1, 1
ffmpeg -to 39.122 -copyts -i %SOURCE% -map 0 %FORCE% -c copy -sn -dn c:\target_2.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
ffmpeg -to 39.122 -copyts -i %SOURCE% -map 0 -c copy -sn -dn c:\target_1.m2ts : RESULT: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
While I'm not sure why you're not getting the expected output, you can add "-debug_ts" to your ffmpeg command line as a global option and it will show the timestamps for the packets at every stage (i.e. demux/rebasing/decoding/encoding/muxing). That should allow you to track down where in the pipeline the timestamp is changing.
I have some beautified debug to paste in here, but first I need to say that here is where the packet CRCs are really needed. Too bad they're not listed by '-debug_ts'.
Here is the first video packet: type pkt_pts pkt_dts duration [vist#0:0/h264...] demuxer video 1048560 1044806 3753 [vist#0:0/h264...] demuxer+tsfixup video 1048560 1044806 3753 demuxer+ffmpeg video 1048560 1044806 3753 off:0 [aost#0:1/copy...] muxer <- audio pkt_pts:1048560 pkt_dts:1048560 duration:960 size:1084
As shown in my previous post, PTS=1048560 is being changed to PTS=1174560
Confirmed: 1048560 is the lowest PTS. Confirmed: 1174560 doesn't appear anywhere.
So, the change from 1048560 to 1174560 remains mysterious.
The change from 1048560 to 1174560 has to be happening inside the muxer, wouldn't you say? We now know that what's going into the muxer is right. Here is what went to the target file in the last run: 0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
On Wed, Jan 10, 2024 at 4:26 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
The change from 1048560 to 1174560 has to be happening inside the muxer, wouldn't you say? We now know that what's going into the muxer is right. Here is what went to the target file in the last run:
0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
Try setting -muxdelay 0 on the output options. If not specified it defaults to 0.7, and the delta between 1174560 and 1048560 is exactly 1.4 seconds. I don't know why you're getting exactly 2x the mux delay rather than just being off by 0.7s, but I suspect it's the muxdelay that is causing you to get PTS values which are not what you would expect. Devin -- Devin Heitmueller, Senior Software Engineer LTN Global Communications o: +1 (301) 363-1001 w: https://ltnglobal.com e: devin.heitmueller@ltnglobal.com
On 1/10/24 16:50, Devin Heitmueller wrote:
On Wed, Jan 10, 2024 at 4:26 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
The change from 1048560 to 1174560 has to be happening inside the muxer, wouldn't you say? We now know that what's going into the muxer is right. Here is what went to the target file in the last run:
0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
Try setting -muxdelay 0 on the output options. If not specified it defaults to 0.7, and the delta between 1174560 and 1048560 is exactly 1.4 seconds. I don't know why you're getting exactly 2x the mux delay rather than just being off by 0.7s, but I suspect it's the muxdelay that is causing you to get PTS values which are not what you would expect.
Devon, you're a lifesaver. That did it. Look: 0, 1044806, 1048560, 3753, 640646, 0x900a1a7a, S=1, 1 So, to summarize, I needed '-copyts' before '-i' and '-muxdelay 0' after '-i'. Is there any reason I should _not_ make those permanent and do them every time? Thanks so much for your help. I could _never_ have done that on my own. Now that there's fewer moving parts, I can maybe make more progress in my main task: Towards better trims & concatenations. But first, I have about 30 work files to delete. -- Mark.
On 1/10/24 16:50, Devin Heitmueller wrote:
On Wed, Jan 10, 2024 at 4:26 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
The change from 1048560 to 1174560 has to be happening inside the muxer, wouldn't you say? We now know that what's going into the muxer is right. Here is what went to the target file in the last run:
0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
Try setting -muxdelay 0 on the output options. If not specified it defaults to 0.7, and the delta between 1174560 and 1048560 is exactly 1.4 seconds. I don't know why you're getting exactly 2x the mux delay rather than just being off by 0.7s, but I suspect it's the muxdelay that is causing you to get PTS values which are not what you would expect.
Devin
When I wrote "That did it", I 'spoke' too soon. I'm still being driven nuts. There are 4 questions at the end. -- Mark. set TRIM=-ss 20.061708333 -to 40.123416666 set SOURCE=h:\BDMV\STREAM\00305.m2ts set CODE=-c copy -sn -dn set TARGET=c:\FANNY AND ALEXANDER [1982(1983)] 1of4.mp4 ffmpeg -report %TRIM% -copyts -i %SOURCE% -map 0 %CODE% -muxdelay 0 "%TARGET%" (The report is attached.) ___ THE INPUT M2TS (the cut is PTS=2854113) : 0, 2839098, 2839098, 3753, 25719, 0x6f77b9b6 1, 2839920, 2839920, 960, 1084, 0xe54d2b6f 1, 2840880, 2840880, 960, 1084, 0xe54d2b6f 1, 2841840, 2841840, 960, 1084, 0xe54d2b6f 1, 2842800, 2842800, 960, 1084, 0xe54d2b6f 0, 2842852, 2842852, 3753, 22455, 0xaa9655b8 1, 2843760, 2843760, 960, 1084, 0xe54d2b6f 1, 2844720, 2844720, 960, 1084, 0xe54d2b6f 1, 2845680, 2845680, 960, 1084, 0xe54d2b6f -cut- +---------+ 0, 2846606, ¦ 2854113 ¦ 3753, 640646, 0x3a5a0c45 1, 2846640, +---------+ 960, 1084, 0xe54d2b6f 1, 2847600, 2847600, 960, 1084, 0xe54d2b6f 1, 2848560, 2848560, 960, 1084, 0xe54d2b6f 1, 2849520, +---------+ 960, 1084, 0xe54d2b6f 0, 2850360, ¦ 2850360 ¦ 3753, 640646, 0xfed1d09a <= TO BE CUT 1, 2850480, +---------+ 960, 1084, 0xe54d2b6f 1, 2851440, 2851440, 960, 1084, 0xe54d2b6f 1, 2852400, 2852400, 960, 1084, 0xe54d2b6f 1, 2853360, 2853360, 960, 1084, 0xe54d2b6f 0, 2854113, 2861621, 3753, 640646, 0x02208727 : ___ THE OUTPUT MP4 (the cut is PTS=2854080) 1, 1492608, 1492608, 512, 60, 0xec16103f : 50 audio packets, total 1, 1517696, 1517696, 512, 1084, 0xe54d2b6f -cut- +---------+ 0, 2846573, ¦ 2854080 ¦ 3753, 640654, 0xb9811068 1, 1518208, +---------+ 512, 1084, 0xe54d2b6f 1, 1518720, 1518720, 512, 1084, 0xe54d2b6f 1, 1519232, 1519232, 512, 1084, 0xe54d2b6f 1, 1519744, +---------+ 512, 1084, 0xe54d2b6f 0, 2850327, ¦ 2850327 ¦ 3753, 640652, 0xbf9ad2d1 <= NOT CUT 1, 1520256, +---------+ 512, 1084, 0xe54d2b6f 1, 1520768, 1520768, 512, 1084, 0xe54d2b6f 1, 1521280, 1521280, 512, 1084, 0xe54d2b6f 1, 1521792, 1521792, 512, 1084, 0xe54d2b6f 0, 2854080, 2861588, 3753, 640652, 0x8f98895e : Q1: How can I force the mp4 muxer to use the existing PTSs? Q2: Why are there 50 audio packets ahead of the -cut-? Q3: How can I force the mp4 audio time_base to 1/90000? Q4: Why wasn't INPUT PTS=2850360 cut off?
пт, 12 янв. 2024 г., 05:18 Mark Filipak <markfilipak.imdb@gmail.com>:
On Wed, Jan 10, 2024 at 4:26 PM Mark Filipak <markfilipak.imdb@gmail.com> wrote:
The change from 1048560 to 1174560 has to be happening inside the muxer, wouldn't you say? We now know that what's going into the muxer is right. Here is what went to
On 1/10/24 16:50, Devin Heitmueller wrote: the target file in the last run:
0, 1170806, 1174560, 3753, 640646, 0x900a1a7a, S=1, 1
Try setting -muxdelay 0 on the output options. If not specified it defaults to 0.7, and the delta between 1174560 and 1048560 is exactly 1.4 seconds. I don't know why you're getting exactly 2x the mux delay rather than just being off by 0.7s, but I suspect it's the muxdelay that is causing you to get PTS values which are not what you would expect.
Devin
When I wrote "That did it", I 'spoke' too soon. I'm still being driven nuts. There are 4 questions at the end. -- Mark.
set TRIM=-ss 20.061708333 -to 40.123416666 set SOURCE=h:\BDMV\STREAM\00305.m2ts set CODE=-c copy -sn -dn set TARGET=c:\FANNY AND ALEXANDER [1982(1983)] 1of4.mp4 ffmpeg -report %TRIM% -copyts -i %SOURCE% -map 0 %CODE% -muxdelay 0 "%TARGET%" (The report is attached.)
___ THE INPUT M2TS (the cut is PTS=2854113) : 0, 2839098, 2839098, 3753, 25719, 0x6f77b9b6 1, 2839920, 2839920, 960, 1084, 0xe54d2b6f 1, 2840880, 2840880, 960, 1084, 0xe54d2b6f 1, 2841840, 2841840, 960, 1084, 0xe54d2b6f 1, 2842800, 2842800, 960, 1084, 0xe54d2b6f 0, 2842852, 2842852, 3753, 22455, 0xaa9655b8 1, 2843760, 2843760, 960, 1084, 0xe54d2b6f 1, 2844720, 2844720, 960, 1084, 0xe54d2b6f 1, 2845680, 2845680, 960, 1084, 0xe54d2b6f -cut- +---------+ 0, 2846606, ¦ 2854113 ¦ 3753, 640646, 0x3a5a0c45 1, 2846640, +---------+ 960, 1084, 0xe54d2b6f 1, 2847600, 2847600, 960, 1084, 0xe54d2b6f 1, 2848560, 2848560, 960, 1084, 0xe54d2b6f 1, 2849520, +---------+ 960, 1084, 0xe54d2b6f 0, 2850360, ¦ 2850360 ¦ 3753, 640646, 0xfed1d09a <= TO BE CUT 1, 2850480, +---------+ 960, 1084, 0xe54d2b6f 1, 2851440, 2851440, 960, 1084, 0xe54d2b6f 1, 2852400, 2852400, 960, 1084, 0xe54d2b6f 1, 2853360, 2853360, 960, 1084, 0xe54d2b6f 0, 2854113, 2861621, 3753, 640646, 0x02208727 :
___ THE OUTPUT MP4 (the cut is PTS=2854080) 1, 1492608, 1492608, 512, 60, 0xec16103f : 50 audio packets, total 1, 1517696, 1517696, 512, 1084, 0xe54d2b6f -cut- +---------+ 0, 2846573, ¦ 2854080 ¦ 3753, 640654, 0xb9811068 1, 1518208, +---------+ 512, 1084, 0xe54d2b6f 1, 1518720, 1518720, 512, 1084, 0xe54d2b6f 1, 1519232, 1519232, 512, 1084, 0xe54d2b6f 1, 1519744, +---------+ 512, 1084, 0xe54d2b6f 0, 2850327, ¦ 2850327 ¦ 3753, 640652, 0xbf9ad2d1 <= NOT CUT 1, 1520256, +---------+ 512, 1084, 0xe54d2b6f 1, 1520768, 1520768, 512, 1084, 0xe54d2b6f 1, 1521280, 1521280, 512, 1084, 0xe54d2b6f 1, 1521792, 1521792, 512, 1084, 0xe54d2b6f 0, 2854080, 2861588, 3753, 640652, 0x8f98895e :
Q1: How can I force the mp4 muxer to use the existing PTSs? Q2: Why are there 50 audio packets ahead of the -cut-? Q3: How can I force the mp4 audio time_base to 1/90000?
https://git.ffmpeg.org/gitweb/ffmpeg.git/blob/HEAD:/libavformat/movenc.c (oh, it grow to 300 kb?) there are options "movie_timescale", "set movie timescale" and video_track_timescale", "set timescale of all video tracks" AND "pts", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = MOV_PRFT_SRC_PTS}, 0, 0, AV_OPT_FLAG_ENCODING_PARAM, "prft"}, but you probably need to consult documentation on how exactly they used https://ffmpeg.org/ffmpeg-formats.html#Options-4 but if you have some time it will be interesting to hear if script I found on videohelp forums for testing open-gop/closed gop situations shows something interesting for your source file? Somewhere at second level someone said that blurays specifically not mandate closed-gop video streams, and only demand full decoder refres (IDR frame) at chapter marks. I wonder if your m2ts stream encoded like this ? How exactly you determinated keyframe to cut at, initially? Q4: Why wasn't INPUT PTS=2850360 cut off?
_______________________________________________ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user
To unsubscribe, visit link above, or email ffmpeg-user-request@ffmpeg.org with subject "unsubscribe".
participants (3)
-
Andrew Randrianasulu -
Devin Heitmueller -
Mark Filipak