I want to convert a bunch of old videos to H.264 to save space, but ffmpeg always drops the creation date, no matter what fancy -map_metadata variations I use. This is obviously a huge dealbreaker for me.
When converting a video, ffmpeg even displays the creation date, only to not copy it. Here's ffmpeg's output from converting one video:
$ ffmpeg -i avi/test/21.1.08\ 081.AVI -pix_fmt yuv420p test.mov
ffmpeg version 2.6.1 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libvorbis --enable-libfaac --enable-libfdk-aac --enable-libopus --enable-libwebp --enable-nonfree --enable-vda
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from 'avi/test/21.1.08 081.AVI':
Metadata:
creation_time : 2008年01月20日 12:12:22
encoder : CanonMVI06
Duration: 00:00:13.23, start: 0.000000, bitrate: 15161 kb/s
Stream #0:0: Video: mjpeg (MJPG / 0x47504A4D), yuvj422p(pc, bt470bg/unknown/unknown), 640x480, 14486 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc
Stream #0:1: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, 1 channels, s16, 705 kb/s
[swscaler @ 0x7fc952800600] deprecated pixel format used, make sure you did set range correctly
[libx264 @ 0x7fc95203da00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2
[libx264 @ 0x7fc95203da00] profile High, level 3.0
[libx264 @ 0x7fc95203da00] 264 - core 144 r2533 c8a773e - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[mov @ 0x7fc95203ce00] WARNING codec timebase is very high. If duration is too long,
file may not be playable by quicktime. Specify a shorter timebase
or choose different container.
Output #0, mov, to 'test.mov':
Metadata:
encoder : Lavf56.25.101
Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 640x480, q=-1--1, 30 fps, 1000k tbn, 30 tbc
Metadata:
encoder : Lavc56.26.100 libx264
Stream #0:1: Audio: aac (libfaac) (mp4a / 0x6134706D), 44100 Hz, mono, s16, 128 kb/s
Metadata:
encoder : Lavc56.26.100 libfaac
Stream mapping:
Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Stream #0:1 -> #0:1 (pcm_s16le (native) -> aac (libfaac))
Press [q] to stop, [?] for help
frame= 92 fps=0.0 q=29.0 size= 159kB time=00:00:03.90 bitrate= 333.0kbits/frame= 174 fps=173 q=29.0 size= 442kB time=00:00:05.89 bitrate= 613.6kbits/frame= 250 fps=165 q=29.0 size= 768kB time=00:00:08.89 bitrate= 707.3kbits/frame= 324 fps=161 q=29.0 size= 1099kB time=00:00:10.89 bitrate= 826.6kbits/frame= 397 fps=149 q=-1.0 Lsize= 1448kB time=00:00:13.23 bitrate= 896.2kbits/s
video:1311kB audio:122kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.060318%
[libx264 @ 0x7fc95203da00] frame I:2 Avg QP:23.06 size: 15524
[libx264 @ 0x7fc95203da00] frame P:165 Avg QP:24.65 size: 6142
[libx264 @ 0x7fc95203da00] frame B:230 Avg QP:27.41 size: 1293
[libx264 @ 0x7fc95203da00] consecutive B-frames: 7.8% 23.2% 65.0% 4.0%
[libx264 @ 0x7fc95203da00] mb I I16..4: 20.0% 74.5% 5.5%
[libx264 @ 0x7fc95203da00] mb P I16..4: 4.0% 4.5% 0.7% P16..4: 46.2% 13.5% 7.5% 0.0% 0.0% skip:23.6%
[libx264 @ 0x7fc95203da00] mb B I16..4: 0.1% 0.1% 0.1% B16..8: 40.6% 3.2% 0.6% direct: 0.8% skip:54.5% L0:43.7% L1:51.4% BI: 4.9%
[libx264 @ 0x7fc95203da00] 8x8 transform intra:51.4% inter:66.4%
[libx264 @ 0x7fc95203da00] coded y,uvDC,uvAC intra: 40.3% 63.6% 22.5% inter: 11.6% 17.6% 1.3%
[libx264 @ 0x7fc95203da00] i16 v,h,dc,p: 20% 23% 6% 51%
[libx264 @ 0x7fc95203da00] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 17% 21% 4% 5% 8% 5% 6% 6%
[libx264 @ 0x7fc95203da00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 26% 19% 14% 5% 8% 9% 8% 6% 6%
[libx264 @ 0x7fc95203da00] i8c dc,h,v,p: 56% 17% 23% 4%
[libx264 @ 0x7fc95203da00] Weighted P-Frames: Y:7.9% UV:2.4%
[libx264 @ 0x7fc95203da00] ref P L0: 60.0% 14.3% 16.9% 8.6% 0.2%
[libx264 @ 0x7fc95203da00] ref B L0: 73.8% 21.7% 4.5%
[libx264 @ 0x7fc95203da00] ref B L1: 89.1% 10.9%
[libx264 @ 0x7fc95203da00] kb/s:811.24
How do I get ffmpeg to copy the creation date of these videos?
2 Answers 2
There seems to a problem with ffmpeg while copying creation_time metadata from video. However, you can do this manually like this:
ffmpeg -i avi/test/21.1.08\ 081.AVI -pix_fmt yuv420p -metadata creation_time='2008-01-20 12:12:22' test.mov
-
2And then if you have 100 videos in a folder and want to do it in batch...Jonny– Jonny2024年12月15日 01:55:51 +00:00Commented Dec 15, 2024 at 1:55
I wrote a small program (in Swift) that copies the creation and modification dates for each file in a source directory to another directory containing pre-converted files with corresponding file names.
If using this you'll have to modify sourcePath and outputPath to match your directory structure. And also possibly filepathOutput if your video files aren't MP4s, etc.
import Foundation
enum MyError: Error {
case dateFetchFailed(String)
}
struct AttributeJob {
let fileToModify: String
let attributesToSet: [FileAttributeKey : Any]
}
let filemanager = FileManager()
let sourcePath = "/Users/yourname/temp/sourcevideos"
let outputPath = "/Users/yourname/temp/outputvideos"
let files = filemanager.enumerator(atPath: sourcePath)
var jobs = [AttributeJob]()
while let file = files?.nextObject() {
let filepathSource = "\(sourcePath)/\(file)"
let filepathOutput = "\(outputPath)/\(file).mp4"
if !filemanager.fileExists(atPath: filepathSource) {
print("Warning: expected filepathOutput did not exist: \(filepathOutput)")
continue
}
do {
let attributes = try filemanager.attributesOfItem(atPath: filepathSource)
if let creationDate = attributes[FileAttributeKey.creationDate], let modificationDate = attributes[FileAttributeKey.modificationDate] {
let setTheseAttributes: [FileAttributeKey : Any] = [
FileAttributeKey.creationDate: creationDate,
FileAttributeKey.modificationDate: modificationDate,
]
jobs.append(.init(fileToModify: filepathOutput, attributesToSet: setTheseAttributes))
}
else {
throw(MyError.dateFetchFailed("Could not get dates for \(filepathSource)"))
}
}
catch {
print("Error getting attributes for \(filepathSource): \(error)")
}
}
for job in jobs {
do {
try filemanager.setAttributes(job.attributesToSet, ofItemAtPath: job.fileToModify)
print("Set attributes for \(job.fileToModify) to: \(job.attributesToSet)")
}
catch {
print("Error setting attributes for \(job.fileToModify): \(error)")
}
}
creation_timeif you use-map_metadata 0?-map_metadata 0doesn't change ffmpeg's behavior in any way.