4

I understand that it is impossible to edit metadata of MPG files (i.e. createdate), so I am looking for another way to "upgrade" my MPGs into a newer file format (preferred are formats that work both on Windows and iOS).

What should I do to achieve this goal? Remux/encode/convert my MPG videos into MP4 or MOV and what settings should be used in remuxing/encoding/converting the files? Which action would produce the best result; as close as possible to the original MPG videos?

Here is the mediainfo specification of one of my MPG files:

General
Complete name : E:\Users\Owner\Desktop\test\MOV03521.MPG
Format : MPEG-PS
File size : 25.1 MiB
Duration : 20s 124ms
Overall bit rate mode : Variable
Overall bit rate : 10.5 Mbps

Video
ID : 224 (0xE0)
Format : MPEG Video
Format version : Version 1
Format settings, BVOP : No
Format settings, Matrix : Default
Format settings, GOP : N=1
Duration : 20s 100ms
Bit rate mode : Variable
Bit rate : 10.2 Mbps
Width : 640 pixels
Height : 480 pixels
Display aspect ratio : 4:3
Frame rate : 30.000 fps
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
Scan type : Progressive
Compression mode : Lossy
Bits/(Pixel*Frame) : 1.105
Time code of first frame : 00:00:00:00
Time code source : Group of pictures header
GOP, Open/Closed : Closed
Stream size : 24.4 MiB (97%)

Audio
ID : 192 (0xC0)
Format : MPEG Audio
Format version : Version 1
Format profile : Layer 2
Duration : 20s 124ms
Bit rate mode : Constant
Bit rate : 64.0 Kbps
Channel(s) : 1 channel
Sampling rate : 32.0 KHz
Compression mode : Lossy
Stream size : 157 KiB (1%) 
3
  • 1
    MPEG-1 video? That seems rather old. But what is the reason you want to convert them? Editing metadata should even be possible with MPEG-PS containers. Converting to MP4/MOV would reduce the quality or at least take up a bit of space (that's the tradeoff here). Or do you want compatibility with iOS (which I assume does not handle MPEG-1)?
    – slhck
    Jan 11, 2015 at 15:09
  • All I want is to add a "createdate" tag inside of my files, as otherwise they do not show up correctly in my Carousel by Dropbox timeline. I tried editing my MPG movie with EXIFTOOL and it did not work. It works with many different formats but not with MPG. I do not want to convert my files, I just want to have the time tag associated with my MPG files (which are actually camera videos). Conversion has resulted in loss of quality on my iOS devices. I don't know what to do and that's why I am seeking advice from the experts.
    – zarko
    Jan 11, 2015 at 16:52
  • Ah, please ignore the "editing metadata should be possible". That's of course not always true. See my answer below. Let me know if you need help getting ffmpeg to run from a command line, or getting some other video conversion tool to do the job for you.
    – slhck
    Jan 11, 2015 at 17:10

2 Answers 2

5

Creation date (like many other metadata fields) is a property you can set for MP4/MOV and MKV containers (as well as several others), but not for MPEG Program Streams or Transport Streams. In fact, there's no standard for video metadata like there's EXIF for photos. And when they designed MPEG containers they probably just didn't think about this application (yet).

You have to be aware of the fact that MPEG-1 is very old—they started developing it when I was born—and you would probably be better off converting the videos to a more recent and compression-efficient codec like H.264. Your 10 MBit/s MPEG-1 video will probably end up looking just as good at 1 MBit/s H.264, or even less than that.

So if the real issue is that the videos need to show up in the correct order in a file manager of some sort, and you cannot change the file manager or use a metadata platform, you need to re-mux or re-encode the videos.

Re-muxing will not touch the video/audio bitstream, thus keeping the file size and quality intact. With ffmpeg, you could try the following:

ffmpeg -i input.mpeg -c copy output.mkv

This may work or may not. It didn't when I tried, but in theory Matroska supports MPEG-1 video. Matroska is not natively supported on Windows or iOS though.

So, you can re-encode the video and audio to H.264/AAC in an MP4 container:

ffmpeg -i input.mpeg -c:v libx264 -preset slow -crf 18 -c:a aac -strict experimental -b:a 128k output.mp4

Here, the CRF option sets the quality. 18 means very good. 23 is the default. Lower means better, so if you want to retain quality, you might even want to go below 18. A CRF of ±6 results in about half/double the file size. The H.264 encoding guide is very helpful. Note that your resulting file may be smaller than the input file but will still look just as good. That's because the codec is much more efficient. I recommend you vary the CRF until you find the value where you cannot perceive a difference anymore between the original and the re-encoded one.

H.264/AAC in MP4 is supported on (newer) Windows and iOS. Older Windows versions (that includes Windows 7 IIRC) will not play it unless a codec pack is installed. For iOS compatibility on older devices, you may have to set -profile:v baseline as an option.

After converting to MKV or MP4, setting metadata such as creation date will be possible.

14
  • Thanks slhck! Well explained and easy to follow. If I have three MPGs that I would like to re-encode separately, do I need to re-encode them one by one or is there a smarter way? My files are: MOV03521.mpg, MOV03552.mpg, MOV03553.mpg and I would like to re-encode them to the same-named files with Mp4 extension. Do you know if it can be done and by what command/program?
    – zarko
    Jan 16, 2015 at 0:26
  • Depends on your operating system! I'm a fan of command line scripts, so either Windows batch files or Linux scripts. See here for some code examples: superuser.com/a/440639/48078
    – slhck
    Jan 16, 2015 at 7:55
  • Thanks - I am giving it a try :-) I am on Win8. Startconvert.bat will include this: for %%i IN (*.mpg) DO (convert-to-mp4.bat "%%i") pause Convert-to-mp4.bat will include this: IF EXIST "%1.mp4" GOTO exit echo Conversion for %1 started on %DATE% %TIME% ffmpeg -i %1 -c:v libx264 -preset slow -crf 18 -c:a aac -strict experimental -b:a 128k %1.mp4 :exit echo %1.mp4 already exists
    – zarko
    Jan 16, 2015 at 17:26
  • (the above comment lacks @ in front of echo) - it is easier to read here: pastebin.com/zy4FcbM2
    – zarko
    Jan 16, 2015 at 17:33
  • Could you please see if I correctly applied your command in the convert-to-mp4.bat (ffmpeg -i %1 -c:v libx264 -preset slow -crf 18 -c:a aac -strict experimental -b:a 128k %1.mp4)
    – zarko
    Jan 16, 2015 at 17:35
0

I successfully used exiftool for this. Here is the metadata of an MPG file before correction:

C:\>exiftool.exe -s test.mp4

ExifToolVersion                 : 10.01
FileName                        : test.mp4
Directory                       : .
FileSize                        : 14 MB
FileModifyDate                  : 2015:09:04 22:33:16+05:00
FileAccessDate                  : 2015:09:05 14:10:08+05:00
FileCreateDate                  : 2015:09:05 14:10:08+05:00
FilePermissions                 : rw-rw-rw-
FileType                        : MP4
FileTypeExtension               : mp4
MIMEType                        : video/mp4
MajorBrand                      : MP4  Base Media v1 [IS0 14496-12:2003]
MinorVersion                    : 0.2.0
CompatibleBrands                : isom, iso2, avc1, mp41
MovieHeaderVersion              : 0
CreateDate                      : 0000:00:00 00:00:00
ModifyDate                      : 0000:00:00 00:00:00
TimeScale                       : 1000
Duration                        : 0:01:22
-- snip --
TrackHeaderVersion              : 0
TrackCreateDate                 : 0000:00:00 00:00:00
TrackModifyDate                 : 0000:00:00 00:00:00
-- snip --
MediaHeaderVersion              : 0
MediaCreateDate                 : 0000:00:00 00:00:00
MediaModifyDate                 : 0000:00:00 00:00:00
-- snip --

I used this to change all dates:

C:\>exiftool.exe ^
-Quicktime:CreateDate="2007-01-02 03:04:05" ^
-Quicktime:ModifyDate="2007-01-02 03:04:05" ^
     -TrackCreateDate="2007-01-02 03:04:05" ^
     -TrackModifyDate="2007-01-02 03:04:05" ^
     -MediaCreateDate="2007-01-02 03:04:05" ^
     -MediaModifyDate="2007-01-02 03:04:05" ^
test.mp4

Here is the metadata after correction:

FileModifyDate                  : 2015:09:05 14:20:54+05:00
FileAccessDate                  : 2015:09:05 14:20:54+05:00
FileCreateDate                  : 2015:09:05 14:10:08+05:00
-- snip --
CreateDate                      : 2007:01:02 03:04:05
ModifyDate                      : 2007:01:02 03:04:05
-- snip --
TrackCreateDate                 : 2007:01:02 03:04:05
TrackModifyDate                 : 2007:01:02 03:04:05
-- snip --
MediaCreateDate                 : 2007:01:02 03:04:05
MediaModifyDate                 : 2007:01:02 03:04:05
-- snip --

I would suggest that you first look at metadata of good, known MPG files and note down which date is which. Backup your files before experimenting (exiftool creates a backup by default). In my testing, the size of original and updated files remains exactly the same.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .