Log in

View Full Version : how do I get ffmpeg to copy timecodes?


mynewusername
14th July 2010, 00:51
Hi,

I am having trouble getting ffmpeg to preserve the timecode when changing video from an mkv to a flv. The mkv is h.264 and I am using -vcodec copy. I am doing this because I need to play the files over adobe flash player using the new 10.1 api appendBytes method that require the flv fileformat.

Here is the command line:
"ffmpeg.exe -i '400-001.mkv' -vcodec copy -acodec libmp3lame -ab 64k -ar 44100 -copyts '400-001.flv'"

I thought this was what the -copyts flag was for but I get the same file with or without it.

I am using one of the ffmpeg autobuilds:

FFmpeg version SVN-r24228, Copyright (c) 2000-2010 the FFmpeg developers
built on Jul 13 2010 04:18:07 with gcc 4.4.2
configuration: --enable-gpl --enable-version3 --enable-libgsm --enable-pthread
s --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libmp3lame --
enable-libopenjpeg --enable-libschroedinger --enable-libopencore_amrwb --enable-
libopencore_amrnb --enable-libvpx --arch=x86 --enable-runtime-cpudetect --enable
-libxvid --enable-libx264 --extra-libs='-lx264 -lpthread' --enable-librtmp --ext
ra-libs='-lrtmp -lpolarssl -lws2_32 -lwinmm' --target-os=mingw32 --enable-avisyn
th --cross-prefix=i686-mingw32- --cc='ccache i686-mingw32-gcc' --enable-memalign
-hack
libavutil 50.22. 0 / 50.22. 0
libavcodec 52.83. 0 / 52.83. 0
libavformat 52.73. 0 / 52.73. 0
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.22. 0 / 1.22. 0
libswscale 0.11. 0 / 0.11. 0

I have attached two small clips so you can see what I am talking about. If you open the mkv file in vlc you can see that the timecode starts at 00:00:12 and goes to 00:00:13 give or take. The flv however says it starts at 00:00:00 and goes until 00:00:13, but runs out of video after 1 second.

Sorry for the small files but I have a 300kb upload limit.

Here is the ffmpeg -i for the file:
FFmpeg version SVN-r24228, Copyright (c) 2000-2010 the FFmpeg developers
built on Jul 13 2010 04:18:07 with gcc 4.4.2
configuration: --enable-gpl --enable-version3 --enable-libgsm --enable-pthread
s --enable-libvorbis --enable-libtheora --enable-libspeex --enable-libmp3lame --
enable-libopenjpeg --enable-libschroedinger --enable-libopencore_amrwb --enable-
libopencore_amrnb --enable-libvpx --arch=x86 --enable-runtime-cpudetect --enable
-libxvid --enable-libx264 --extra-libs='-lx264 -lpthread' --enable-librtmp --ext
ra-libs='-lrtmp -lpolarssl -lws2_32 -lwinmm' --target-os=mingw32 --enable-avisyn
th --cross-prefix=i686-mingw32- --cc='ccache i686-mingw32-gcc' --enable-memalign
-hack
libavutil 50.22. 0 / 50.22. 0
libavcodec 52.83. 0 / 52.83. 0
libavformat 52.73. 0 / 52.73. 0
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.22. 0 / 1.22. 0
libswscale 0.11. 0 / 0.11. 0
[flv @ 002fc220] Estimating duration from bitrate, this may be inaccurate

Seems stream 0 codec frame rate differs from container frame rate: 47.95 (48000/
1001) -> 23.98 (48000/2002)
Input #0, flv, from 'C:\...\400-003.flv':
Metadata:
duration : 14
width : 320
height : 176
videodatarate : 0
framerate : 24
videocodecid : 7
filesize : 85589
Duration: 00:00:13.97, start: 12.429000, bitrate: N/A
Stream #0.0: Video: h264, yuv420p, 320x176, 23.98 tbr, 1k tbn, 47.95 tbc
At least one output file must be specified

ifb
16th July 2010, 00:27
You could try Baptiste's ffmpeg fork, ffmbc (http://code.google.com/p/ffmbc/), that has some extra features useful for broadcast/production.

kieranrk
16th July 2010, 01:29
FLV timestamps must start from zero.

roozhou
16th July 2010, 04:38
BIG FAT WARNING:
Official ffmpeg does NOT support -vcodec copy from mkv when b-frame is used. And this is not to be fixed in the near future.

If you need frame copy from mkv to flv or anything else, use ffmpeg build from here (http://forum.doom9.org/showthread.php?t=152419).

Dark Shikari
16th July 2010, 04:42
BIG FAT WARNING:
Official ffmpeg does NOT support -vcodec copy from mkv when b-frame is used. And this is not to be fixed in the near future.I'm pretty sure this was fixed a month or two ago. I've been using -vcodec copy with bframes just fine. I just tested it on an MKV and it works quite perfectly.

Furthermore, if this was the issue, he would be getting a very specific error message. Which he isn't getting.

As kierank said, FLV requires that the first timestamp be zero.

roozhou
16th July 2010, 07:30
I'm pretty sure this was fixed a month or two ago. I've been using -vcodec copy with bframes just fine. I just tested it on an MKV and it works quite perfectly.

Have you tried mkv -> mp4/flv? FFmpeg won't popup error, but the target file is unplayable.

MKV contains only PTS while MP4/FLV require both PTS and DTS. FFmpeg currently lacks the ability to generate DTS based on PTS. I have done some hack on the MKV demuxer so my ffmpeg generates correct DTS from MKV. That's why only my ffmpeg works on MKV.

Dark Shikari
16th July 2010, 07:53
Have you tried mkv -> mp4/flv? FFmpeg won't popup error, but the target file is unplayable.FLV plays fine here. Didn't test mp4.

roozhou
16th July 2010, 09:05
FLV plays fine here. Didn't test mp4.

It is not a surprise that some players accept such files (e.g. MPC-HC), but the PTS of the first frame will always be non-zero.

sneaker_ger
16th July 2010, 18:10
I never had success with remuxing mkv->mp4 (tried it every now and then, should be ffmpeg issue 807) using ffmpeg but it seems to be working in the latest build. The files seem to play fine. Could you test if the newest version creates mp4 files correctly, roozhou?

roozhou
17th July 2010, 17:30
I never had success with remuxing mkv->mp4 (tried it every now and then, should be ffmpeg issue 807) using ffmpeg but it seems to be working in the latest build. The files seem to play fine. Could you test if the newest version creates mp4 files correctly, roozhou?
No, I checked out build from http://ffmpeg.arrozcru.org/autobuilds/ and it still fails. The file plays in MPC-HC, but fails in mplayer and PSP.

I have looked into ffmpeg's auto DTS generation code, and unfortunately it cannot be handling mkv correctly.

If you are using windows, try my build here (http://forum.doom9.org/showthread.php?t=152419).

Dark Shikari
17th July 2010, 17:46
No, I checked out build from http://ffmpeg.arrozcru.org/autobuilds/ and it still fails. The file plays in MPC-HC, but fails in mplayer and PSP.Works just fine in mplayer here. :rolleyes:

sneaker_ger
17th July 2010, 18:24
Thanks for testing, both of you. For me playing works fine in Lord_Mulder's mplayer build, but not in kovensky chan's. So I'm tempted to believe in roozhou and will stay away from it for now, at least for archival purposes. Extracting the tracks and muxing using mp4box plays fine in both builds (as expected).

roozhou's version works fine.

Ritsuka
17th July 2010, 18:52
I guess mplayer is not a good app to test, it used to play even mp4 without pts informations.

b66pak
17th July 2010, 18:59
ps3 only plays mp4 remuxed with roozhou's build of ffmpeg...
_

mynewusername
17th July 2010, 21:28
FLV timestamps must start from zero.

Thanks for all the responses. I ended up keeping track of the starting time inside of my player code to get around this.