View Full Version : AVCHD .m2ts conversion for Linux
Axel Olmos 01-17-07, 10:13 PM Hi,
For those of us using Linux, I put together a readme and some sample scripts on how to convert .m2ts files to a format playable with mplayer.
Here's a link to the package I put together:
http://www.olmosconsulting.com/m2ts.tar.gz
Here is the procedure used:
1. Use xporthdmv to convert the file into .mpv and .mpa files.
2. Use ldecod to convert the .mpv file into a .yuv file.
3. Rename the .mpa file ldecod created to .ac3
4. Convert the .yuv file into a .y4m file using yuv4mpeg.
At this point, you have a .y4m file and .ac3 file which should be
standard.
5. Use ffmpeg to create a .avi file that contains the .y4m
transcoded to something else and the .ac3 file.
Sample commands:
xporthdmv -nh FILE.m2ts 1 1 1
ldecod -i bits0001.mpv -o /tmp/FILE.yuv
mv bits0001.mpa /tmp/FILE.ac3
yuv4mpeg -w 1440 -h 1080 -x 420mpeg2 < /tmp/FILE.yuv > /tmp/FILE.y4m
ffmpeg -i /tmp/FILE.y4m -i /tmp/FILE.ac3 -acodec copy -vcodec h264 -sameq -s 1440x1080 -aspect 16:9 -b 15000000 FILE.avi
If there is anyone out there who knows what they are doing with ffmpeg and
has suggestions, I'd love to hear them.
Axel
Giorgio Arlanch 01-27-07, 07:23 AM It's about a month that I'm looking for a m2ts conversion.
I spent a lot of hour in internet, but this is the first solution I found that use only opensource programs.
I tried and it works fine.
I found only a little problems during the last step:
ffmpeg -i /tmp/FILE.y4m -i /tmp/FILE.ac3 -acodec copy -vcodec h264 -sameq -s 1440x1080 -aspect 16:9 -b 15000000 FILE.avi
The output is:
Input #0, yuv4mpegpipe, from 'bits0001.y4m':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 1440x1080, 29.97 fps(r)
Input #1, ac3, from 'bits0001.ac3':
Duration: 00:00:21.3, start: 0.000000, bitrate: 448 kb/s
Stream #1.0: Audio: ac3, 48000 Hz, 5 channels, 448 kb/s
Output #0, avi, to 'output.avi':
Stream #0.0: Video: 0x0000, yuv420p, 1440x1080, q=2-31, 2115098 kb/s, 29.97 fps(c)
Stream #0.1: Audio: ac3, 48000 Hz, 5 channels, 448 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Unsupported codec for output stream #0.0
Then i tried with mpegvideo code and it runs well.
I use cinelerra and the 1080i source video has to deinterlace.
Do you think it's better to deinterlace during the conversion m2ts->avi or could be better to deinterlace using cinelerra filter?
Thanks very much
:) :) :)
For all of you Mac OS X users, this is a viable solution. I will give Axel full details on how I got it to work so that he can include it in his m2ts.tar.gz file. There are still a few bugs to work out (aspect ratio for one), but I was able to get the m2ts file converted, and I can view it in various programs. Stay tuned.
mangell 02-06-07, 09:47 PM How were you able to get the file on to your Linux workstation? Has anyone been successful in mounting the drive over USB? I've been trying this to no avail. What device should I use on the mount command? I'm using RH9, so my kernel may certainly be to old for this cambera. After reading through theBlu-ray Disc/DVD+RW/+R/-R[W] for Linux article it seems an upgrade may be in order.
Any pointers?
Giorgio Arlanch 02-07-07, 05:31 AM Hi Mangel,
I use Kubuntu edgy and it autodetect and mount itself pendrive and camera.
I prefer to use windows to save the m2ts file on a fat32 partition and then I return in linux and use a script for convert the m2ts->quicktime mov file with mpeg4+aac codec.
The script is very slow, but the mov file works fine in cinelerra.
When you connect the device to usb port try to use the command
lsusb
You can see the list of the founded devices.
Bye
Giorgio
How were you able to get the file on to your Linux workstation? Has anyone been successful in mounting the drive over USB? I've been trying this to no avail. What device should I use on the mount command? I'm using RH9, so my kernel may certainly be to old for this cambera. After reading through theBlu-ray Disc/DVD+RW/+R/-R[W] for Linux article it seems an upgrade may be in order.
Any pointers?
As I have discussed with Axel in PMs, the yuv4mpeg step can be skipped using the following command:
% ffmpeg -r 29.97 -s 1440x1080 -i /tmp/samplevideo.yuv -i /tmp/samplevideo.ac3 -vcodec mpeg4 -acodec copy -aspect 16:9 -b 15000k samplevideo.avi
Ffmpeg will take the *.yuv file created by ldecod and convert it to whatever format you like. Note that the order of options is important (which might help Giorgio's problem).
[edited] video and audio now sync properly with the addition of -r 29.97
I have posted Mac OS X instructions here (http://www.0ctane.net/files/readme_osx.txt) for converting AVCHD content to HDV, and hopefully Axel will include them in his package. You should still get Axel's m2ts.tar.gz file (see first post at top of page) since it has a sample video clip and other information.
My instructions illustrate how to convert AVCHD content into HDV content, which is a format supported by iMovieHD and Final Cut. Of course, you can convert your videos into many other formats too, but that is up to you.
A new option is Voltaic (http://www.mac1080hd.com). This bundles the whole process together into one program (and does not require QTPro). Of course, the benefit of my instructions are that it is the free way of doing a conversion.
Giorgio Arlanch 02-08-07, 08:32 AM Thanks for your suggestion Octane. I will try it.
The procecude is very slow. Remove a step is a good idea.
I also tried -vcodec mpeg4 but I must use -acodec aac.
I don't know why, but I have problem using -acode copy. Cinelerra don't work with this ac3 stream.
I also tried the option -deinterlace. It seems work well.
At the moment I prefer use pal low resolution format and so I use this command:
ffmpeg -i /tmp/samplevideo.y4v -i /tmp/samplevideo.ac3 -acodec aac -ac 5 -ab 448 -r 25 -vcodec mpeg4 -sameq -s 720x576 -aspect 16:9 -deinterlace samplevideo.mov
Bye
As I have discussed with Axel in PMs, the yuv4mpeg step can be skipped using the following command:
% ffmpeg -r 29.97 -s 1440x1080 -i /tmp/samplevideo.yuv -i /tmp/samplevideo.ac3 -vcodec mpeg4 -acodec copy -aspect 16:9 -b 15000k samplevideo.avi
Giorgio Arlanch 02-08-07, 12:58 PM Hi Octane,
I tried to use directly yuv file but my ffmpeg don't recognize yuv codec:
FFmpeg version SVN-r7773, Copyright (c) 2000-2006 Fabrice Bellard, et al.
configuration: --enable-faac --enable-gpl --enable-pthreads --disable-debug --disable-mmx --enable-a52
libavutil version: 49.2.0
libavcodec version: 51.29.0
libavformat version: 51.8.0
built on Jan 31 2007 08:18:23, gcc: 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)
picture size invalid (0x0)
[rawvideo @ 0x6d4880]Could not find codec parameters (Video: rawvideo, yuv420p)
/mnt/hda4/temp/file.yuv: could not find codec parameters
Did you compile ffmpeg or did you install it from binary? Can you give me the configuration options. You can find it on the second line when you run ffmpeg.
Thanks
% ffmpeg -r 29.97 -s 1440x1080 -i /tmp/samplevideo.yuv -i /tmp/samplevideo.ac3 -vcodec mpeg4 -acodec copy -aspect 16:9 -b 15000k samplevideo.avi
Hi Octane,
I tried to use directly yuv file but my ffmpeg don't recognize yuv codec:
picture size invalid (0x0)
[rawvideo @ 0x6d4880]Could not find codec parameters (Video: rawvideo, yuv420p)
/mnt/hda4/temp/file.yuv: could not find codec parameters
I have to requote myself: "Note that the order of options is important". Maybe I should have written "VERY important". If the -r 29.97 -s 1440x1080 is NOT before your input (-i) you will get the error you experienced (I had to post to the ffmpeg forums in order to learn this lesson). By having the -r -s before the -i you are telling ffmpeg that the input is 29.97fps and at a 1440x1080 size.
Axel Olmos 02-08-07, 03:18 PM For all of you Mac OS X users, this is a viable solution. I will give Axel full details on how I got it to work so that he can include it in his m2ts.tar.gz file. There are still a few bugs to work out (aspect ratio for one), but I was able to get the m2ts file converted, and I can view it in various programs. Stay tuned.
Thanks so much for this!! I updated the .tar.gz with the improvements.
Axel Olmos 02-08-07, 04:37 PM It looks to me that our videos are NOT 16:9, but are 4:3. Dropping the -aspect 16:9 from the ffmpeg line makes the video smaller, but the aspect looks right. Can anyone verify?
Giorgio Arlanch 02-08-07, 06:40 PM Thanks Octane,
using the right order it works well.
And now, the next step, is to remove ldecod!
... "VERY important". If the -r 29.97 -s 1440x1080 is NOT before your input (-i) ...
johnellisdm 02-17-07, 01:28 PM i tried your instructions at octane(dot)net for getting this to convert with a mac. i'm getting strange results. in iMovieHD, the avi just comes out black. i tried with the sample in axel's post and also with a sample i got from somewhere else (i don't want to commit to buying the camera until i am comfortable that i can edit footage with it), both with the same results. in FCP, it tells me that it is missing a codec.
any ideas?
johnellisdm 02-17-07, 02:11 PM ok, after running all the scrits, i can get it to work in mplayer, but i'm still getting "no codec" in fcp. do i have to get this codec from somewhere?
johnellisdm 02-17-07, 06:35 PM after playing around with the m2tstoavi script a bit, i think i *might* be getting somewhere:
i can load stuff into fcp if i change the vcodec to mpeg2video and change the extension of the file to .mpg. only problem is i don't get sound. i'm thinking that fcp doesn't support ac3? anyway, i tried to set acodec to something other than copy and i get:
[ac3 @ 0x423514]A52 library liba52.so.0 could not be opened!
dlopen(liba52.so.0, 1): image not found
i tried to recompile with --enable-shared but that got a compile error. i am using the ffmpeg revision 7013. the one checked out as a result of the download script doesn't seem to work with the configuration options in the "configure" script. it seems they have changed at some point.
any ideas?
johnellisdm 02-18-07, 01:01 AM i've been playing with some of the settings for ffmpeg. i changed the script around so that i could change the video codec, audio codec, format and the output file extension.
i ended up with:
set codec=mpeg4
set acodec=mp3
set fformat=mov
set fext=mov
and i use the -f option which forces a certain format on ffmpeg.
and that seemed to work ok in fcp if i set the project to:
HDV 1080i60
the only problem is that i have to always render the timeline, which will take a long time. i'm wondering if there is some format i could use ffmpeg to transform to that fcp will handle natively.
the other section of the scrip that i modified is the bottom that calls ffmpeg:
echo ffmpeg -r 29.97 -s 1440x1080 -i $tmpfile".yuv" -i $tmpfile".ac3" -f $fformat -vcodec $codec -sameq -acodec $acodec -aspect 16:9 -b 15000k $outputfile
ffmpeg -r 29.97 -s 1440x1080 -i $tmpfile".yuv" -i $tmpfile".ac3" -f $fformat -vcodec $codec -sameq -acodec $acodec -aspect 16:9 -b 15000k $outputfile && rm -f $tmpfile".ac3" $tmpfile".yuv"
john
johnellisdm 02-19-07, 11:16 AM Ok.. using all the steps above, you can get an mpeg4/mp3 .mov file (i guess you loose the surround sound feature of the camera). from there, you can use Compressor to convert to HDV. once the file is in HDV, you can edit natively in FCP.
I am planning on using the above script and apple's Folder Actions feature to create an apple script that will run when .m2ts files are dropped into my "porjects" folder. with this, i will have pretty much the same workflow as if FCP handled AVCHD natively.
when i get all this done, i will post all the relevant scripts, etc.
john
johnellisdm 02-21-07, 05:09 PM ok... i got an SR1 from fry's electronics (they still have a "no restocking fee" return policy) and tried some video out. i was able to edit, but for every min. of recorded footage, it took about 20-30 mins to convert. this will not work for me since i usually shoot underwater footage on a dive trip. i like to shoot in the morning and edit in the afternoons/evenings. i couldn't wait the 5 hours it would take to convert 10 mins of video.
i think i'll go with the HDR-HC7. looks like it has some better stats anyway, especially for the low light conditions when diving.
Lysander 03-14-07, 11:47 AM xport is not compiling for me without warnings. And it doesn't seem to be working. As I understand it, xport should convert the .MTS (m2ts) file into seperate video and audio files in original format- eg: mp4 and ac3. The audio file is playable in VLC, but the video is not.
The warning I get when trying to compile xport on a mac are:
gcc -o xportdmv xport.c ; chmod 755 xportdmv
xport.c:37: warning: integer constant is too large for 'long' type
xport.c: In function 'parse_ac3_audio':
xport.c:383: warning: integer constant is too large for 'long' type
xport.c: In function 'parse_mp2_audio':
xport.c:626: warning: integer constant is too large for 'long' type
This is a PowerMac G5 with OS X 10.4.8
I checked the first line and the value is being put into a long long type, not a long type, and long long seems to be supported on the Mac, so I'm not sure how to get GCC to compile this correctly... it wants to put it in a long (And this probably causes the video problems I was seeing.)
gcc --version
powerpc-apple-darwin8-gcc-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
Copyright (C) 2005 Free Software Foundation, Inc.
xport is not compiling for me without warnings. And it doesn't seem to be working. As I understand it, xport should convert the .MTS (m2ts) file into seperate video and audio files in original format- eg: mp4 and ac3. The audio file is playable in VLC, but the video is not. Yes, xport separates tracks. The video cannot be played in VLC since VLC does not (yet?) recognize AVCHD.
The warning I get when trying to compile xport on a mac are:
... it wants to put it in a long (And this probably causes the video problems I was seeing.)Are you saying that it did compile, but just gave error/warning messages? Did you go through the rest of the procedure to convert to *.yuv and then to a playable mpeg/mp4 format?
Axel Olmos 03-16-07, 08:12 PM xport is not compiling for me without warnings. And it doesn't seem to be working...
Hi, it turns out the latest version of xporthdmv exports 0 byte audio files. I am in contact with the author who will try and fix it. In the meantime, unless you are lucky enough to find a download of an older version of xport, you are stuck without audio.
Axel Olmos 03-23-07, 06:48 PM Hi, it turns out the latest version of xporthdmv exports 0 byte audio files. I am in contact with the author who will try and fix it. In the meantime, unless you are lucky enough to find a download of an older version of xport, you are stuck without audio.
For those of you having trouble with xport creating 0 byte audio files:
diff xport.c xport.c.orig
383,384c383,384
< if (pts_aligned != 0 ) {
< if (current_pts >= 0 ) {
---
> if (pts_aligned != 0xffffffffffffffff) {
> if (current_pts >= pts_aligned) {
Change lines 383,384 as indicated above.
That change makes it work on my machine. (It probably has unintended consequences for other cases I don't understand.)
p28driver 04-03-07, 12:34 AM Axel - Thanks for your post; works great on the small samples I've played with. Problem is the size of the raw files generated by ldecod - around 4GB / min of video for my samples. Seems like there should be a way to avoid creating the entire raw file, like piping the output of ldecod directly to ffmpeg. I tried this, but it looks like one or the other (or both) doesn't support pipes. Am I wrong? Any ideas?
p28driver
Yeah, the hard drive overhead is quite big. I am not aware of being able to pipe into ffmpeg. You could always get onto the ffmpeg development forum and post an inquiry there.
p28driver 04-03-07, 12:02 PM I dug into this a bit more by looking at the source code for ffmpeg, and it certainly does allow for pipes. Looks like you still have to specify an input filename with the -i option, but for a pipe you specify either "-" or "/dev/stdin" as the input filename.
The remaining question is whether or not the ldecod output can be piped to another program, which looks doubtful. I'm looking into the source code of ldecod to see if it's possible, with or without modifiation...
p28driver
latedate 04-03-07, 01:22 PM I dug into this a bit more by looking at the source code for ffmpeg, and it certainly does allow for pipes. Looks like you still have to specify an input filename with the -i option, but for a pipe you specify either "-" or "/dev/stdin" as the input filename.
The remaining question is whether or not the ldecod output can be piped to another program, which looks doubtful. I'm looking into the source code of ldecod to see if it's possible, with or without modifiation...
p28driver
If ldecod doesn't accept pipes (stdin) explicitly, can't you work around the problem using named pipes (FIFOs)?
Chris
p28driver 04-03-07, 07:47 PM Thanks, Chris! Named pipes do the trick nicely!
Here's what I tried:
% xport -h sample.m2ts 1 1 1
% mv bits0001.mpa sample.ac3
% mkfifo pipe.yuv
% ldecod -i bits0001.mpv -o pipe.yuv &
% ffmpeg -r 29.97 -s 1440x1080 -i pipe.yuv -i /tmp/sample.ac3 -acodec copy \
-vcodec mpeg4 -aspect 16:9 -b 15000k sample.avi
% rm pipe.yuv
No gigantic intermediate files, no filling up my hard drive with 15 minutes of raw video I'm just going to delete anyway! This is starting to look like a practical technique.
Does anybody have links to other sample videos from any of the Sony AVCHD cameras?
Dallas
It looks to me that our videos are NOT 16:9, but are 4:3. Dropping the -aspect 16:9 from the ffmpeg line makes the video smaller, but the aspect looks right. Can anyone verify?Yes, the camera captures video at 4:3. That is why we need to explicitly state the resolution (1440x1080) and aspect ratio (16:9).
Interesting work-around with the pipes guys. I had never used (or even heard of) mkfifo before. I tested it out on one of my videos and it worked just fine. Great job!
For Macintosh iMovie users, the ac3 format and -acodec copy does not seem to be a viable option. Apple does not really support ac3, and Quicktime does not seem to be able to convert to a different audio format internally. I slightly modified my command-line options to allow output as mp3. % ffmpeg -r 29.97 -s 1440x1080 -i avchd.yuv -i avchd.ac3 -vcodec mpeg4 -ac 2 -acodec mp3 -aspect 16:9 -b 15000k sample.avi
I was previously having "Error while opening codec for output stream #0.1" problems because ac3 is 5 (.1) channel while mp3 is 2 channel. Duh. However, exporting the video to HDV 1440x1080 in Quicktime Pro still causes the audio to drop/fail. More digging...
Thanks to everyone who is contributing, debugging, and optimizing. :D
dwrowley 04-19-07, 07:38 AM Does anyone have any pre-compiled intel binaries for xport, ldecod, etc.?
Thanks,
David
Does anyone have any pre-compiled intel binaries for xport, ldecod, etc.?
Thanks,
DavidDavid,
Well, yes. Anyone who has followed the instructions has intel binaries for the programs. The big problem is that most of these programs by default use dynamic library linking, and if your libraries are in slightly different places, then you will not be able to use someone else's binaries. Eventually I may build and distribute binaries (if the various packages' licenses allow it). That also requires time that I do not have right now. I did provide my ffmpeg binary to someone to test, but they never told me if it worked or not. Very frustrating.
If you put in a little effort, you can compile the binaries yourself. Alex and I already put in the toughest work in figuring out how to get the ball rolling. And, by building the software yourself, you will better understand how to build other free software too. :cool:
dwrowley 04-24-07, 01:02 AM An update on my AVCHD to MacOS / Quicktime conversion goal.
Well I was able to get xport compiled and running, and then ldecod (I originally tried JM 12.2 - March 13, 2007 - but got bus errors, so I backed out to 12.1 - worked fine). (Axel's and Jeffrey's documentation was great)
For ffmpeg, when compiling the x264 library, the configure script was a bit screwed up for macs - looking for yasm instead of nasm - but I just grabbed/compiled/installed yasm and all was well.
Everything else (lame, etc.) was straightforward.
I got the mkfifo version of the script running easily (I had to apply the same '-ac 2' fix to map 5.1 to stereo) - and am now happily (though SLOWLY!) transcoding AVCHD .MTS files to 20mbps mpeg4 quicktime files which import nicely into iMovieHD. This makes my new Panasonic HDC-SD3 camcorder FAR more useful to me (and the quality of the video is excellent - full 1920x1080i - and it records to 4gb+ SD cards (SDHC actually)) I now have a complete MacOS only workflow - no more having to run Nero under Windows/Parallels!
It's amazing how many people's efforts went in to this incredible open source environment - all very much appreciated.
Now if we can only improve ldecod performance :-)
Thanks again,
Cheers,
David
It's amazing how many people's efforts went in to this incredible open source environment - all very much appreciated.
I am glad things are working for you. Yes, while Axel was the instigator of this madness, and while I continued the fun, the community has helped a lot with debugging and useful advice.
dwrowley 04-24-07, 04:58 PM That's excellent news, 0ctane!
Do you know if anyone is working on a higher-performance ldecod?
It would also be great to have AVCHD/.m2ts support in some kind of player (mplayer, vlc, etc.) - right now the best alternative I've found on the mac is to run Elecard's player under Parallels...
Looks like things are starting to come together for the AVCHD format! (I noticed Pinnacle sent out an announce for Studio 11 that supports AVCHD -- and while I don't use Pinnacle, it's good to see further support announced).
David
I don't have to pretend to be a dumb beginning user...I AM ONE. I thought I was purchasing something more than a PAPER WEIGHT to use with my MAC...so far it is the most expensive paper weight ever!
I have the HDC-SD1PP...I have a MacBook Pro fully loaded and up to date running VMware Fusion (so I can move files - images and avchd to the MAC).
I have read everything in this thread...makes me hopeful, but still lost.
Is there something I can do once I have the AVCHD files on the MAC to convert them there or do I have to try and figure out how to make what you all mention above work under Fusion?
Finally...when Premier Pro for MAC comes out and they support AVCHD...how will that work...how will I get files from the camera to the computer?
Final "finally"...I spoke with Panasonic...they said there was NO WAY to use the camera as a webcam. Any of you know otherwise?
At this point I feel like I made a real mistake buying this...but the video looks so nice in bright and dark settings :-)!
Thanks, ---bill
Do you know if anyone is working on a higher-performance ldecod?I am just a hobbiest that has a little programming experience. As far as I know, the JM group are the only ones with ldecod (of course, someone might be calling it something else). Their website has information on the AVCHD specifications, and I know they are continuing to work on improving the code.
It would also be great to have AVCHD/.m2ts support in some kind of player (mplayer, vlc, etc.) - right now the best alternative I've found on the mac is to run Elecard's player under Parallels...Not much of an alternative, especially if you have 1GB RAM or less. Yes, it would be nice to have AVCHD playback support in a Mac program. Go ahead and write it. :eek: I am looking into adding AVCHD support to ffmpeg which would save a step (but in reality it would just be bundling ldecod into ffmpeg). As I have little-to-no AV experience, this may be a delusion, and it might take a few years. Anyone feel like helping my R&D expenses?
I have the HDC-SD1PP...I have a MacBook Pro fully loaded and up to date running VMware Fusion (so I can move files - images and avchd to the MAC).Well, you do not need VMware to access the files. Just plug the USB cable to you Mac. I forget which directory the files live in (DCIM maybe?), but you can just copy them over as if the camera was an external hard drive.
Is there something I can do once I have the AVCHD files on the MAC to convert them there or do I have to try and figure out how to make what you all mention above work under Fusion?
Again, the "solution" we have devised does not require VMware or Windows. You will need to figure out how to use the "command line" on your Mac. Yes, the process is a little laborious. Eventually I hope to make a friendlier interface, so you may want to keep your paperweight a little longer.
Finally...when Premier Pro for MAC comes out and they support AVCHD...how will that work...how will I get files from the camera to the computer? Well, like I wrote above, you will probably just need to drag the files onto your computer and then edit them there. For a better answer, talk to the Premier Pro folks.
Final "finally"...I spoke with Panasonic...they said there was NO WAY to use the camera as a webcam. Any of you know otherwise? Not me.
After playing with setting for a while, I think I have come up with a better encoding scheme for OS X users. This is borrrowing on the pipe information presented earlier, and it includes an optimization for iMovieHD users.% xporthdmv -nh samplevideo.m2ts 1 1 1
% mv bits0001.mpa /tmp/samplevideo.ac3
% mkfifo pipe.yuv
% ldecod -i bits0001.mpv -o pipe.yuv &
% ffmpeg -r 29.97 -s 1440x1080 -i pipe.yuv -i /tmp/samplevideo.ac3 -acodec pcm_s16le -ac 2 -vcodec mpeg4 -aspect 16:9 -b 15000k samplevideo.avi
% rm pipe.yuv /tmp/samplevideo.ac3
We are mapping the AC3 audio into 2 channel PCM which Quicktime is happy about. Yes, the aspect ratio looks funny. You still need to "Export..." from Quicktime Pro in the Apple Intermediate Codec as HDV1080i, and you need to choose Linear PCM Stereo for the audio. The resulting film should appear just fine (16:9) when you import it into iMovieHD. It worked for me, YMMV. :)
Axel Olmos 05-01-07, 07:32 PM For those of you having trouble with xport creating 0 byte audio files:
diff xport.c xport.c.orig
383,384c383,384
< if (pts_aligned != 0 ) {
< if (current_pts >= 0 ) {
---
> if (pts_aligned != 0xffffffffffffffff) {
> if (current_pts >= pts_aligned) {
Change lines 383,384 as indicated above.
That change makes it work on my machine. (It probably has unintended consequences for other cases I don't understand.)
I updated the .tar.gz file to include this change as well as 0ctane's new readme.
dwrowley 05-09-07, 06:06 PM My pipeline is working well with the JM 12.1 ldecod I compiled, but the performance is SLOW! Apparently 12.2 (release March 13, 2007) has some good performance improvements, but it hangs when I run it on my test files...
Anyone have any luck with using JM 12.2 (on MacOS)?
Thanks,
David
Yes, I am using JM 12.2 right now on OS X.
dwrowley 05-10-07, 03:33 PM And no problems? Did you make any mods in the src, set special compiler options, or anything else?
Could you perhaps PM me the file? (ldecod is relatively standalone, right?)
Thanks,
David
general question...
Can I do any significant damage is I say mis-type some of the script items in the command line?
outside of the obvious dl *.*
thanks...almost ready to try the wizardry you all have created.
--bill
Raymundo 06-25-07, 07:44 AM Hi,
I am about to buy a camcorder, and like the Panasonic SD1, howeverneed to know can i down load AVCHD onto my Mac and then edit it from there. I am not very technically savy and i have tried to follow the thread, but it looks like i am going to have trouble doing that. Please advise.
Also, for all SD1 owners, what is the quality of the video like. I read that there is still a "trailing" issue with all AVCHD type recording vs. traditional tape. Is there any thing to be said for that.
Thanks for you comments.
If you follow the instructions in Axel's download (or from my site) you can edit AVCHD content on your Mac (free version). Or, you can wait 1 week. For those of you who are not programming savvy, I will be releasing prebuilt & bundled software to do the conversion to HDV1080i (which can be edited in iMovieHD and FC, but you will have to pay a few bucks). Stay tuned.
If you follow the instructions in Axel's download (or from my site) you can edit AVCHD content on your Mac (free version). Or, you can wait 1 week. For those of you who are not programming savvy, I will be releasing prebuilt & bundled software to do the conversion to HDV1080i (which can be edited in iMovieHD and FC, but you will have to pay a few bucks). Stay tuned.
I hope it isn't out of the range of us working POOR, but either way...thanks to all here that have strived to allow the rest of us to use our cameras with a MAC! Hip, Hip Horray!
--bill
p.s. OCTANE, if you have a mailing list of those interested in your programming magic please ADD me.
graphite99 06-29-07, 03:29 AM thanks octane for your help. yes a pre-bundled version would be GREAT to have. let us know when your package is avaliable & reliable.
ta!!!
Does anyone have any pre-compiled intel binaries for xport, ldecod, etc.?
Since this seems to be a common question (especially in e-mails), there is a new option. Voltaic (http://www.mac1080hd.com) brings the whole process together in one package. The output format is HDV1080i with the Apple Intermediate Codec. Therefore, the resulting movies are in the native format for iMovieHD and Final Cut. QuicktimePro is not necessary. Visit http://www.mac1080hd.com.
[edit]I don't have a e-mail list yet. I have a personal website (http://0ctane.net) . I am thinking of creating a developer blog, probably with a RSS feed. Unfortunately, I am not great with blogging software.
Thanks Octane and others...the software from Voltaic is WORTH it!
==bill
snostorm 07-19-07, 09:28 PM I recently bought a Sony HD camcorder the HDR5 HDD 40Gig one. I downloaded the scripts and all dependencies and am having a audio sync issue. I am using JM12.3 ldecod Not sure if that is the problem or not I guess I could try to find 12.2 but the installer did not retrieve it. any help would be greatly appreciated I can try about any thing can program a little and know my way around linux enough to be dangerous
snostorm,
Your problem is probably a regional one. NTSC vs PAL. Set your FPS to 25 if you are in a PAL region or 29.97 if in a NTSC region.
snostorm 07-21-07, 09:01 PM Here is my ffmpeg command I have also tried moving the -r option around but always get the same results I have also set it to 25 to match what it seems to think the video is but I bought he camcorder in the US so it should be NTSC, not sure why ffmpeg thinks the video is in PAL 25 fps
ffmpeg -r 29.97 -s 1440x1080 -i test_dec.yuv -i test.ac3 -vcodec mpeg4 -acodec copy -aspect 16:9 -b 15000k samplevideo.avi
FFmpeg version SVN-r8743, Copyright (c) 2000-2007 Fabrice Bellard, et al.
configuration: --prefix=/usr --libdir=/usr/lib --shlibdir=/usr/lib --mandir=/usr/share/man --enable-shared --enable-gpl --enable-pp --enable-swscaler --enable-pthreads --enable-x11grab --enable-dc1394 --enable-liba52bin --enable-libdts --enable-libfaac --enable-libfaadbin --enable-libmp3lame --enable-libogg --enable-libtheora --enable-libvorbis --enable-xvid --extra-cflags=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables --disable-strip
libavutil version: 49.4.0
libavcodec version: 51.40.3
libavformat version: 51.12.1
built on Apr 23 2007 23:45:21, gcc: 4.1.1 20070105 (Red Hat 4.1.1-51)
Input #0, rawvideo, from 'test_dec.yuv':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 1440x1080, 25.00 fps(r)
Input #1, ac3, from 'test.ac3':
Duration: 00:00:44.5, start: 0.000000, bitrate: 448 kb/s
Stream #1.0: Audio: 0x0000, 48000 Hz, 5:1, 448 kb/s
Output #0, avi, to 'samplevideo.avi':
Stream #0.0: Video: mpeg4, yuv420p, 1440x1080, q=2-31, 15000 kb/s, 29.97 fps(c)
Stream #0.1: Audio: ac3, 48000 Hz, 5:1, 448 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Press [q] to stop encoding
frame= 386 fps= 14 q=4.5 Lsize= 24559kB time=12.9 bitrate=15639.7kbits/s
video:20774kB audio:704kB global headers:0kB muxing overhead 14.346512%
Received signal 2: terminating.
ethos101 07-31-07, 11:57 AM I am somewhat of a linux noob. I've learned a lot though. Anyways, I try not to compile from source if I don't have to. In fact I think I only ever successfully did it once. I wish there was another way but anyways, here's what I'm getting when I run ./install or ./installasroot or even with ./configure.
/bin/csh: bad interpreter: Permission denied
Surely I am doing something wrong? Can someone shed some light on this for me?
I have Sony HDR-SR1 with .mts files I need to convert then edit.
Thanks in advance.
Here is my ffmpeg command I have also tried moving the -r option around but always get the same results I have also set it to 25 to match what it seems to think the video is but I bought he camcorder in the US so it should be NTSC, not sure why ffmpeg thinks the video is in PAL 25 fps
ffmpeg -r 29.97 -s 1440x1080 -i test_dec.yuv -i test.ac3 -vcodec mpeg4 -acodec copy -aspect 16:9 -b 15000k samplevideo.avi
...
Input #0, rawvideo, from 'test_dec.yuv':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 1440x1080, 25.00 fps(r)
Input #1, ac3, from 'test.ac3':
Duration: 00:00:44.5, start: 0.000000, bitrate: 448 kb/s
Stream #1.0: Audio: 0x0000, 48000 Hz, 5:1, 448 kb/s
Output #0, avi, to 'samplevideo.avi':
Stream #0.0: Video: mpeg4, yuv420p, 1440x1080, q=2-31, 15000 kb/s, 29.97 fps(c)
The -r command stays at the front as you have posted. Did you get your camera off e-bay or something? It is possible that you did get a PAL camera, as it clearly seems to be the case. I thought I remembered reading something about a cinema mode that would do 24 or 25fps on an otherwise NTSC camera, but I could be mistaken. Offhand, I do not recall any camera options for setting the regional info, but you could check through the menus and manual.
rob_avs 09-16-07, 10:52 PM snostorm & others:
I am having the EXACT same audio syncing issues. Using all the scripts as is I cannot get the audio to sync to the video... the longer the clip, the more out of sync it gets. I began to suspect the frame rate, and pulled out plenty of hair. I went ahead and forced the ffmpeg step to 25 fps... and the audio sync'd up!
I bought this camera for my wife 12/20/06 from a Best Buy in Kansas City. All the packaging and manuals say NTSC. What am I doing wrong here?
I do not think you are necessarily doing anything wrong. Apparently PAL encoding cameras are finding there was to NTSC regions. I would be very interested to know if there is a way to switch.
rob_avs 09-17-07, 08:55 AM There is no doubt in my mind that I have a PAL camera. The following scripts produce clips with perfectly sync'd audio (note the 25 fps on the ffmpeg and mencoder steps):
$ cat /usr/local/bin/m2tstoavi
#!/bin/tcsh
#The scripts and instructions in this package are free to use and
#redistribute AT YOUR OWN RISK!! Standard disclaimers apply.
#NO WARRANTY!
echo using:
which xporthdmv || exit
which ldecod || exit
which ffmpeg || exit
if ( $#argv == "0" ) then
echo usage: $0 filename.m2ts ...
exit
else
set files=($*)
endif
set path = ( . $path )
echo $0 Starting.
echo " "
foreach file ($files)
if ( ! -f $file ) then
echo file $file not found
exit
endif
set outputfile=`basename $file | sed s/\.m2ts// | sed s/\.MTS//`
set tmpfile=`echo $outputfile`
set outputfile=$outputfile".avi"
echo Converting $file of $files...
if ( ! -f $tmpfile".ac3" ) then
echo xporthdmv -nh $file 1 1 1
xporthdmv -nh $file 1 1 1 && mv bits0001.mpa $tmpfile".ac3"
else
echo $tmpfile".ac3" already exists, not creating it.
endif
if ( ! -f $outputfile ) then
mkfifo pipe.yuv
echo ldecod -i bits0001.mpv -o pipe.yuv
echo ffmpeg -r 25 -s 1440x1080 -i pipe.yuv -i $tmpfile".ac3" -vcodec mpeg4 -sameq -acodec copy -aspect 16:9 -b 15000k $outputfile
ldecod -i bits0001.mpv -o pipe.yuv &
ffmpeg -r 25 -s 1440x1080 -i pipe.yuv -i $tmpfile".ac3" -vcodec mpeg4 -sameq -acodec copy -aspect 16:9 -b 15000k $outputfile && rm -f $tmpfile".ac3" $tmpfile".yuv"
rm -f bits0001.mpv
rm -f pipe.yuv
else
echo $outputfile exists, not creating it.
endif
end
rm -f ./dataDec.txt ./log.dec
echo $0 complete.
$ cat /usr/local/bin/mencoder_two_pass
#!/bin/tcsh
#The scripts and instructions in this package are free to use and
#redistribute AT YOUR OWN RISK!! Standard disclaimers apply.
#NO WARRANTY!
if ( $#argv == "0" ) then
echo usage: $0 filename.avi ...
exit
else
set files=($*)
endif
set path = ( . $path )
echo using:
which mencoder || exit
echo $0 Starting.
echo " "
foreach file ($files)
if ( ! -f $file ) then
echo file $file not found
exit
endif
set outputfile=`basename $file | sed s/\.avi// | sed s/\.AVI//`
set outputfile=$outputfile".m2p.avi"
echo MENCODER two-pass encoder converting $file of $files -- pass 1...
mencoder $file -o $outputfile \
-fps 25 \
-vf scale=720:405 \
-oac copy \
-ovc lavc \
-lavcopts \
vcodec=mpeg4:trell:qpel:vbitrate=4000:mbd=1:vqmax=10:lmax=10 :keyint=130:vpass=1:turbo
echo MENCODER two-pass encoder converting $file of $files -- pass 2...
mencoder $file -o $outputfile \
-fps 25 \
-vf scale=720:405 \
-oac copy \
-ovc lavc \
-lavcopts \
vcodec=mpeg4:trell:qpel:vbitrate=4000:mbd=1:vqmax=10:lmax=10 :keyint=130:vpass=2
end
echo $0 complete.
rm divx2pass.log
If the scripts are adjusted to use 29.97 fps the audio in the resulting clip falls more and more out of sync as the length of the clip increases. Judging from this thread and others I have found on the web I know I am not the only one with this issue. Can it be an accident that PAL cameras are in the US in NTSC boxes? Or did Sony realize they were falling short of quantities of NTSC HDR-SR1 leading up to xmas '06? Did they make up the shortfall by boxing PAL cameras in NTSC boxes? I am more than a little disappointed.
I have a fix for the H.264 reference decoder with files from the Panasonic HDC-SD5 AVCHD camcorder. The HDC-SD5 H.264 bitstream does not contain recovery_point SEI messages, and this makes the reference decoder essentially ignore the stream.
I've added an option (-f) to ldecod to force the recovery point.
ldecod -f -i bits0001.mpv
Here's the patched source files (for JM 13.0) along with the Windows binary.
http://www.w6rz.net/ldecod_patch.zip
BTW, has anyone tried to compile xport lately? I've been trying to make it as OS independent as possible. Version 1.00 is here:
http://www.w6z.net/xport.zip
Ron
Thanks Ron. I haven't had any problem using the existing version of ldecod with H.264 streams from my Panasonic HDC-SD3 (which resembles the HDC-SD1 more than the SD5). I guess that means the recovery_point SEI messages were present in the streams from these earlier models...
Thanks Ron. I will take a look at these new files. As I communicated with you previously, there are a few SD5 cameras out there that have problems, but not all. Hopefully this will solve the problems.
Hi, Ron,
any plans to include this change in the official sources?
Thanks, Gordan
Hi, Ron,
any plans to include this change in the official sources?
Thanks, Gordan
I think Ron has already modified his xport. ldecod is maintained by a different individual.
The current top-of-trunk version of mencoder from SVN at mplayerhq.hu can decode raw .mts files.
That means that if you checkout and build this version of mplayer/mencoder, you can use a single commandline like the one below to do the entire decode/encode in one step. I've done several tests, and seen no A/V sync issues. Here's the command:
# mencoder $file -o ./$file.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=5000 -fps 60 -vf scale=1280:720
Yes, I'm scaling it down, and thats just for playback on my PC. I assume you could stick with 1440:1080 and still get reasonable playback speed as long as you encode as mpeg4. I haven't tried using the x264 encoder yet, but that should work as well.
Looks like it is at least getting close. I grabbed dev-SVN-r25991-4.0.1, but it is having trouble with the video stream. The resulting audio track is of the correct size, but the video track is too long. I also get "X dulicate frame(s)!" messages during the conversion.
Did you pass any additional configure options? Also, your fps should probably be 59.94 (double the NTSC 29.97).
catpunt 02-26-08, 01:21 PM Try forcing the output FPS like so:
mencoder $file -o ./$file.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=5000 -fps 59.94 -ofps 29.97 -vf scale=1280:720
I think the "X duplicate frames" warning is because mencoder simply discards every other frame for interlaced AVCHD source files.
Has anyone gotten this to work using just ffmpeg without any other programs? I think it's just a matter of making ffmpeg (or libx264) discard every other field to achieve rudimentary "support" for this conversion.
I still get framerate issues with your modifications. Like you say, support is rudimentary. Many people have posted to the ffmpeg mailing list regarding proper handling of interlacing with AVCHD content. We just need someone to, I hate to say it, "get'er done". But, that is a discussion for the ffmpeg mailing list....
catpunt 02-26-08, 01:46 PM Agreed.
This is the command line I used to get the conversion I wanted:
~/src/mplayer-checkout-2008-02-14/mencoder 00042.MTS -o test.mp4 -oac lavc -ovc lavc -lavcopts acodec=libfaac:vcodec=libx264:vbitrate=800 -of lavf -lavfopts format=mp4 -fps 59.94 -ofps 29.97 -vf scale=1280:720
The frame rate and audio sync of the output file seemed correct.
Louis-Marie 02-27-08, 07:00 AM I use :
# mencoder /$video.mts -o /$video.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=5000 -fps 50 -vf scale=1280:720
It gives me a perfect audio/video sync, I just loose some frames somtimes.
(ps : sry for my bad english)
What about the date and time of creation information that is tored in MTS file. Is there a way to retrieve this info and then use ffmpeg to store it in resulting file?
What about the date and time of creation information that is tored in MTS file. Is there a way to retrieve this info and then use ffmpeg to store it in resulting file?That information is not stored in the AVCHD file.
kensystem 02-29-08, 01:15 PM Not sure this is true - the first AVCHD camcorder (hdr-sr1) records shutter speed, gain, f-stop equiv, and AWB in the transport stream metadata. I'm not sure about datetime (if it is only implied fom the file-name) but dont see why it shouldnt be supported in the TS.
Okay, this is getting a bit off topic, but I would like to see your source that says those values are stored in the AVC stream. Framerate and aspect ratio are stored, of course. Have you spent any time looking at the transport stream? Can you find a date and time? Can you find any of those other values?
kensystem 02-29-08, 01:39 PM The simplest way to demonstrate this is to put old m2ts files back onto the camera (using the vendor software) and turn on the camera's metadata display. As far as transport stream analyzers and what standard the vendor uses to encode this data, that depends. I havent had a licensed transport stream analyzer in my pocession for a while now, and dont know of any free ones.
kensystem 02-29-08, 02:06 PM I found a free analyzer, and it appears there is not a separate PID for metadata, only a video and audio PID. Perhaps the data is embedded into the video, I do not know. But it is available. Googling for "data code" and mpeg transport stream variants turns up few results, interestingly.
jryoung 04-07-08, 11:21 AM Hi there, for the first time I have a few large recordings (one maxed out at 4GB - on my 8GB SDHC card on my Panny SD1, and the other is about 3.7GB). The files are playable on the camcorder, but the xporthdmv command seems to fail to read the file. I wondered if the "fopen" c command can handle such a large file. My other files are under 2GB, and they seem fine. Is this a recognised problem? Is there a solution?
Thanks for the great work on Linux and mts!!
Jonathan
Axel Olmos 04-09-08, 02:15 PM Are you using a 32 bit version of Linux or a 64 bit version?
Hi there, for the first time I have a few large recordings (one maxed out at 4GB - on my 8GB SDHC card on my Panny SD1, and the other is about 3.7GB). The files are playable on the camcorder, but the xporthdmv command seems to fail to read the file. I wondered if the "fopen" c command can handle such a large file. My other files are under 2GB, and they seem fine. Is this a recognized problem? Is there a solution?
Thanks for the great work on Linux and mts!!
Jonathan
I believe fopen64 is supported in Linux. Replace the four fopen function calls in xport to fopen64 and see if it compiles and links.
Ron
If anyone still cares, another way to fix the 2GB limit is to compile with the _FILE_OFFSET_BITS option. Like so:
gcc -O3 -D_FILE_OFFSET_BITS=64 xport.c -o xport
Tested on Solaris only.
Ron
Hi there.
This is a version of m2tstoavi.mencoder which supports pipelining.
$ cat m2tstoavi.mencoder.fifo
#!/bin/csh
set resolution=640x360
set resx=640
#The scripts and instructions in this package are free to use and
#redistribute AT YOUR OWN RISK!! Standard disclaimers apply.
#NO WARRANTY!
if ( $#argv == "0" ) then
echo usage: $0 filename.m2ts ...
exit
else
set files=($*)
endif
set path = ( . $path )
echo using:
which xporthdmv || exit
which ldecod || exit
which ffmpeg || exit
echo $0 Starting.
echo " "
foreach file ($files)
if ( ! -f $file ) then
echo file $file not found
exit
endif
set filebase=`basename $file | sed s/\.m2ts// | sed s/\.MTS//`
#set audiofile=/tmp/$filebase".ac3"
#set videofifo=/tmp/$filebase".yuv"
set audiofile=$filebase".ac3"
set videofifo=$filebase".yuv"
set outputfile=`stat -c %y $file | cut -d \. -f 1`" @"$resolution" ("`basename $file`").avi"
if ( ! -f $audiofile ) then
echo xporthdmv -hn $file 1 1 1
xporthdmv -hn $file 1 1 1 && mv bits0001.mpa $audiofile
else
echo $audiofile already exists, not creating it.
endif
mkfifo $videofifo
echo ldecod -i bits0001.mpv -o $videofifo
ldecod -i bits0001.mpv -o $videofifo > /dev/null &
if ( ! -f "$outputfile" ) then
echo mencoder $videofifo -demuxer rawvideo -rawvideo w=1440:h=1080 -aspect 16:9 \
-vf scale -zoom -xy $resx \
-cache 8192 \
-audiofile $audiofile \
-oac copy -ovc x264 -x264encopts bitrate=5000 \
-o "$outputfile"
mencoder $videofifo -demuxer rawvideo -rawvideo w=1440:h=1080 -aspect 16:9 \
-vf scale -zoom -xy $resx \
-cache 8192 \
-audiofile $audiofile \
-oac copy -ovc x264 -x264encopts bitrate=5000 \
-o "$outputfile"
else
echo $outputfile exists, not creating it.
endif
#echo To remove temporary files: rm -f *.ac3 *.yuv
rm -f ./dataDec.txt ./log.dec bits0001.mpv $videofifo $audiofile
end
echo $0 complete.
Warning.
The script is used for PAL (Sony HDR-UX1E) camera with 25 fps (to convert-and-scale at once). :)
I have no idea is it really necessary to specify fps for NTSC... Perhaps no.
Hi. I'm having a bit of a problem using this script. It's the only method i'w tried so far that gives me a croped output.
For starters, i'm new to the whole avchd world. Actualy i'm new to everything that has anything to do with video editing, but i understand the consepts.
I bought my sony hdr-sr10e a couple of days ago and i am trying to convert the output files to something useable (since i don't have any blueray equipment.).
The problem is: when i try to run the script i get a perfect picture (and no sound in VLC) but the playback never stops. It seems like there is no end of file or something. When i try to play my avi-files in any other player on my windows computer i get no picture, the time runs wild (from 0:00 mins to 2:42 and so on). The strange thing here is that i get audio in those players. (t.d. windows media player, but i think this is because wmp is using the ffdshow ac3 codec).
I was hoping that someone have encountered this cind of problem, and that there is some cind of fix to it.
btw: The output from my camcorder is: 1920x1080, 16Mbits/s and PAL. (norway).
--
Halvard
Hi there.
This is a version of m2tstoavi.mencoder which supports pipelining.
Hi. I'm having a bit of a problem...
and i solved it. It was a codec-problem on my vista machine. the ffdshow was messing about with the ac3-audio-tracks.. no big problem. (and vlc witch is not using any 3d party codecs did not support the audio-tracks from my camcorder. )
mplayer played it without problems btw.
--
HL
Hi folks,
First thanks to everyone who has contributed to this thread, it's been of great help, however I'm now a little stuck. I don't own a HD camera but I'm thinking of getting one, I've been trying out these scripts on random .mts files that people have been uploading to the net and they've all worked great! However I've found some MTS files from the camera that I want to buy in another thread on this forum and I can't get them to work with these scripts. I know the output is in 1920 x 1080 but changing that in the script hasn't helped I still get corrupted audio or .avi files that are 0mb in size, if anyone has any suggestions I'd be really grateful. Heres a link to the files I've been trying to convert
eirikso2.com/Panasonic_HDC-SD5/Original-MTS-Streams-From-Camera/
Following Axels notes/utilities I am able to convert from my Panasonic generated AVCHD .mts file to .mpg or .avi or what ever. However the audio is out of sync. The longer the file plays the further out of sync it becomes. I assume this is directly related to the vbr video encoding. In any case how does one synchronize the audio to the video when transcoding in this fashion?
What I am actually doing is (for example):
xporthdmv -hn 1 1 1 1
ldecod -i bits0001.mpv
ffmpeg -s 1440x1080 -y -i $videofile -i $audiofile -target ntsc-vcd -r 29 -acodec mp3 -vcodec mpeg2video $outputfilempg
Is this still the best way to accomplish this? Thx.
Following Axels notes/utilities I am able to convert from my Panasonic generated AVCHD .mts file to .mpg or .avi or what ever. However the audio is out of sync. The longer the file plays the further out of sync it becomes. I assume this is directly related to the vbr video encoding. In any case how does one synchronize the audio to the video when transcoding in this fashion?
What I am actually doing is (for example):
xporthdmv -hn 1 1 1 1
ldecod -i bits0001.mpv
ffmpeg -s 1440x1080 -y -i $videofile -i $audiofile -target ntsc-vcd -r 29 -acodec mp3 -vcodec mpeg2video $outputfilempg
Is this still the best way to accomplish this? Thx.
First, put the rate in front of the size. Next, use an appropriate rate. This has been discussed previously, but to give you a hint, ntsc is not 29.000fps.
spoleweski 06-19-08, 07:19 PM Since this seems to be a common question (especially in e-mails), there is a new option. Voltaic (http://www.mac1080hd.com) brings the whole process together in one package. The output format is HDV1080i with the Apple Intermediate Codec. Therefore, the resulting movies are in the native format for iMovieHD and Final Cut. QuicktimePro is not necessary. Visit http://www.mac1080hd.com.
[edit]I don't have a e-mail list yet. I have a personal website (http://0ctane.net) . I am thinking of creating a developer blog, probably with a RSS feed. Unfortunately, I am not great with blogging software.
This program is sweet, but $30usd? thats a bit rich, all it does is convert the files. Why such a heavy price tag??
This program is sweet, but $30usd? thats a bit rich, all it does is convert the files. Why such a heavy price tag??
I don't know. Ask them. You already paid how much for your camera?
spoleweski 06-20-08, 09:58 PM I don't know. Ask them. You already paid how much for your camera?
1600 AUD
Exactly! And yet there are free conversion programs for pc users like Oxygen Lite 1.2. I've ended up installing bootcamp on my mac and using oxygen to convert the files instead.
debfreak 06-26-08, 11:51 PM Hi there,
I'm a Debian/Ubuntu user and I recently purchased a Sony HDR-SR12 which records to AVCHD .mts files. I have the files on my machine's hard drive, but I am hesitant to jump into transcoding the video right away. I certainly want them out of the .mts format (because I can't play/edit them right now!) but I would like to preserve video quality by not transcoding.
Now as I understand it, AVCHD uses the H.264/MPEG-4 AVC format for video, which is my target format anyway (at least until Theora/Dirac get better), so as I see it, why should I have to transcode the video? I would like the audio in Vorbis format with the container as Matroska, so I certainly want to make steps to do that, but why do I have to transcode the video at all if My target format is MPEG-4 AVC video, Vorbis audio, and Matroska container?
Is it possible to simply demux the H.264 video and AC-3 audio from each other to get rid of .mts, then simply transcode the AC-3 to Vorbis and remux the pristine H.264 video stream with the newly encoded Vorbis stream into a Matroska container file? This is my ideal situation, and I obviously am not as wise or knowledgeable as some here are, so please tell me why this is or is not possible, and how to do it if it is.
Again, my goal is to not have to transcode the H.264 video the camera records. Once a Free/Open video format of sufficient quality emerges down the line, I plan on transcoding this camera's H.264 recordings into that (probably Dirac?), and one transcoding is enough in my opinion, so I definitely don't want to have to do it twice to reach Dirac in a few years (H.264 --> H.264 --> Dirac is worse than H.264 --> Dirac).
Hope I've been clear enough to elicite an intelligent and clear response,
thank you
Hi there,HelloNow as I understand it, AVCHD uses the H.264/MPEG-4 AVC format for video, which is my target format anyway (at least until Theora/Dirac get better), so as I see it, why should I have to transcode the video? I would like the audio in Vorbis format with the container as Matroska, so I certainly want to make steps to do that, but why do I have to transcode the video at all if My target format is MPEG-4 AVC video, Vorbis audio, and Matroska container?
Is it possible to simply demux the H.264 video and AC-3 audio from each other to get rid of .mts, this is what the xport step doesthen simply transcode the AC-3 to Vorbis and remux the pristine H.264 video stream with the newly encoded Vorbis stream into a Matroska container file? This is my ideal situationIn an ideal world, this would be fine. However, AVCHD's h264 stream is not a garden variety mpeg-4/h264. AVCHD is a bastard child created by Sony and Panasonic. Until a straight decoder is made which will play the AVCHD h264 stream, we have to transcode to a standard h264 (or other format).
Your best option is to transcode stuff now, but keep a hard copy of all the MTS/m2ts files (DVD or Hard drive backup). That is my advice.
jryoung 07-01-08, 11:37 AM Thanks - sorry for the late reply, but that did the trick.
canonhf100 07-25-08, 01:45 AM I've been trying to get this script to work,but so far have been unable to get ldecod. The output from the script is :-
Starting ./install script.
Starting ./download script.
Archive: xport.zip
xport.zip unzipped
Archive: jm14.1.zip
jm14.1.zip unzipped
ffmpeg
/usr/bin/ffmpeg
ffmpeg done
mplayer
/usr/bin/mplayer
mplayer done
Run the configure script to configure the downloaded software
The ./download script has ended.
Starting ./configure script.
/bin/sed
Removing DOS LF chars...
Done.
x264
No suitable assembler found. Install 'yasm' to get MMX/SSE optimized code.
If you really want to compile without asm, configure with --disable-asm.
x264 done
a52dec-0.7.4
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for working aclocal... missing
checking for working autoconf... missing
checking for working automake... missing
checking for working autoheader... missing
checking for working makeinfo... missing
checking whether to enable maintainer-specific portions of Makefiles... no
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking how to run the C preprocessor... gcc -E
checking whether gcc needs -traditional... no
checking if gcc supports -g -O3 flags... yes
checking if gcc supports -g -O3 -fomit-frame-pointer flags... yes
checking if gcc supports -g -O3 -fomit-frame-pointer -mcpu=pentiumpro flags... yes
checking for ld used by GCC... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognise dependant libraries... pass_all
checking command to parse /usr/bin/nm -B output... ok
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for ranlib... ranlib
checking for strip... strip
checking for objdir... .libs
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... no
checking if we can lock with hard links... yes
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking whether the linker (/usr/bin/ld) supports shared libraries... yes
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
creating libtool
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/timeb.h usability... yes
checking sys/timeb.h presence... yes
checking for sys/timeb.h... yes
checking io.h usability... no
checking io.h presence... no
checking for io.h... no
checking for inttypes.h... (cached) yes
checking for gcc option to accept ANSI C... none needed
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking for always_inline... yes
checking for restrict... __restrict__
checking for size_t... yes
checking whether byte ordering is bigendian... no
checking for memalign... yes
checking for gettimeofday... yes
checking for ftime... yes
checking return type of signal handlers... void
checking for _oss_ioctl in -lossaudio... no
checking __attribute__ ((aligned ())) support... 64
configure: creating ./config.status
config.status: creating Makefile
config.status: creating autotools/Makefile
config.status: creating include/Makefile
config.status: creating test/Makefile
config.status: creating doc/Makefile
config.status: creating src/Makefile
config.status: creating liba52/Makefile
config.status: creating libao/Makefile
config.status: creating vc++/Makefile
config.status: creating include/config.h
config.status: include/config.h is unchanged
config.status: executing default-1 commands
a52dec-0.7.4 done
Run the compile script to compile the software.
The ./configure script has ended.
Starting ./compile script.
checking dependencies
compiling object file "obj/annexb.o" ...
compiling object file "obj/biaridecod.o" ...
compiling object file "obj/block.o" ...
compiling object file "obj/cabac.o" ...
compiling object file "obj/context_ini.o" ...
compiling object file "obj/erc_api.o" ...
compiling object file "obj/erc_do_i.o" ...
compiling object file "obj/erc_do_p.o" ...
compiling object file "obj/errorconcealment.o" ...
compiling object file "obj/filehandle.o" ...
compiling object file "obj/fmo.o" ...
compiling object file "obj/header.o" ...
compiling object file "obj/image.o" ...
compiling object file "obj/ldecod.o" ...
compiling object file "obj/leaky_bucket.o" ...
compiling object file "obj/loopFilter.o" ...
compiling object file "obj/macroblock.o" ...
compiling object file "obj/mb_access.o" ...
compiling object file "obj/mbuffer.o" ...
compiling object file "obj/mc_prediction.o" ...
compiling object file "obj/memalloc.o" ...
compiling object file "obj/nal.o" ...
compiling object file "obj/nal_part.o" ...
compiling object file "obj/nalu.o" ...
compiling object file "obj/nalucommon.o" ...
compiling object file "obj/output.o" ...
compiling object file "obj/parset.o" ...
compiling object file "obj/parsetcommon.o" ...
compiling object file "obj/quant.o" ...
In file included from src/quant.c:24:
inc/quant.h:32: error: conflicting types for qmatrix
inc/global.h:76: error: previous declaration of qmatrix was here
src/quant.c:226: error: conflicting types for qmatrix
inc/global.h:76: error: previous declaration of qmatrix was here
src/quant.c: In function init_qp_process:
src/quant.c:242: warning: implicit declaration of function malloc
src/quant.c:242: warning: incompatible implicit declaration of built-in function malloc
src/quant.c:245: warning: incompatible implicit declaration of built-in function malloc
make: *** [obj/quant.o] Error 1
cp: cannot stat `bin/ldecod.exe': No such file or directory
chmod: cannot access `../xporthdmv': No such file or directory
chmod: cannot access `../ldecod': No such file or directory
Run the configure2 script to configure ffmpeg and mplayer
The ./compile script has ended.
Installing xporthdmv into /usr/local
Installing hdrsr1 into /usr/local
Installing m2tstoavi into /usr/local
Doing make install for x264-snapshot-20080629-2245
Makefile:3: config.mak: No such file or directory
./configure
No suitable assembler found. Install 'yasm' to get MMX/SSE optimized code.
If you really want to compile without asm, configure with --disable-asm.
make: *** [config.mak] Error 1
Doing make install for a52dec-0.7.4
Making install in autotools
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/autotools'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/autotools'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/autotools'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/autotools'
Making install in include
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/include'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/include'
make[2]: Nothing to be done for `install-exec-am'.
/bin/bash ../autotools/mkinstalldirs /usr/local/include/a52dec
/usr/bin/install -c -m 644 a52.h /usr/local/include/a52dec/a52.h
/usr/bin/install -c -m 644 attributes.h /usr/local/include/a52dec/attributes.h
/usr/bin/install -c -m 644 audio_out.h /usr/local/include/a52dec/audio_out.h
/usr/bin/install -c -m 644 mm_accel.h /usr/local/include/a52dec/mm_accel.h
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/include'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/include'
Making install in doc
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/doc'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/doc'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/doc'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/doc'
Making install in liba52
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/liba52'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/liba52'
/bin/bash ../autotools/mkinstalldirs /usr/local/lib
/bin/bash ../libtool --mode=install /usr/bin/install -c liba52.la /usr/local/lib/liba52.la
/usr/bin/install -c .libs/liba52.lai /usr/local/lib/liba52.la
/usr/bin/install -c .libs/liba52.a /usr/local/lib/liba52.a
ranlib /usr/local/lib/liba52.a
chmod 644 /usr/local/lib/liba52.a
PATH="$PATH:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/liba52'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/liba52'
Making install in libao
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/libao'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/libao'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/libao'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/libao'
Making install in src
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/src'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/src'
/bin/bash ../autotools/mkinstalldirs /usr/local/bin
/bin/bash ../libtool --mode=install /usr/bin/install -c a52dec /usr/local/bin/a52dec
/usr/bin/install -c a52dec /usr/local/bin/a52dec
/bin/bash ../libtool --mode=install /usr/bin/install -c extract_a52 /usr/local/bin/extract_a52
/usr/bin/install -c extract_a52 /usr/local/bin/extract_a52
make install-man1
make[3]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/src'
/bin/bash ../autotools/mkinstalldirs /usr/local/man/man1
/usr/bin/install -c -m 644 ./a52dec.1 /usr/local/man/man1/a52dec.1
/usr/bin/install -c -m 644 ./extract_a52.1 /usr/local/man/man1/extract_a52.1
make[3]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/src'
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/src'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/src'
Making install in vc++
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/vc++'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/vc++'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/vc++'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/vc++'
Making install in test
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/test'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4/test'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/test'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4/test'
make[1]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4'
make[2]: Entering directory `/home/oliver/avchd/src/a52dec-0.7.4'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4'
make[1]: Leaving directory `/home/oliver/avchd/src/a52dec-0.7.4'
Starting ./configure2 script.
Run the compile2 script to compile ffmpeg and mplayer.
The ./configure2 script has ended.
Starting ./compile2 script.
Run the installasroot script as root to install the software in /usr/local/bin
The ./compile2 script has ended.
using:
./xporthdmv
ldecod: Command not found.
MPlayer 1.0rc2-4.2.3 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Pentium(R) 4 CPU 2.66GHz (Family: 15, Model: 2, Stepping: 7)
CPUflags: MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing samplevideo.avi.
File not found: 'samplevideo.avi'
Failed to open samplevideo.avi.
I thought the lack of yasm might be the problem, and tried to install it, so far without success.
macgreg 07-28-08, 03:32 PM Hi,
I just got my sony hdr-sr12, hot off the assembly line.
I took a quick video (48 mb) just to play with for conversion.
When I run it through the m2tstoavi, I end up with a multi-pane fluctuating green video.
I have attached a screen shot.
I get this same output with either the mencoder method or ffmpeg method, so I'm suspect of either the demuxer or ldecoder.
Here are some of the details:
everything installed from the script.
$ xport
xport Transport Stream Demuxer 1.00
$ ldecod
----------------------------- JM 14.1 (FRExt) -----------------------------
Decoder config file : (null)
--------------------------------------------------------------------------
Input H.264 bitstream : test.264
Output decoded YUV : test_dec.yuv
Output status file : log.dec
Input reference file : test_rec.yuv does not exist
SNR values are not available
grammaton76 07-29-08, 12:05 AM Macgreg, I have an SR-10 and had exactly the same problem you had. The information below is a good starting point, but it is not a conclusive fix. I've noticed that although now I don't get the green screen, I do get major macroblock issues shortly into the video and the audio and video don't seem to sync up.
Edit: I've figured out why the blocks show up. Turns out that the m2tstoavi script isn't setting a bitrate explicitly, and mencoder, by default, uses a bitrate which is ok for DVD-resolution things, but it's horrible for HD-resolution video. So, if you don't want to learn mencoder-fu, then simply add "-lavcopts vcodec=mpeg4:vbitrate=12000" into the mencoder line as mentioned below for the resolution fix. You can tack it onto the end if you want. If you intend to edit the video, then you probably should research mencoder options and translate it to a lossless format instead.
The deal is that the resolution is being assumed by m2tstoavi to be 1440x1080, and I had exactly the same screen you had.
My SR-10's files are apparently 1920x1080, because as soon as I editted the /usr/local/bin/m2tstoavi script and changed everywhere I saw:
"mencoder $videofifo -demuxer rawvideo -rawvideo w=1440:h=1080 -aspect 16:9 -ofps 29.97"
to:
"mencoder $videofifo -demuxer rawvideo -rawvideo w=1920:h=1080 -aspect 16:9 -ofps 29.97"
Suddenly my video output changed from that nasty green screen-spasm into exactly what I'd filmed.
I suspect there's a flag somewhere in the video that could be read/parsed in order to allow m2tstoavi to tell what the original resolution was, but it may not be worth the developer's time to change things.
So, all that folks like us with 1920x1080 cameras must do, is edit one line.
Given that the product literature says that the SR-10 has 2.3 effective megapixels, while the SR-11 and SR-12 have 5.6, it's possible that you may still need to adjust your resolution settings. If that's the case, I recommend going to sonystyle.com and looking at the product spec charts. Whatever item is listed as 1920x1080 (probably "effective resolution" or something) on the SR-10, would probably have a higher-res counterpart on the SR-11 or SR-12.
erlander 07-29-08, 07:24 AM Hi,
I'm new here and joined because of this thread. I have just purchased a Sony HDR-SR11E and until I sort out AVCHD its in SD mode.
I'm also very new to ffmpeg and encoding.
I have run the script and get the following code in Ubuntu 8.04:
rob@robs:~/m2ts$ m2tstoavi sample.mts
using:
./xporthdmv
ldecod: Command not found.
What do I need to do to get ldecod?
TIA
Rob
grammaton76 07-29-08, 03:14 PM Hi,
I'm new here and joined because of this thread. I have just purchased a Sony HDR-SR11E and until I sort out AVCHD its in SD mode.
I'm also very new to ffmpeg and encoding.
I have run the script and get the following code in Ubuntu 8.04:
rob@robs:~/m2ts$ m2tstoavi sample.mts
using:
./xporthdmv
ldecod: Command not found.
What do I need to do to get ldecod?
I was just thrashing that out last night myself... here are my notes; not really formatted since they were just for my reference, but obtaining ldecod is covered.
Grr... don't have 3 posts so I can't post URLs. Ok, so just copy the line below into your address bar to see my notes on it.
notes.cheapspeech.com/bin/view/Notes/RefHdCamcorderOnLinux
Now, if someone wants to be real nice to me, maybe they can post an example mencoder command line that'll result in a file which Cinelerra will enjoy trying to import? Right now I'm thrashing around trying to figure out lqt_transcode due to some reading at cinelerra.org/docs/wiki/doku.php?id=supported_file_formats which seems to indicate that most AVI container files (which mencoder seems to work easiest with) aren't going to smell right to cinelerra.
macgreg 07-29-08, 03:16 PM That was the ticket.
I changed my ffmpeg line from 1440 to 1920 and it worked like a charm.
As a side note, I have been kicking myself all day about not noticing that.
What is 1440 anyway? PAL?
Macgreg, I have an SR-10 and had exactly the same problem you had. The information below is a good starting point, but it is not a conclusive fix. I've noticed that although now I don't get the green screen, I do get major macroblock issues shortly into the video and the audio and video don't seem to sync up.
Edit: I've figured out why the blocks show up. Turns out that the m2tstoavi script isn't setting a bitrate explicitly, and mencoder, by default, uses a bitrate which is ok for DVD-resolution things, but it's horrible for HD-resolution video. So, if you don't want to learn mencoder-fu, then simply add "-lavcopts vcodec=mpeg4:vbitrate=12000" into the mencoder line as mentioned below for the resolution fix. You can tack it onto the end if you want. If you intend to edit the video, then you probably should research mencoder options and translate it to a lossless format instead.
The deal is that the resolution is being assumed by m2tstoavi to be 1440x1080, and I had exactly the same screen you had.
My SR-10's files are apparently 1920x1080, because as soon as I editted the /usr/local/bin/m2tstoavi script and changed everywhere I saw:
"mencoder $videofifo -demuxer rawvideo -rawvideo w=1440:h=1080 -aspect 16:9 -ofps 29.97"
to:
"mencoder $videofifo -demuxer rawvideo -rawvideo w=1920:h=1080 -aspect 16:9 -ofps 29.97"
Suddenly my video output changed from that nasty green screen-spasm into exactly what I'd filmed.
I suspect there's a flag somewhere in the video that could be read/parsed in order to allow m2tstoavi to tell what the original resolution was, but it may not be worth the developer's time to change things.
So, all that folks like us with 1920x1080 cameras must do, is edit one line.
Given that the product literature says that the SR-10 has 2.3 effective megapixels, while the SR-11 and SR-12 have 5.6, it's possible that you may still need to adjust your resolution settings. If that's the case, I recommend going to sonystyle.com and looking at the product spec charts. Whatever item is listed as 1920x1080 (probably "effective resolution" or something) on the SR-10, would probably have a higher-res counterpart on the SR-11 or SR-12.
macgreg 07-29-08, 03:31 PM modify the download script change:
# Download jm12.2
#
# Versions change often, so if it fails, just
# change the 12.2 below to whatever is listed at
# iphome.hhi.de/suehring/tml/download
#
set version=12.2
to:
set version=14.1
I ran the install script included in the tarball and it downloaded:
jm14.1.zip
unpacked and compiled it no errors.
Hi,
I'm new here and joined because of this thread. I have just purchased a Sony HDR-SR11E and until I sort out AVCHD its in SD mode.
I'm also very new to ffmpeg and encoding.
I have run the script and get the following code in Ubuntu 8.04:
rob@robs:~/m2ts$ m2tstoavi sample.mts
using:
./xporthdmv
ldecod: Command not found.
What do I need to do to get ldecod?
TIA
Rob
grammaton76 07-29-08, 11:37 PM That was the ticket.
I changed my ffmpeg line from 1440 to 1920 and it worked like a charm.
As a side note, I have been kicking myself all day about not noticing that.
What is 1440 anyway? PAL?
Some cameras are just 1440 instead of 1920, or when they use 1920 it's variable bitrate instead of CBR. Two examples that came up real quick:
www.videodirect.com/Merchant2/merchant.mvc?Screen=PROD&Product_Code=XHA1
www.maximumpc.com/article/jvc_g7hd7_everio_hard_drive_camcorder
erlander 07-30-08, 05:06 AM I'm still not having any luck. I notice problems with dependencies at step 2 of Wes Bailey's HowTo. ie "sudo apt-get install mplayer ffmpeg a52dec mencoder x264 faad faac libfaad2-0 libfaad2-dev subversion csh build-essential"
I have resolved most of them but have had to un-install programs like Cinerella and Kino.
My current plan is to do a clean install of Ubuntu and then see how I go.
I will have to do some backups of data first for safety's sake so will take a day or 2.
Rob
grammaton76 07-30-08, 06:18 AM For what it's worth, I found that the Livna repository presents horrible conflicts under Fedora, but going with freshrpms.net versions of mplayer, etc seems to resolve the conflicts. Of course, in Ubuntu I really can't help you there.
I'm not far off from finishing my sr10tomov script (a mutilated version of m2tstoavi). At present, it's geared towards getting files into cinerella. Useful tip: mplayer can't do anything with the video from a mts file, but it can identify and play OR DUMP the audio just fine. I'm using mplayer in the modified script to copy out the audio to avoid the stereo downmixing.
At present, I've moved from mencoder to transcode (better Quicktime support), but I can't get transcode to stop mutilating my audio. I just want it to pass the 5.1 sound through, but I can't find a single way for it to agree to STOP downmixing it to 2-channel stereo. I should amend that; there's ways to get it to stop trying that, but then it insists that the import and/or export methods don't support it.
However, Cinelerra doesn't seem to mind having a separate 6-channel ac3 file and 1920x1080 Quicktime file.
Other than the annoyance of loading two files instead of one, the only major hitch left is that transcode seems to only want to get the full frame count if I tell it that the video's 120FPS. Of course, Cinelerra reads this and says, "Ok, I'm going to make your 1.7s sample video only .5s long". But if I drop the frame rate to a reasonable number, Transcode decides it's done after 13 or so frames and I'm still stuck with only .5s or so of video. So, I can have either all the frames in .5s or around a quarter of my frames in .5s, but for some reason it seems really hung up on only letting me have .5s or so of video once it reaches Cinelerra.
grammaton76 07-30-08, 09:41 AM Attached, is the sr10tomov script. This modified version of Axel's m2tstoavi is geared towards SR-10 camcorder owners who wish to import their video files into Cinelerra for editing. Edit: I have deleted this older version of the script due to bugs - check farther down in the page for the current version of sr10tomov.
In order to use this script, you should first have Axel's package installed and working, then ensure you've also got ffmpeg installed. There could be other dependencies too, dunno.
Switching to ffmpeg addressed the weird time issue I mentioned one post ago, and also allowed me enough freedom that I was able to get the audio file into the Quicktime container. The resultant file can be loaded into Cinelerra and edited, at least under 2.1-0.14.20080214.fc9 running on Fedora Core 9 on i386.
According to http://cinelerra.org/docs/wiki/doku.php?id=supported_file_formats , the videos this script puts out should be a fairly reasonable format to edit. ffmpeg's output says:
Output #0, mov, to '00040.mts.mov':
Stream #0.0: Video: mpeg4, yuv420p, 1920x1080, q=2-31, 25000 kb/s, 25.00 tb(c)
Stream #0.1: Audio: libfaac, 48000 Hz, 5:1, 448 kb/s
According to the compatibility chart, mpeg4 audio and video in Quicktime files sync well, and are stable. Hopefully that is the case. I will say it syncs fine with my 1.7s sample video, and at present I'm busy rendering a few larger videos (a few minutes each) to see how they do.
By no means do I consider this script to be final or even 'good' yet. It's just there so other SR-10 owners can have a starting point that should at least get the data into Cinelerra in one piece.
BTW, don't run more than one copy of this script in any one directory at a time. The design of ldecod (hardcoded filenames) creates some race conditions that'd mess up batch processing. As long as the scripts are in different working directories, you should be fine.
grammaton76 07-30-08, 03:19 PM Now that I've seen longer samples... frame rate is definitely off, audio is way off sync.
The separate AC3 file is retaining 5.1 surround sound, but the in-mov track isn't - this can probably be fixed fairly easily.
Interestingly enough, all the spec sheets I've read say that the Sony SR-10 is recording in 25FPS. However, based upon the frame-count benchmarks and run-time benchmarks (comparing audio track runtime vs video runtime), it seems that things should match evenly after tweaking ffmpeg to consider the YUV source to be in 29.97fps.
grammaton76 07-31-08, 03:01 PM Next generation of sr10tomov attached. It seems to completely fix audio sync, however it's only including a downsampled AC3 track. It does, however, leave the original AC3 track in the directory, so you can still load it separetely into Cinelerra.
I've tested this with some short (30s) videos taken at a shooting range, and it looks like the gunshots are lining up well with what's supposed to be happening. I'm presently rendering some much longer videos, in order to see if there's a gradual loss of sync later on.
Next project is to get inlined 5.1ch audio, and after that I believe I'm done. Let the torch pass on to the next guy who discovers that Sony has made slight improvements to his camera, vs the previous model. :)
Now that I've seen longer samples... frame rate is definitely off, audio is way off sync.
The separate AC3 file is retaining 5.1 surround sound, but the in-mov track isn't - this can probably be fixed fairly easily.
Interestingly enough, all the spec sheets I've read say that the Sony SR-10 is recording in 25FPS. However, based upon the frame-count benchmarks and run-time benchmarks (comparing audio track runtime vs video runtime), it seems that things should match evenly after tweaking ffmpeg to consider the YUV source to be in 29.97fps.
We have seen this behavior before, and I think someone in this thread might have mentioned it. It seems as though (on occasion) PAL cameras are winding up in NTSC locations and vice versa. If you can upload a sample (to a personal site or sharing site), I can take a look at it if you want.
Has anybody tried this on a PS3 running linux?
grammaton76 08-20-08, 08:31 PM We have seen this behavior before, and I think someone in this thread might have mentioned it. It seems as though (on occasion) PAL cameras are winding up in NTSC locations and vice versa. If you can upload a sample (to a personal site or sharing site), I can take a look at it if you want.
Interesting. I kind of doubt it was a wrong-territory camera, given that it was purchased at an official Sony store. But, I'll attempt to get a sample uploaded somewhere for your inspection.
grammaton76 08-20-08, 08:33 PM Has anybody tried this on a PS3 running linux?
I'm sure it would work, assuming that ffmpeg and such are available for it. However, I don't think the codecs are particularly optimized for multi threaded operation, which is probably why using a PS3 would be so desirable.
Inquisitive Alex 09-10-08, 01:46 PM Hello. I tried to run m2tstoavi and had the following error:
using:
/usr/local/bin/xporthdmv
ldecod: Command not found.
Where can I get ldecod?
Hi there Alex,
ldecod is part of the jm package. The newest version seems to be 14.2. If you use the original m2ts package you need to change the version in 'download' file ('set version=14.2').
I hope this helps.
sharan4o 09-20-08, 03:59 AM hi,
i'm using m2tstoavi with ubuntu 8.04. Compiling went well and the testfile was converted successfully.
Then I tried to convert a 14GB file and the result was:
./m2tstoavi /media/sdc2/Tierra.La.Pelicula.de.Nuestro.Planeta.Blu-ray.1080p.VC-1.DD5.1-GrupoHDS/BDMV/STREAM/00004.m2ts
using:
./xporthdmv
./ldecod
/usr/bin/ffmpeg
./m2tstoavi Starting.
file /media/sdc2/Tierra.La.Pelicula.de.Nuestro.Planeta.Blu-ray.1080p.VC-1.DD5.1-GrupoHDS/BDMV/STREAM/00004.m2ts not found
any ideas?
I wrote a testscript and the result was true. Something wrong with csh?
#!/bin/bash
if [ -f $1 ]
then
echo true
else
echo false
fi
hi,
i'm using m2tstoavi with ubuntu 8.04. Compiling went well and the testfile was converted successfully.
Then I tried to convert a 14GB file and the result was:
any ideas?
I wrote a testscript and the result was true. Something wrong with csh?
Not sure, but it may be because you are trying to convert copyrighted material.
Try running each individual step to see where things are failing.
Galaxydriver 10-11-08, 06:00 AM Hello,
I'm new here.
I've installed the files and everything works fine.
Due to a better qualitiy of my videos I want to covert my the mts-files with m2tstoavi.fifo.
The quality is much better, but the converted video is very very slow. Well it's hardly to belive it's a video-file. If I don't know it - I'd thougt it's a picture-slide-show..
Maybe I have to change the bitrate, but I don't know where I have to change it..?
Audio is ok.
BTW: I've chaged in m2tstoavi.fifo the line:
ffmpeg -r 29.97 -s 1440x1080 -vcodec mpeg4 -sameq -i $videofifo \
into:
ffmpeg -r 29.97 -s 1920x1080 -vcodec mpeg4 -sameq -i $videofifo \
Does anyone have any solution for this problem?
cu
Chris
grammaton76 10-22-08, 06:17 PM With the superfast and high-quality m2ts converter (http://www.m2tsconverter.net) can convert M2TS files to so many other formats. What' more, this M2TS Converter has powerful editing function, you can crop, trim the video and customize video effect and merge the video into a file.
Unless there's a Linux version of this application which is not being advertised on the page I loaded (which was ONLY a Windows app as far as I can tell), the quoted post is irrelevant spam to this thread.
krudl3r 11-14-08, 06:55 PM Not to encourage spamming of this thread, but if it worked under Wine I'd be willing to pay for a windows app that did the job well, as I am having problems with the script...
Hello,
...
BTW: I've chaged in m2tstoavi.fifo the line:
ffmpeg -r 29.97 -s 1440x1080 -vcodec mpeg4 -sameq -i $videofifo \
into:
ffmpeg -r 29.97 -s 1920x1080 -vcodec mpeg4 -sameq -i $videofifo \
Does anyone have any solution for this problem?
The resolution entirely depends on how you originally captured the video. The first generation cameras that Axel and I have were only able to capture at 1440x1080. Current generation cameras cam capture at both 1920 and 1440, so you need to adjust the "-s" flag accordingly.
With the superfast and high-quality m2ts converter (http://www.m2tsconverter.net) can convert M2TS files to so many other formats. What' more, this M2TS Converter has powerful editing function, you can crop, trim the video and customize video effect and merge the video into a file.
I agree with grammaton76. This looks a little suspect.
massi888 11-19-08, 03:54 PM Hello. I tried to run m2tstoavi and had the following error:
using:
/usr/local/bin/xporthdmv
ldecod: Command not found.
Where can I get ldecod?
Hi there Alex,
ldecod is part of the jm package. The newest version seems to be 14.2. If you use the original m2ts package you need to change the version in 'download' file ('set version=14.2').
I hope this helps.
this help very well! Now m2toavi is working on my hardy ubuntu linux system!
Thanks a lot!
jtappin 11-30-08, 06:43 PM The resolution entirely depends on how you originally captured the video. The first generation cameras that Axel and I have were only able to capture at 1440x1080. Current generation cameras cam capture at both 1920 and 1440, so you need to adjust the "-s" flag accordingly.
A convenient modification if you have a camera that does both (e.g. the Sony SR11) is near the start of the script to add:
if ( $#argv == "0" ) then
echo usage: $0 filename.m2ts ...
exit
else
if ("$1" == '-h') then
set xsz = 1920
set aspect = "16:9"
shift
else if ("$1" == '-l') then
set xsz = 1440
set aspect = "4:3"
shift
else
set xsz = 1440
set aspect = "4:3"
endif
set files=($*)
endif
in place of:
if ( $#argv == "0" ) then
echo usage: $0 filename.m2ts ...
exit
else
set files=($*)
endif
And the modify the ffmpeg line to read:
ffmpeg -r 29.97 -s ${xsz}x1080 -vcodec mpeg4 \
-sameq -i $videofifo -aspect ${aspect} \
-acodec mp3 -i $audiofile -b 15000k \
$outputfile || exit 1
jtappin 11-30-08, 07:37 PM A couple of months ago I had m2tstoavi working fine, with the mods I described in an earlier post (including changing the audio codec to mp3 from copy as xine couldn't play the DVM sound). However when I tried it again today, I get an error:
Input #0, rawvideo, from '/tmp/00006.yuv':
Duration: N/A, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 1920x1080, 29.97 fps(r)
Input #1, ac3, from '/tmp/00006.ac3':
Duration: 00:00:11.9, start: 0.000000, bitrate: 256 kb/s
Stream #1.0: Audio: 0x0000, 48000 Hz, stereo, 256 kb/s
Output #0, avi, to '00006.avi':
Stream #0.0: Video: mpeg4, yuv420p, 1920x1080, q=2-31, 15000 kb/s, 29.97 fps(c)
Stream #0.1: Audio: pcm_s16le, 48000 Hz, stereo, 1536 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Unsupported codec (id=86020) for input stream #1.0
As far as I can make out, it looks as if ffmpeg is no longer able to convert DVM input streams -- has anyone else seen anything similar and if so is there a fix.
I'm using Kubuntu Hardy (not yet ready for KDE4), with the ffmpeg from the repositories.
Your best bet is to compile ffmpeg from subversion source.
jtappin 12-03-08, 09:53 PM Your best bet is to compile ffmpeg from subversion source.
When I did that, I just got an Mpeg4 header error for each and every data frame (sorry I don't have the exact errors) -- I may try that option again but on my "crash & burn" machine.
babyshake 12-06-08, 03:27 PM Using a couple variations of the script, I can't get past this error:
"Failed to open audio demuxer: samplevideo.ac3"
The video works fine, but I can never get audio.
However, the samplevideo.ac3 in /tmp/ sounds just fine. Why can't it demux?
This sounds like you configured ffmpeg incorrectly.
UberBock 12-06-08, 07:48 PM I had the same problem. When I used m2tstoavi.fifo to convert an MTS from my HF10 I got damaged header error for each frame. I previously was able to convert these MTS files in 8.04 without a problem. But this is in 8.10. m2tsoavi doesn't have this same problem.
<sarcasm>Thanks for the advertisement.</sarcasm> Oh, wait. It looks like 12 of your 13 posts are all advertisements for this program... that does not run on linux.
Maybe you missed the point that this is a thread for Linux and Macs.
jtappin 12-15-08, 07:11 PM I had the same problem. When I used m2tstoavi.fifo to convert an MTS from my HF10 I got damaged header error for each frame. I previously was able to convert these MTS files in 8.04 without a problem. But this is in 8.10. m2tsoavi doesn't have this same problem.
As set up in the standard scripts, m2tstoavi uses mencoder, but m2tstoavi.fifo uses ffmpeg.
The BIG problem I've had using mencoder is that I can't get the audio & video to sync, the video is running about 20% slow (as estimated by videoing my watch and calling out the seconds every 5 seconds). This is supported by the report at the end with gives the durations of the audio as about 30s and of the video as about 37s.
FWIW: handbrake looks to have the same problem.
jtappin 12-19-08, 07:02 PM The BIG problem I've had using mencoder is that I can't get the audio & video to sync, the video is running about 20% slow (as estimated by videoing my watch and calling out the seconds every 5 seconds). This is supported by the report at the end with gives the durations of the audio as about 30s and of the video as about 37s.
It looks as if mencoder was assuming an input rate of 25fps, adding -fps 29.97 as well as -ofps 29.97 in the mencoder command pretty much clears it up. I'm not sure that it's perfect yet but it's certainly much better.
It looks as if mencoder was assuming an input rate of 25fps, adding -fps 29.97 as well as -ofps 29.97 in the mencoder command pretty much clears it up. I'm not sure that it's perfect yet but it's certainly much better.
I am not too familiar with mencoder, but 29.97 is a poor approximation of the NTSC frame rate. If you have a very large movie, A/V will get out of sync.
jtappin 12-20-08, 09:26 AM It looks as if mencoder was assuming an input rate of 25fps, adding -fps 29.97 as well as -ofps 29.97 in the mencoder command pretty much clears it up. I'm not sure that it's perfect yet but it's certainly much better.
FWIW here is a copy of the version of m2tstoavi.fifo that I'm using right now. It uses mencoder as the encoder, and has a -h option for 1920x1080 inputs, 1440x1080 is the default. Use at your own risk, modify it if you need to.
[The extra .txt extension was added to keep the attachment manager happy].
squashbrain 12-23-08, 09:43 AM Hello all,
I just wanted to post my enhanced version of m2tstoavi.fifo file. I have a Canon
Vixia HF-10 and wanted to have just one command to execute to get all the videos
off the camera as well as convert them using m2tstoavi. I would like to thank
jtappin for his bit of code that I used that allows me to select different resolutions
at the command line. I also noticed a bug or 2 in the original m2tstoavi. One of
them was the following at the bottom...
rm -f $videofifo
rm -f $audiofile
This needed to be in the main foreach loop so that each temp file gets
deleted. Otherwise only the last *.yuv and *.ac3 files in the /tmp directory are deleted.
This could be a disk space issue if you are running m2tstoavi.fifo for multiple .MTS files.
OK, so here is my enhanced versions of 2 of the original files.
First is hdrsr1cp. The only thing I changed was ...
set sourcedir=/media/CANON/AVCHD/BDMV/STREAM
for the Canon Vixia HF-10 and HF-100
Second was m2tstoavi.fifo
#!/bin/csh -f
#The scripts and instructions in this package are free to use and
#redistribute AT YOUR OWN RISK!! Standard disclaimers apply.
#NO WARRANTY!
if ( $#argv == "0" ) then
echo usage: $0 filename.m2ts ...
exit
else
if ("$1" == '-h') then
set xsz = 1920
set aspect = "16:9"
shift
else if ("$1" == '-l') then
set xsz = 1440
set aspect = "4:3"
shift
else
set xsz = 1440
set aspect = "4:3"
endif
#set files=`find $* -name "*.m2ts"`
endif
set path = ( . $path )
set camerasourcedir=/media/CANON/AVCHD/BDMV/STREAM
echo using:
which xporthdmv || exit
which ldecod || exit
which ffmpeg || exit
which hdrsr1cp || exit
echo $0 Starting.
echo " "
# if camera is found, ask for importing
if (-d $camerasourcedir) then
echo "Your camera connection has been detected. Import Videos? [y/n]:"
set doimport = $<
switch ($doimport)
case [yY]:
echo Starting import from camera...
./hdrsr1cp
echo Import complete.
breaksw
default:
breaksw
endsw
endif
echo Starting video conversion...
set files=`find $* -name "*.m2ts"`
foreach file ($files)
if ( ! -f $file ) then
echo file $file not found
exit
endif
set filebase=`basename $file | sed s/\.m2ts// | sed s/\.MTS//`
set outdir=`dirname $file`;
set audiofile=/tmp/$filebase".ac3"
set videofifo=/tmp/$filebase".yuv"
set outputfile=$outdir/$filebase".avi"
if ( ! -f $outputfile ) then
if ( ! -f $audiofile ) then
echo xporthdmv -hn $file 1 1 1
xporthdmv -hn $file 1 1 1 && mv bits0001.mpa $audiofile
else
echo $audiofile already exists, not creating it.
endif
mkfifo $videofifo
echo ldecod -i bits0001.mpv -o $videofifo
ldecod -i bits0001.mpv -o $videofifo &
echo ffmpeg -r 29.97 -s ${xsz}x1080 -vcodec mpeg4 \
-sameq -i $videofifo -aspect ${aspect} \
-acodec mp3 -i $audiofile -b 15000k \
$outputfile || exit 1
ffmpeg -r 29.97 -s ${xsz}x1080 -vcodec mpeg4 \
-sameq -i $videofifo -aspect ${aspect} \
-acodec mp3 -i $audiofile -b 15000k \
$outputfile || exit 1
else
echo $outputfile:t exists, not creating it.
endif
# remove intermediate files
rm -f $videofifo
rm -f $audiofile
end
#echo To remove temporary files: rm -f /tmp/*.ac3 /tmp/*.yuv
#rm -f ./dataDec.txt ./log.dec bits0001.mpv $videofifo $audiofile
rm -f ./dataDec.txt
rm -f ./log.dec
rm -f bits0001.mpv
echo $0 complete.
OH!!! I almost forgot, I also changed the script so that It saves the output AVI files onto the same directory as the input m2ts files. This was simply for convenience.
I hope this can help someone.
Thanks Axel for great conversion scripts.
MasterCLC 12-28-08, 01:08 PM Hello,
So I want to have transcoded video that has audio in sync too! I'm on Gentoo and ldecod doesn't seem to be an available package. I'd be happy to compile it from source, but I'd first like to find out if I really need it. I have been able to successfully transcode using mencoder or ffmpeg but both result in video with the audio way out of sync. Here's the command I'm using:
/usr/bin/mencoder $1 -o $1-DVD.avi -fps 60 -ofps 60 -oac mp3lame -lameopts br=256 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:v4mv:cbp:vbitrate=4000 -vf yadif=1,scale=854:480
I use ls | xargs -n1 to pipe each file into the script.
From some of the posts in this thread I am starting to think it's my -fps and -ofps value that may be causing this, and if so, how do I find out what I should be using or what works?
Also, I get a repeating message during the encoding process:
Pos: 15.0s 645f (72%) 13.36fps Trem: 0min 7mb A-V:0.004 [2870:255]
Too many video packets in the buffer: (132 in 8405941 bytes).
Maybe you are playing a non-interleaved stream/file or the codec failed?
For AVI files, try to force non-interleaved mode with the -ni option.
If I switch that on (-ni) then the message goes away but my audio still remains out of sync. It also doesn't throw up that warning until about 40-70% of the video has been encoded.
Any thoughts would be appreciated.
My camera is a Canon HF-100.
-Chad
jtappin 12-30-08, 11:03 AM Hello,
So I want to have transcoded video that has audio in sync too! I'm on Gentoo and ldecod doesn't seem to be an available package. I'd be happy to compile it from source, but I'd first like to find out if I really need it. I have been able to successfully transcode using mencoder or ffmpeg but both result in video with the audio way out of sync. Here's the command I'm using:
/usr/bin/mencoder $1 -o $1-DVD.avi -fps 60 -ofps 60 -oac mp3lame -lameopts br=256 -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell:v4mv:cbp:vbitrate=4000 -vf yadif=1,scale=854:480
Does your camera really work at 60 frames per second?
Try changing the -fps and -ofps settings to 29.97 or 30000/1001 and see what happens then.
Essentially, all these conversion tools handle the video and audio streams separately, and so if either the video frame rate or the audio sampling rate is incorrect then the streams will drift apart.
Does your camera really work at 60 frames per second?
Try changing the -fps and -ofps settings to 29.97 or 30000/1001 and see what happens then.
Essentially, all these conversion tools handle the video and audio streams separately, and so if either the video frame rate or the audio sampling rate is incorrect then the streams will drift apart.
Going along with this, remember that 60fps is not a real frame rate. There are a few AVCHD cameras that do "30p" or "60p" (depending on marketing) but those values are really 59.94. More accurately 60000/1001.
alecmuffett 01-07-09, 04:47 PM Hi Guys,
I junked Axel's script and wrote a new one which only needs a recent-ish FFMPEG to work, and which can take greater advantage of multi-processor machines.
Unfortunately since I am new here, I can't paste a link - argh. :eek:
The project / download is at: code.google.com/p/hdffxvrt/ and there is a link off that home page to the blog posting.
- alec
Hi Guys,
I junked Axel's script and wrote a new one which only needs a recent-ish FFMPEG to work, and which can take greater advantage of multi-processor machines.
Unfortunately since I am new here, I can't paste a link - argh. :eek:
The project / download is at: code.google.com/p/hdffxvrt/ and there is a link off that home page to the blog posting.
- alec
I will be away for a few days, but I will take a look at your scripts. On the surface it looks fine as long you are a PAL user. I might add a few extra flags to improve quality. You might want to update the crypticide link to point to here rather than Vimeo. And no love for me, the mac guy? ;)
alecmuffett 01-08-09, 05:01 AM Hiya!
Yeah, I intend to update the script once I have a few "friends" who can send me samples of material from other cameras - ones which are non-interlaced, have square pixels, are NTSC, and so forth.
Then new/extra/PAL/NTSC commandline options will be forthcoming. I won't release code that I cannot test somehow. :-)
Any quality-improvement tweaks you can suggest will be gratefully considered; after much much pain I have concluded that the only sane way to proceed was add the "complex" options to the backend (re-encoding) of the pipeline - processing otherwise "raw" input; attempting cleverness on the input side of the pipeline seems to involve much greater pain.
- alec :-)
alecmuffett 01-08-09, 05:09 AM Plus: I must say thanks, 0ctane - I read a lot of your stuff in pursuit of solving this problem, and learned/inferred heaps about how things work.
alecmuffett 01-08-09, 05:17 AM Now I have done 3 posts, the URLs should work:
hdffxvrt (HD FFmpeg-based Convert) is available on Google Code at:
http://code.google.com/p/hdffxvrt/
Issues and feature requests can be registered at:
http://code.google.com/p/hdffxvrt/issues/list
...and the blog post where it is announced is at:
http://www.crypticide.com/dropsafe/article/2657
If folks with AVCHD camcorders would like to contact me about getting hdffxvrt to work for their camera configuration, please leave a comment on the blog above and I will be in touch.
I am particularly interested in getting short (15 second?) samples of
1920x1080i PAL
1920x1080i NTSC
1920x1080p PAL
1920x1080p NTSC
1440x1080i NTSC
...which I think would give me the complete set? Does anyone do 1440x1080p?
Thanks, all.
- alec
h-munster 01-09-09, 04:21 PM Hello,
Thanks to all who are helping to make AVCHD files work on Linux.
I slightly modified Alec's hdffxvrt script to work with the 1920x1080i files from my NTSC, Canon HF11 (set to 24P).
Basically, I changed the "isize" setting to 1920x1080, I changed both the "irate" and "orate" settings to 60000/1001, and I replaced the "$irate2" variable with plain "$irate" in the ffmpeg command section of the script.
Here is the resulting ffmpeg command produced by the script (not sure if I'm properly notating the intermediate video file and the piping):
ffmpeg -y -i input_file.mts -an -pix_fmt yuv420p -f rawvideo - | ffmpeg -y -i /var/tmp/temp_audio_file.wav -r 60000/1001 -deinterlace -s 1920x1080 -pix_fmt yuv420p -f rawvideo -i - -r 60000/1001 -s 1280x720 -vcodec mpeg4 -sameq -shortest -f mov -acodec libfaac -ac 2 -ab 128k -ar 44100 output_file.mov
It worked wonderfully, but I need to be able to send footage for viewing to clients who use Windows, so I replaced all ".mov" references in the script with ".avi" and tried it. Unfortunately, the video played faster than the audio after this modification. any suggestions for a remedy would be appreciated.
The original mts file and the mov and avi files along with the modified scripts are all available for download here: marks.org/avchd/
I'll keep the files up for a few weeks. I would be happy to shoot test files that anyone might need and post them, too.
In regards to improvements for hdffxvrt, it might be useful to be able to independently specify (with arguments/options) frame rates, input/output frame size, output file names, etc. Of course, any flags that would improve image quality would be welcome.
Please keep up the great work!
-Dale
alecmuffett 01-09-09, 05:34 PM Dale - is there any chance you could supply me a short clip - 10 to 30 seconds - which I could play with ? Is there somewhere you could post such a thing that I might retrieve it?
I would like to get your requirements properly implemented, with commandline switches, etc...
update: whoops, just noticed the URL - I will go pull and have a look, may not be able to get updates until monday.
A short clip would still be welcomed - something where i can see the sound going out of sync :-)
ps: after much experimentation I have decided I rather like:
input.mts -> input.mts.SIZE.mov
as a file naming convention; itīs flexible and makes locking easy.
Is this a problem?
alecmuffett 01-09-09, 06:02 PM thought: do you really want 60000/1001 as an OUTPUT?
UPDATE: Also I ran:
$ ffmpeg -i 00053med.avi
[...]
Seems stream 0 codec frame rate differs from container frame rate: 60000.00 (60000/1) -> 59.94 (60000/1001)
...which is curious; maybe the output rates for AVI are constrained? Or there is a mismatch with the AVI container which needs cleaning up?
(as you may have guessed I am not experienced in AVI :-))
h-munster 01-10-09, 02:39 AM Alec,
I would be happy to shoot a clip that has more discernable visual/sound action. In the next few days, I'll try to get a pretty girl to count and clap while the camera rolls.
The file naming scheme that you like is fine. I was just thinking that it might be convenient to make available a switch that would allow one to tailor the file names to one's liking (especially if one doesn't need the file "locking.)"
After reading your question about output frame rates, I also tried output frame rates of 24000/1001, 30000/1001 and 23.98, with the ".mov" version of hdffxvrt.
The overall frame flicker is more noticeable with the output rates of 24000/1001 and 23.98, but the moire' flicker within the harp strings is slower and more pronounced with the 60000/1001 rate. The 30000/1001 rate seems to be a happy "medium" for this clip.
I also ran "ffmpeg -i" on all of these different ".mov" files, and, in each case, there is a mismatch between the "stream 0 codec" frame rate and the container frame rate. So, it seems that this discrepancy is not specific to AVI.
The 30000/1001 file exhibits a 30000 stream 0 codec rate, and the 24000/1001 has a 24000 stream 0 codec frame rate. Curiously, the 23.98 file shows a 1199 stream 0 codec frame rate.
h-munster 01-15-09, 03:10 PM Alec,
Sorry for the delay.
I made a file of a girl counting and clapping. It can be found at:
marks.org/avchd/
The file is "00106.mts" and it is about 69Mb.
Again, this was shot on my Canon HF11, set a FP24 (24fps) but recorded at 60i (60000/1001fps?).
Thanks,
-Dale
kilimano 01-20-09, 08:17 PM After many hours I got a version of the fifo script to run without errors. But am still not sure that the created avi file is good because subsequent testing of the avi file indicates that the stream frame rate is different from the container frame rate.
I manually compiled and installed xporthdmv and ldecod because I already had mplayer and ffmpeg from SUSE 11.1. I should also mention that my camera is a Cannon Vixia HF100. Here are the basic commands that the script does:
xporthdmv -h 2009-01-05-21-13-32.m2ts 1 1 1
mv bits0001.mpa /tmp/2009-01-05-21-13-32.ac3
ldecod -i bits0001.mpv -o /tmp/2009-01-05-21-13-32.yuv
Here is the ffmpeg command and the output:
ffmpeg -r 29.97002997 -s 1440x1080 -i /tmp/2009-01-05-21-13-32.yuv -i /tmp/2009-01-05-21-13-32.ac3 -vcodec mpeg4 -sameq -acodec copy -aspect 4:3 -b 15000k 2009-01-05-21-13-32.avi
FFmpeg version SVN-r16240, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --shlibdir=/usr/lib --prefix=/usr --mandir=/usr/share/man --libdir=/usr/lib --enable-shared --enabl
e-libmp3lame --enable-libvorbis --enable-libtheora --enable-libfaad --enable-libfaac --enable-libxvid --enable-swsca
le --enable-postproc --enable-gpl --enable-vhook --enable-x11grab --enable-libschroedinger --enable-libdirac --enabl
e-libgsm --enable-libx264 --enable-libamr-nb --enable-libamr-wb --enable-libdc1394 --enable-nonfree --enable-pthread
s
libavutil 49.12. 0 / 49.12. 0
libavcodec 52. 7. 0 / 52. 7. 0
libavformat 52.23. 1 / 52.23. 1
libavdevice 52. 1. 0 / 52. 1. 0
libswscale 0. 6. 1 / 0. 6. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Dec 19 2008 20:23:44, gcc: 4.3.2 [gcc-4_3-branch revision 141291]
Input #0, rawvideo, from '/tmp/2009-01-05-21-13-32.yuv':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0.0: Video: rawvideo, yuv420p, 1440x1080, 29.97 tb(r)
Input #1, ac3, from '/tmp/2009-01-05-21-13-32.ac3':
Duration: 00:00:48.00, bitrate: 256 kb/s
Stream #1.0: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
Output #0, avi, to '2009-01-05-21-13-32.avi':
Stream #0.0: Video: mpeg4, yuv420p, 1440x1080 [PAR 1:1 DAR 4:3], q=2-31, 15000 kb/s, 29.97 tb(c)
Stream #0.1: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #1.0 -> #0.1
Press [q] to stop encoding
frame= 1440 fps= 28 q=0.0 Lsize= 149167kB time=48.00 bitrate=25457.8kbits/s
video:147587kB audio:1500kB global headers:0kB muxing overhead 0.053214%
The created avi file plays with mplayer but I still wanted to prove that it was good so i tried the following ffmpeg command to null:
ffmpeg -v 5 -i 2009-01-05-21-13-32.avi -f null -
(... redundant output omitted...)
Seems stream 0 codec frame rate differs from container frame rate: 30000.00 (30000/1) -> 29.97 (30000/1001)
Input #0, avi, from '2009-01-05-21-13-32.avi':
Duration: 00:00:48.04, start: 0.000000, bitrate: 25432 kb/s
Stream #0.0, 1001/30000: Video: mpeg4, yuv420p, 1440x1080 [PAR 1:1 DAR 4:3], 1/30000, 29.97 tb(r)
Stream #0.1, 4/125: Audio: ac3, 48000 Hz, stereo, s16, 256 kb/s
Output #0, null, to 'pipe:':
Stream #0.0, 1/90000: Video: rawvideo, yuv420p, 1440x1080 [PAR 1:1 DAR 4:3], 1001/30000, q=2-31, 200 kb/s, 29.97
tb(c)
Stream #0.1, 1/90000: Audio: pcm_s16le, 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
Stream #0.0 -> #0.0
Stream #0.1 -> #0.1
Press [q] to stop encoding
frame= 1440 fps= 99 q=0.0 Lsize= -0kB time=48.00 bitrate= -0.0kbits/s dup=0 drop=0
video:0kB audio:9000kB global headers:0kB muxing overhead -100.000239%
Why is the stream codec frame rate different from the container frame rate? Does this mean that there is a problem with the avi file? I did some research on this message but didn't find anything helpful.
Thanks.
Rather than "-r 29.97002997", have you tried "-r ntsc"? The rate you specified is an approximation of 30000/1001 but is not the true frame rate.
linuxcrypt 01-21-09, 08:12 AM I found a nice tip on the ubuntuforums, I can't post the link as it thinks I'm a spammer because I'm new to this site.
Essentially it uses one command, and it worked great, I just tried it this morning.
as root or sudo:
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
./configure
make
make install
Then
mencoder 00001.MTS -o 1.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=10000 -fps 50 -vf scale=1280:720
Worked like a champ for me. I hope this helps!
h-munster 01-21-09, 03:22 PM @kilimano
Thank you for the info.
I have a Canon HF11. I get the same error message saying the stream codec frame rate differs from the container frame rate, using Alec's hdffxvrt script. However, in my case, it doesn't appear with just AVI encoding -- it also appears with Quicktime encoding.
I have tried changing frame rate variable (60000/1001, 30000/1001, 59.94, 29.97, etc). If I specify an input rate of 30000/1001 or 29.97, I get slow motion video. On the other hand, an input rate of 60000/1001 or 59.94 yields video at the proper speed. These results seem to contradict ffmpeg's assessment of the original footage as 29.97, but Canon says that the HF11 records footage at 60i.
Also, when I try to make AVIs with any of these settings, the video is always slow motion. However, the Quicktime files are fine.
I have not tried to specifying "ntsc," as Octane suggested (thanks!), and I have not tried just omitting the input and/or output frame rate.
If you are able to eliminate the error message please post an update.
By the way, doesn't the Canon HF100 capture at full 1920x1080? If so, when did your footage become 1440x1080? The transformation appears to have occurred prior to the ffmpeg command, because ffmpeg shows the input stream at 1440x1080.
@linuxcrypt
The mencoder tip is appreciated. It would be great to be able to use this simple command and to add other mencoder filters to make extra tweaks!
Is this the forum you were trying to link?: http://ubuntuforums.org/showthread.php?t=1045153&highlight=avchd+to+avi
I think that new members can post links merely by excluding the "www" or "http" prefix:
ubuntuforums.org/showthread.php?t=1045153&highlight=avchd+to+avi
-Dale
linuxcrypt 01-21-09, 06:23 PM @h-munster
Yup, that sure enough was the link. I'll remember that trick when posting links :)
If you have any other cool findings let me know.
When I use that mencoder command, I actually changed the "50" for fps to "65" to kind of make up the difference. Otherwise, my exported .avi would come out with the audio and video slightly off sync. I'm still working with it, but for a quick and easy solution it's working quite well.
kilimano 01-22-09, 07:32 PM I have a comment for everyone. Isn't the frame rate for 30p and 60i the same? 30p means 30 progressive non-interlaced video fields for a frame rate of 29.97. 60i means 60 interlaced video fields (two on top of each other) for a frame rate of 29.97. So, the frame rate for 30p and 60i is the same. I don't think this has been made clear in this thread. See the wikipedia definition for "frame rate". Somebody correct me if I am wrong.
60i (actually 59.94, or 60 x 1000/1001 to be more precise; 60 interlaced fields = 29.97 frames) is the standard video field rate per second that has been used for NTSC television since 1941, whether from a broadcast signal, rented DVD, or home camcorder. (When NTSC color was introduced, the older rate of 60 fields per second was reduced by a factor of 1000/1001 to avoid interference between the chroma subcarrier and the broadcast sound carrier.)
This quote might also explain why the real frame rate is a little less than stated rate (30 verses 29.97). It is the reduction factor of 1000/1001.
Rather than "-r 29.97002997", have you tried "-r ntsc"? The rate you specified is an approximation of 30000/1001 but is not the true frame rate.
Using -r ntsc did not make any difference. My avi file still has a difference between the codec frame rate and the container frame rate (see my previous post). Does any one know if this is just an ffmeg warning or does it mean that there is a problem with the video?
By the way, doesn't the Canon HF100 capture at full 1920x1080? If so, when did your footage become 1440x1080?
The Canon HF100 has 4 video recording quality modes ( LP SP XP+ FXP). Only FXP records at 1920x1080. All others are at 1440x1080. The video I was processing was recorded at 1440x1080. The size did not change.
Okay, this is getting a bit off topic, but I would like to see your source that says those values are stored in the AVC stream. Framerate and aspect ratio are stored, of course. Have you spent any time looking at the transport stream? Can you find a date and time? Can you find any of those other values?
... well not all of them. just the date and time. for the beginning and the end of the clip. well to be honest, the information is in about every 1000 packet of the stream, but i analyze only the first 100 one to get the beginning and the last 100 one to get the endstamp.
at least this is true for my canon hg-20. tomorrow i'll check my program against a hf-100 and a hf-10.
h-munster 03-04-09, 11:09 PM Making a little progress.
My slight modification to Alec's script works, but ffmpeg doesn't have a lot of filters. I am often shooting 24P on my Canon HF11, so I need a good pull-down removal filter. The hdffxvrt script can't really remove the Canon 24P pull-down -- it just duplicates and drops frames and deinterlaces the video.
The best, open-source pull-down removal filter that I have found for my HF11 24P footage is the "detc" filter in mencoder.
I also need to be able to give files to editors that they can use in Final Cut Pro, and ffmpeg is great for converting formats.
So, the procedure I am trying now is to remove the 24P pull-down in mencoder, and, then, I use ffmpeg to convert the resulting file to the Quicktime format at the desired bitrate.
Here is the mencoder command:
mencoder canon_24p_footage.mts -fps 60000/1001 -oac pcm -demuxer lavf -vf detc,softskip -ofps 24000/1001 -ovc lavc -lavcopts vcodec=ffvhuff:format=YV12:vstrict=-1:aspect=16/9 -o intermediate_file.avi
And I follow-up with this ffmpeg command:
ffmpeg -i intermediate_file.avi -vcodec mpeg4 -b 35000k -f mov -acodec copy final_quicktime_file.mov
Then I remove the intermediate file.
A test run is posted at http://marks.org/avchd/ The test file is ffmpeg05.mov (The original Canon AVCHD footage is also posted on this page -- 00053.mts).
I am doing this manually. It will probably get tedious and time consuming when there are a lot of files to convert. If someone is good at making scripts, I would welcome any help in writing one for this procedure.
In addition, I wonder if it is better/cleaner to use the raw video format in mencoder and, then, pipe that result into ffmpeg.
I was unable to achieve the 35 Mb/s bitrate -- is that a Quicktime limitation? The Canon HF11 AVCHD footage was recorded at 24Mb/s. I would like to encode at 35Mb/s into a format that can be used in Final Cut Pro.
Should I make a 2-pass run of the mencoder command? ... or a 2-pass ffmpeg command?
Any opinions and suggestions are appreciated.
By the way, I also made a smaller AVI file with this method and posted it on the same page (above): "
ffmpeg07.avi".
This message was also posted in a related thread here: https://www.blogger.com/comment.g?blogID=8012505786049526776&postID=7840880571555486167&page=1
Thanks,
-Dale
I also need to be able to give files to editors that they can use in Final Cut Pro, and ffmpeg is great for converting formats.
Under openSUSE-11.1 Linux, I tried playing your files with ffplay on 3 different PCs, and also tried edit/rendering them with kdenlive. I made a note of my efforts here:
http://www.avsforum.com/avs-vb/showthread.php?p=15976985#post15976985
In essence, play back of the raw file was poor on all 3 PCs (with an 11-Feb svn version of ffmpeg) but editing/rendering them with the NLE kdenlive worked fine (in a limited test - I tried a few output formats).
h-munster 03-05-09, 03:38 PM Under openSUSE-11.1 Linux, I tried playing your files with ffplay on 3 different PCs, and also tried edit/rendering them with kdenlive.
Thank you for your help.
I am glad to know about the ffplay capability. On my machine, ffplay stutters (both video and audio) with the Canon AVCHD footage. I have ffplay/ffmpeg version SVN-r1639, and I have an Athlon dual 4000 (but it seems to be running at 1Ghz!). Mplayer doesn't play the AVCHD video at all, but gives smooth audio.
Can you play the Canon AVCHD footage with Mplayer?
Unfortunately, I think it would be futile to try to convince my Final Cut Pro editors to switch to kdenlive. In addition to needing a usable format for those FCP users, I am trying to do the remove the Canon FP24 pull-down, and I don't see that capability anywhere in kdenlive (my version is 0.7.2.1).
I am also grateful that your post made me check the stats in my /proc/cpuinfo. I need to find out why I am running at only 1Ghz.
Thanks,
-Dale
Can you play the Canon AVCHD footage with Mplayer? No, ... audio only with mplayer on all 3 of my PCs (including my Intel core2 duo P8400). But I use a version of mplayer packaged by the Packman rpm/application 3rd party packagers for openSUSE, and I know one user (who packages the scripts xvidenc (http://xvidenc.sourceforge.net/index.html) , h264enc (http://h264enc.sourceforge.net/index.html) , and divxenc (http://divxenc.sourceforge.net/index.html) ) who claims he has yet to find an AVCHD format his custom compiled mplayer can not handle. (I do not compile mplayer myself). I replied to one of his posts with a link to a recent AVCHD and asked if he could confirm that still the case ... he has not got back to me yet.
h-munster 03-09-09, 02:58 AM @oldcpu
Thanks for reminding me of the h264enc/xvidenc/divxenc scripts. It appears that these scripts handle batch encodings, and that they also can use the detc pulldown removal plugin. I might try one of these.
Thanks,
-Dale
.... the h264enc/xvidenc/divxenc scripts. It appears that these scripts handle batch encodings, and that they also can use the detc pulldown removal plugin. I might try one of these.They are handy scripts. I use xvidenc a fair amount.
I confess most of their features, I know nothing about. There is an explanation here:
http://h264enc.sourceforge.net/faq.html
... and reference pull down, after reading your post, I now note this :
- Video filters
* 11 software scaling filters (fast bilinear, bilinear, bicubic, experimental, nearest neighbor/point, area averaging, luma bicubic/chroma bilinear, gaussian, sinc, lanczos, natural bicubic spline)
* 5 deblock/dering postprocessing filters (spp, uspp, fspp, pp7, ha/va/dr)
* 5 denoise filters (denoise3d, hqdn3d, ow, tn, x264's internal denoiser)
* 1 (un)sharp mask/gaussian blur filter (unsharp)
* 10 different deinterlacers (lb, li, ci, md, fd, l5, yadif, tfields, mcdeint, kerndeint)
* 5 inverse telecine/3:2 pulldown filters (pullup, filmdint, ivtc, detc, telecine)
* Automatic brightness/contrast control filters
* 1 software equalizer filter (eq2)
* 1 interlacing filter (tinterlace combined with the phase filter)
* 2 frame rate conversion filters (filmdint, framestep)
which I am certain you noted before I (as most of this is typically beyond my knowledge).
h-munster 03-25-09, 03:53 PM I found a way to remove the 24P pulldown on all the AVCHD files generated by my Canon HF11.
[Note: the method described in this post is being superceded by the easier/faster "pu-avchd" script explained in message #158 below]
Unfortunately, one has to play each file for about 10-15 seconds to determine on which frame it starts in the 3:2 pulldown cadence. Then one moves the file into a corresponding directory, before it can be batch encoded. Eventually, these two manual steps will probably be eliminated/automated.
The below procedure works for Linux, Unix and probably OSX, as long as the versions of mencoder and ffmpeg are recent. The process is simpler than it looks.
Enjoy!
-Dale
=============
PULLDOWN REMOVAL FOR CANON 24P AVCHD FOOTAGE, USING MENCODER AND FFMPEG IN LINUX/UNIX/OSX
WHEN SHOOTING:
- Upon pressing the camera's start button, swipe your hand side-to-side in front of the lens for one second, or pan back-and-forth for one second. This movement will make it much easier to determine which frame of the 3:2 pulldown cadence starts the file (especially when the subject is standing still).
PREPARE YOUR ENCODING DIRECTORIES:
- Put all of the AVCHD files into the desired directory for your project, and, in that directory, create five sub-directories labeled "0", "1", "2", "3" and "4".
DETERMINE EACH FILE'S STARTING FRAME AND MOVE THE FILES TO THEIR CORRESPONDING DIRECTORY:
- Open a terminal, and "CD" to the directory that contains the AVCHD files.
- To play an AVCHD file one-frame-at-a-time, use the command, "mplayer -demuxer lavf -vc ffh264 your_avchd_file.mts". Press the spacebar immediately after pressing "enter" on this mplayer command, which will pause the video on the first or second frame (you can see on which frame it stops). To advance one-frame-at-a-time, press the period (".") key. This method allows you to count through the cadence and determine on which frame the video starts. Once you get the hang of this procedure, it should take about 10-15 seconds to determine the starting frame.
- Here are the five different pulldown cadence patterns ("P"=progressive frame and "I"=interlaced frame):
PPPII -- starts on frame #0
PPIIP -- starts on frame #1
PIIPP -- starts on frame #2
IIPPP -- starts on frame #3
IPPPI -- starts on frame #4
- When you determine on which frame the file's 3:2 cadence starts, move that file to the corresponding sub-directory.
- Repeat this "starting-frame-discovery" procedure on each file, until all the files are moved to their corresponding directories.
- By the way, you could put all files starting on frames #0, #1 and #2 into one directory, because they use the same pulldown removal filter. However, it is probably good to keep each type of file in a separate directory, so that you can recover easily just in case you uniformly miscount/mis-designate every file in a directory (e.g. all the files you designated to be #1 are actually #3 files).
ENCODE THE FILES:
- Get the three mffpeger scripts: mffpeger012; mffpeger3; and mffpeger4. I have put them here: http://marks.org/avchd/mffpeger/
- In your terminal, "CD" to each subdirectory and use the corresponding mffpeger script (mffpeger012 for sub-directories "0", "1" and "2"; mffpeger3 for sub-directory "3"; and mffpeger4 for sub-directory "4").
- Because the mffpeger script is not interactive (it does not use switches/flags to change settings on the command line), it is probably best to put a copy of the script into each subdirectory and use that script, rather than running the script globally (for instance, from within /usr/local/bin). This way, changes to the settings can be made within the script, and they won't affect the script's use elsewhere. Of course, to use a script in the current directory, one merely types "./name_of_script" at the terminal prompt, and then presses "enter".
- If you continually get skipped/dropped frame errors during the mencoder stage, try using one of the other two scripts on the file. By the way, after the pulldown has been removed, there should be no duplicate frames -- you can see duplicate frames by advancing through the footage one-frame-at-a-time in mplayer.
- The mffpeger default file format is Quicktime files (.mov), to use in Final Cut Pro. If you have a Mac computer and these files don't play in Quicktime or FCP, try installing the free Perian utility: http://perian.org/ and then try to play the footage.
TO DO:
1. Find a way to adjust the settings on one of mencoder's fancy, pulldown removal filters, so that a single script can remove the pulldown on all of the files, regardless of the starting frame.
2. Make the script interactive, so that settings (such as frame rate, pulldown removal, file paths, deinterlacing, frame rates, etc.) can be specified on the command line.
3. Explore streaming raw video during encoding. It might be faster/better to pipe a raw video stream out of mencoder and into ffmpeg, but I am not sure how to do that. I have seen scripts that pipe a raw video stream from mplayer into ffmpeg, but this method seems to necessitate that the audio be encoded/copied on a separate pass.
4. Convert the mffpeger script to work in Windows.
I could definitely use some help with these tasks. I am a novice, so it will probably take a lot of time/effort for me to find these command/script settings on my own, merely poking-around by trial-and-error.
mooninite 04-03-09, 10:52 PM h-munster, that's a good set of instructions. Let me help you out a little.
You should use libx264 instead of mpeg4 and mkv instead of mov. Knock the bitrate down from 35k... to 25k...
Also, for 30FP pulldown removal, use the following:
mencoder $i -fps 60000/1001 -oac pcm -demuxer lavf -vf pullup,softskip -ofps 30000/1001 -ovc lavc -lavcopts vcodec=ffvhuff:format=YV12:vstrict=-1:aspect=16/9 -o $INTERMED
You can use fifos by using mplayer -> ffmpeg.
mplayer -vo yuv4mpeg:file=videoout.fifo
ffmpeg -f yuv4mpegpipe -i videoout.fifo
h-munster 04-04-09, 03:26 AM mooninite, thank you very much for the help.
I was aware of the named pipes (fifos) for mplayer/ffmpeg, but I was wondering how to pipe from mencoder into ffmpeg. Mplayer stutters on my machine when playing AVCHD files, even with the "-demuxer lavf -vc ffh264" flags.
Just curious, why is libx264 is better than mpeg4? Isn't AVCHD already H264? And isn't the severe H264 compression the reason why AVCHD is so CPU intensive?
So, for my files to play on most machines and for my files to be editable on most non-linear editors, shouldn't I be trying to get away from H264 compression?
Also, Final Cut Pro has to be able to play my files. So, isn't the Quicktime (.mov) container better than mkv? Every time I mention mkv to an FCP editor, I get a blank stare!
In regards to bitrate, I would love to yield MPEG2 video at 35Mb/s. Mpeg4 (or mencoder/ffmpeg) doesn't seem to allow a constant bitrate of more than about 30 Mb/s. Same with H264 encoded by mencoder/ffmpeg.
Pu-avchd seems to be much better than mffpeger
Since I posted the mffpeger script, I have found a single-pass mencoder command that, so far, seems to successfully remove the pulldown from all Canon ".mts" files -- which means there is no need to play each file to find its starting frame!
Furthermore, it encodes a lot faster than mffpeger (at a varying rate of between 10fps to 20fps), in about 1/6th of the time taken by mffpeger!
I cannot discern any difference in the resulting video quality between the two methods.
Here is the command:
mencoder input_file.mts -o output_file.mov -noskip -mc 0 -oac lavc -demuxer lavf -vf pullup,softskip -ovc lavc -lavcopts acodec=libfaac:abitrate=256:vcodec=mpeg4:vqscale=2:aspect=16/9 -of lavf -lavfopts format=mov -fps 60000/1001 -ofps 24000/1001
Incidentally, the "pullup" filter can be replaced with the "detc" filter, and the command still seems to work on all AVCHD *mts files generated by my Canon HF11. I switched from specifying a constant bitrate to specifying the maximum quality -- "vqscale=2" (vqscale=1 is not necessarily better quality, and there are warnings that vqscale=1 can cause wierd side effects).
I was unable to make the audio/video properly sync when specifying the pcm codec (-oac pcm), as in mffpeger. The audio from the above command seems to have less "bite" than pcm, but it seems to sync better. If anyone knows how to maintain the audio quality, while keeping the sync intact, I would wellcome any suggestions.
I put this command in a "script" to convert a batch of "*mts" files in the current directory into ".mov" files. I call the script, "pu-avchd":
#!/bin/bash
## pu-avchd -- remove the pulldown from a batch of Canon FP24, AVCHD files (.mts),
## and then convert them to Quicktime (mov).
##
## Please send any modified versions of this script to me at h_munster@gmx.com.
## Thanks, -Dale
for i in *mts;
do
ORIGINAL=`basename $i .mts`
FINAL=${ORIGINAL}.mov
## Mencoder command.
mencoder $i -o $FINAL -noskip -mc 0 -oac lavc -demuxer lavf -vf pullup,softskip -ovc lavc -lavcopts acodec=libfaac:abitrate=256:vcodec=mpeg4:vqscale=2:aspect=16/9 -of lavf -lavfopts format=mov -fps 60000/1001 -ofps 24000/1001
done
The "vqscale=2" flag seems to encode with a variable bitrate, and it yields smaller files with slightly lower average bitrates than the constant bitrate flag in the mffpeger script.
The big question now is whether or not the .mov files resulting from pu-avchd are playable in Quicktime/FCP. I have to get a Mac friend to try to play them. It is possible that the Perian utility might have to be installed on the Mac machine, for these files to play.
I am still experimenting with different options/flags. With most of the files, the audio track runs about 0.13 seconds shorter than the video track, so I am considering delaying the audio track in mencoder to compensate for this slight difference.
Any comments or tips are appreciated.
Thanks,
-Dale
mooninite 04-04-09, 09:32 PM mooninite, thank you very much for the help.
I was aware of the named pipes (fifos) for mplayer/ffmpeg, but I was wondering how to pipe from mencoder into ffmpeg. Mplayer stutters on my machine when playing AVCHD files, even with the "-demuxer lavf -vc ffh264" flags.
mencoder is an *encoder* and you cannot output to a fifo. mplayer is a *player* and can output to a fifo. When you are using mplayer to output to a fifo, it does not playback at real-time because it's waiting on the program on the other end of the fifo to accept data. Your "stuttering" computer won't cause any problems with a fifo pipe when using mplayer.
Just curious, why is libx264 is better than mpeg4? Isn't AVCHD already H264? And isn't the severe H264 compression the reason why AVCHD is so CPU intensive?
So, for my files to play on most machines and for my files to be editable on most non-linear editors, shouldn't I be trying to get away from H264 compression?
Yes, AVCHD is h.264, which is MPEG-4 layer 10, but what you are doing is taking h.264 video and transcoding to MPEG-4 layer 2... which is worse than you started with. That's why I recommended that you stick with H.264. If your computer can't handle h.264, then it is time to upgrade. Sticking with h.264 will retain PQ while changing codecs will make your video worse.
Also, Final Cut Pro has to be able to play my files. So, isn't the Quicktime (.mov) container better than mkv? Every time I mention mkv to an FCP editor, I get a blank stare!
Time to find new software. kdenlive will negate all of what you are doing as when ffmpeg gets AVCHD support you can edit straight from the .MTS files from your cam.
In regards to bitrate, I would love to yield MPEG2 video at 35Mb/s. Mpeg4 (or mencoder/ffmpeg) doesn't seem to allow a constant bitrate of more than about 30 Mb/s. Same with H264 encoded by mencoder/ffmpeg.
You do not seem to understand the differences in the codecs you are using. I would recommend that you spend some time reading up the differences between MPEG-2, MPEG-4, and H.264 (MPEG-4 layer 10). Using 35Mb does nothing for your video except take up more disc space unnecessarily.
h-munster 04-06-09, 03:09 PM mooninite,
Thank you for the tips. I figured that the mplayer stuttering wouldn't matter, but there seemed to be other pipe options available with encoders, so I tried them first.
I am a little confused after your explanation about not being able to pipe the output from encoders. I thought that one could do so and also could use named pipes on the output of ffmpeg (which is an encoder).
I found some sites that mentioned these possibilities. Here is the FAQ section from ffmpeg.org showing the use of named pipes on the ffmpeg output: http://www.ffmpeg.org/faq.html#SEC30 Here is a procedure that pipes the output of mencoder: http://wiidiaplayer.wordpress.com/category/mencoder/
In message #136 of this very thread, alecmuffett posted a link to his hdffxvrt script, which seems to pipe output from the ffmpeg encoder.
I just wanted to pipe the output from mencoder into ffmpeg, with or without named pipes.
However, that piping procedure is probably unnecessary, because the single-pass mencoder command in pu-avchd seems to work better. I just have to make sure that my clients (mostly Mac/FCP users) can use the resulting files.
In regards to sticking with H264 on the output, I tried this comand:
mencoder input_file.mts -o output_file.mov -noskip -mc 0 -oac lavc -demuxer lavf -vf pullup,softskip -ovc lavc -lavcopts acodec=libfaac:abitrate=256:vcodec=libx264:vbitrate=24000000 :aspect=16/9 -of lavf -lavfopts format=mov -fps 60000/1001 -ofps 24000/1001
It looked good, but it stuttered in mplayer.
I used the "vbitrate=24000000" flag instead of "vqscale=2", because the "vqscale=2" results looked crappy.
I also tried other formats (mpeg4 in avi, mpeg2 in avi, etc.) at higher bitrates, and I cannot perceive any difference between those videos and the H264 video. I even compared identical, captured, still frames.
I can discern only a very slight difference between the pu-avchd mpeg4 results and the higher bitrate H264 and avi files. However, the difference is almost imperceptible -- the pu-avchd files have slightly less grain/sharpness in certain fleeting areas and moments. I have not spotted any artifacts in any of the videos.
Regarding the tip to get new software, unfortunately, Final Cut Pro (and Avid) software is what my clients usually own. They would probably hire someone else if I relayed your suggestion to them.
The Kdenlive potential is encouraging. However, I think ffmpeg can already decode/read AVCHD -- it just cannot remove the Canon 24P pulldown.
You are correct. I don't understand all of the differences between the many codecs and containers. No matter how much I read about all of the little features and nuances in codecs/containers, I seem to get more confused and forgetful about the subject. I only have so many brain cells!
The reason why I desired MPEG2 video at 35Mb/s is because those "settings" are what the FCP editors report they are using on their timeline from certain Sony cameras. I would like to match those settings as closely as possible.
My compressed AVCHD files supposedly have a bitrate of 25 Mb/s, while ffmpeg reports that the raw video from those files is around 300,000 Mb/s! So, I just want a bitrate that is "in between," and I want files that FCP can use.
Thanks,
-Dale
yeahyeahyeah 06-21-09, 03:34 PM :confused::confused::confused:how do i post a forum of my own??? i only know how to reply. please reply i need help!!!:confused::confused::confused:
h-munster 06-22-09, 02:08 PM how do i post a forum of my own??? i only know how to reply. please reply i need help!!!
I assume that you mean that you want to start a new forum thread.
To do so, find the page that shows the list of threads in the forum in which you wish to post, and then click on the "New Thread" button.
If you do not see a "New Thread" button, it could be that your thread-starting capabilities are restricted until you make a certain number of posts, or check to see if javascript is enabled in your browser.
|
|