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%) 
slhck
  • 223,558
  • 70
  • 607
  • 592
zarko
  • 43
  • 1
  • 4
  • 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 '15 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 '15 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 '15 at 17:10

2 Answers2

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.

slhck
  • 223,558
  • 70
  • 607
  • 592
  • 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 '15 at 00: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: http://superuser.com/a/440639/48078 – slhck Jan 16 '15 at 07: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 '15 at 17:26
  • (the above comment lacks @ in front of echo) - it is easier to read here: http://pastebin.com/zy4FcbM2 – zarko Jan 16 '15 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 '15 at 17:35
  • I'm not a Windows expert – so I can't tell you just from seeing it whether it would work for you. Have you tried it? If something about the batch file doesn't work, I recommend you ask a new question, then others can answer it :) – slhck Jan 16 '15 at 19:23
  • The batch file works. What I wanted you to check is whether I replaced the parts of the sample command correctly. Sample command from your post superuser.com/a/440639/48078: ffmpeg -i %1 -c:v copy -c:a copy %1.mp4 in my case: ffmpeg -i %1 -c:v libx264 -preset slow -crf 18 -c:a aac -strict experimental -b:a 128k %1.mp4 – zarko Jan 17 '15 at 11:06
  • Yes, that looks fine to me! – slhck Jan 17 '15 at 15:45
  • Thanks! Last question: Do you know if we could somehow trick the MPG file and edit e.g. its video or audio stream (date-wise)? Could we embed XMP-data to the MPG file somehow? Or can the MPG file be hex-edited? Would it be possible to create a sidecar/xmp for the original MPG file? What I am aiming at is to trick or rather help Carousel to position the MPG file in the timeline according to the same-named xmp file? It is a long shot but I would still like to try it. – zarko Jan 17 '15 at 18:39
  • That entirely depends on what Carousel supports. I'd rather ask on their forums or support. I would doubt that they have metadata support for anything non-standard (read: non-EXIF or any containers other than maybe MP4 and MKV). The problems is, really, that there's no standard way to add metadata to MPEG files. You can put whatever you like in so-called "user private streams", but you'd have to have a special decoder for it, too. I'd rather go for re-encoding. Or maybe try the remuxing approach again—maybe even with other tools such as MKVToolNix. You could ask a new question about that. – slhck Jan 17 '15 at 20:01
  • Hey slhck! In comparison of the two commands: ffmpeg -i input.mpeg -c:v libx264 -preset slow -crf 18 -c:a aac -strict experimental -b:a 128k output.mp4 and ffmpeg -i input -c:v libx264 -preset slow -crf 18 -pix_fmt yuv420p -c:a aac -strict experimental -b:a 128k -movflags +faststart output.mp4 the only different parts are these: -pix_fmt yuv420p -movflags +faststart Do they improve the conversion? Would appreciate your insight :-) – zarko Feb 03 '15 at 12:08
  • The `-pix_fmt` setting may help improve compatibility with some players or devices. If not set, with some inputs (e.g. images) it could happen that the video is not [chroma subsampled](http://en.wikipedia.org/wiki/Chroma_subsampling). You can safely set this option for any conversion. The `faststart` option moves the file index to the beginning, which will make the video playback start faster when you're streaming it from a server. You can always set this for MP4 containers. – slhck Feb 03 '15 at 12:20
  • Superbly explained slhck! Thanks! And what about the -movflags? Do you know what it does? – zarko Feb 03 '15 at 13:05
  • `-movflags +faststart` belong together. It just says, use the MOV option (MP4 and MOV are similar) `faststart` :) – slhck Feb 03 '15 at 15:59
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.

Salman A
  • 1,652
  • 2
  • 19
  • 32