Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting video formats and copying tags with ffmpeg

I've been trying to convert some videos I took on my camera to a compressed format in order to save some storage space. I figured out how to use ffmpeg to convert the videos to the format I want, but what I haven't been able to figure out is how to copy the metadata. I'd like to copy the original metadata from when the video was taken (most importantly the creation time). I've tried running ffmpeg using the -map_meta_data 0:0 option, but that didn't seem to work. Any ideas?

It looks like the data I want to copy in this case is in the format section of the video. Using ffprobe with the show_format option, I get this output:

[FORMAT]
filename=video.AVI
nb_streams=2
format_name=avi
format_long_name=AVI format
start_time=0.000000
duration=124.565421
size=237722700
bit_rate=15267331
TAG:creation_time=2012-02-07 12:15:27
TAG:encoder=CanonMVI06
[/FORMAT]

I would like to copy the two tags to my new video.

like image 294
Scott Avatar asked Jul 29 '12 01:07

Scott


People also ask

What is FFmpeg video format?

ffmpeg is a command-line tool that converts audio or video formats. It can also capture and encode in real-time from various hardware and software sources such as a TV capture card. ffplay is a simple media player utilizing SDL and the FFmpeg libraries.

Does FFmpeg work with mp4?

FFmpeg can input most container formats natively, including MP4, . ts, MOV, AVI, Y4M, MKV, and many others. This is the output file.


2 Answers

Have a look at the documentation on dumping and loading metadata:

FFmpeg is able to dump metadata from media files into a simple UTF-8-encoded INI-like text file and then load it back using the metadata muxer/demuxer.

The process might look something like this:

# First extract metadata
ffmpeg -i original.mov -f ffmetadata metadata.txt
# Next, transcode, including extracted metadata
ffmpeg -i original.mov -f ffmetadata -i metadata.txt compressed.mp4

I don't have a metadata-ful video to test with right now, but something like that should work.

like image 112
blahdiblah Avatar answered Sep 19 '22 21:09

blahdiblah


Use "-map_metadata 0:g" to copy all global metadata.

0 means Input #0. g means global metadata.

Here's my ffprobe result. enjoy!

input.mp4

[FORMAT]
filename=input.mp4
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.000000
duration=60.560500
size=190252680
bit_rate=25132246
probe_score=100
TAG:major_brand=mp42
TAG:minor_version=1
TAG:compatible_brands=mp42avc1
TAG:creation_time=2016-05-14 10:01:17
[/FORMAT]

output.mp4

[FORMAT]
filename=output.mp4
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.000000
duration=60.632000
size=38636429
bit_rate=5097826
probe_score=100
TAG:major_brand=isom
TAG:minor_version=512
TAG:compatible_brands=isomiso2avc1mp41
TAG:creation_time=2016-05-14 01:01:17
TAG:encoder=Lavf57.36.100
[/FORMAT]
like image 26
stegoma Avatar answered Sep 20 '22 21:09

stegoma