[FFmpeg-user] Is there a way to set 'closed_gop' in FFmpeg?

Mark Filipak markfilipak.imdb at gmail.com
Fri Jun 7 03:31:36 EEST 2024


Please recall that I've cut both ends of 2 M2TSes and then joined them. Recall that both M2TSes are 
open GOPs.

Please recall the commands:

ffmpeg -copyts -i "g:\FANNY AND ALEXANDER [1982(1983)]\00305.m2ts" -map 0 -bsf 
noise=drop='lt(pts\,2854113)+gte(dts\,504219978)',setts=dts='if(eq(DTS\,2846606)\,2850360\,DTS)':pts='if(eq(PTS\,504223732)\,504219978\,PTS)' 
-c copy -sn -dn -muxdelay 0 "g:\FANNY AND ALEXANDER [1982(1983)]\00305 cut.m2ts"

ffmpeg -copyts -i "g:\FANNY AND ALEXANDER [1982(1983)]\00306.m2ts" -map 0 -bsf 
noise=drop='lt(pts\,2317327)+gte(dts\,407620976)',setts=dts='if(eq(DTS\,2306066)\,2313573+501906404\,DTS+501906404)':pts='if(eq(PTS\,407620976)\,407613468+501906404\,PTS+501906404)' 
-c copy -sn -dn -muxdelay 0 "g:\FANNY AND ALEXANDER [1982(1983)]\00306 cut.m2ts"

(Recall that using '-ss' & '-to' to make the cuts produces soup for about 5 seconds at the join.)

Recall that the cuts are perfect -- verified via analysis -- and the concatenation is perfect -- 
verified via analysis -- but the join stalls for about 1/2 second.

(Anyone interested can request the M2TSes and my analysis.)

The 1st section's final GOP went from open to closed, and I reckon that the 'closed_gop' MPEG tag 
needs to be set. I reckon that because everything else is so perfect. So, I used a hex editor and 
found that GOP. I intended to set 'closed_gop' to '1'.

Unfortunately, I can parse only VOBs, not M2TSes.

However, I assumed GOP headers hadn't changed too much between DVDs and Blu-rays. Unfortunately, I 
was wrong.

Instead of '00 00 01 B8' followed by 4 bytes ('drop_frame_flag' bit + 'time_code' field + 
'closed_gop' bit + 'broken_link' bit), the '00 00 01 B8' is followed by 426 bytes. Furthermore, the 
1st 4 bytes don't work the same as for VOBs because marker bits that are supposed to be '1' are '0'. 
So, it appears the GOP header for M2TSes is completely different from the GOP header for VOBs.

Does anyone have an M2TS raw parser? Lacking that, does anyone have a map of M2TS so I can parse it 
manually and locate the 'closed_gop' MPEG tag?

Thanks!
--Mark.



More information about the ffmpeg-user mailing list