View Full Version : Change field-order flag in MPEG-2 program stream?
Trixter
2nd July 2024, 16:23
I have hundreds of MPEG-2 program stream files where, for reasons unknown, the field order flag in the program stream is wrong. This obviously leads to incorrect decoding on software players, showing the fields out of order which results in jittery playback.
Is there a utility or batch process I can use to simply set the field order flag in an MPEG-2 program stream to a specific field order? Linux or Windows is preferred. The goal is to avoid anything interactive, since I'm not going to do hundreds of these interactively.
I'd like to do this without demuxing/remuxing because I'm worried about sync. I have FFMPEG installed, but wasn't able to figure out how to do it with FFMPEG without remuxing.
Trixter
5th August 2024, 00:05
A kind random internet stranger helped me with this, so I thought I'd pay it forward by putting the final solution here for others to find. Their reply follows:
It's not possible in ffmpeg, because the mpeg-2 bitstream filter's limited. Trusty old Restream could do it, but AFAIK there's no batch option:
https://www.videohelp.com/software/Restream
There's a Linux version of DGPulldown that added the option to change the TFF flag.
https://github.com/jaystevens/dgpulldown/tree/master/dgpulldown_linux
Clone the repo, and run the make file.
From the README:
To flag an interlaced m2v file as top field first use the command
dgpulldown input.m2v -interlaced -o output.m2v
to flag an interlaced m2v file as bottom field first use the command
dgpulldown input.m2v -interlaced -bff -o output.m2v
The workflow outlined below works for my test files, which come from my recent experiments with BD-to-DVD conversion on Linux (without using Wine). My concern is that it might not be as successful with the quirks of "real world" files (captures, old recordings, etc) that are not fresh out of the encoder. The new option for dgpulldown caught my eye when building it from source in order to apply soft telecine to some m2v files; it was simply chance that your post on Doom9 caught my eye when researching some MPEG-2 settings.
Demux (to m2v and m2a)
for file in *.mpg; do ffmpeg -i "$file" -map 0:v:0 -c:v copy "${file%.mpg}.m2v" -map 0:a:0 -c:a copy "${file%.mpg}.m2a" ; done
Reflag (each m2v in turn)
# BFF
for file in *.m2v; do dgpulldown "$file" -interlaced -bff -o "${file%.m2v}.mpv"; done
# TFF
for file in *.m2v; do dgpulldown "$file" -interlaced -o "${file%.m2v}.mpv"; done
Remux
Option 1: ffmpeg
for file in *.mpv; do ffmpeg -fflags +genpts -i "${file}" -i "${file//.mpv/.m2a}" -c copy "${file//.mpv/_remux.mpg}"; done
Option2: mplex, which is part of mjpegtools
for file in *.mpv; do mplex -f 8 -o "${file//.mpv/_remux.mpg}" "${file}" "${file//.mpv/.m2a}"; done
Again, this is all in bash. The assumption is that the filename of each input remains constant throughout the process, allowing bash to make a series of substitutions of the file extension (as well as leave the input file in place):
whatever.mpg -> whatever.m2v (& whatever.m2a) -> whatever.mpv -> whatever_remux.mpg
But please back up your files beforehand. :-)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.