I want to make all my movies on an external drive playable on the Roku 3. The complication is that most of the files contain a variable number of audio tracks (main, director's commentary, perhaps a second language track, etc), and +/- subtitle tracks.
I've selected all the .mkv and .m4v files with AC3-only audio, extracted the first audio track, and created the AAC equivalent. To add the new AAC audio track to the .mkv files I use "mkvmerge -o new-movie.mkv movie.mkv movie.aac". How do I accomplish this with ffmpeg (or other program with a CLI) for the .m4v files and not clobber any of the existing tracks? My usual OS is Linux, however Windows 7 is available as well.
Thank you in advance.
+ Reply to Thread
Results 1 to 6 of 6
-
-
I found the initial answer to my question with the command
Code:ffmpeg -i movie.m4v -i movie.aac -c copy -map 0 -map 1 new-movie.m4v
Code:ffmpeg -i movie.m4v -map 0:a:0 -vn -acodec copy movie.ac3 ffmpeg -i movie.ac3 -acodec libfaac movie.aac
Code:[...] Stream #0:0(und): Video: h264 (avc1 / 0x31637661), yuv420p, 718x480 [SAR 8:9 DAR 359:270], q=2-31, 1340 kb/s, 23.98 fps, 23.98 tbr, 90k tbn, 90k tbc (default) Metadata: creation_time : 2014-05-14 14:08:36 encoder : JVT/AVC Coding Stream #0:1(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), 384 kb/s (default) Metadata: creation_time : 2014-05-14 14:08:36 Side data: unknown side data type 7 (4 bytes) Stream #0:2(und): Subtitle: mov_text (text / 0x74786574) Metadata: creation_time : 2014-05-14 14:08:36 Stream #0:3: Audio: aac (mp4a / 0x6134706D), 48000 Hz, 5.1, 195 kb/s Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Stream #0:2 -> #0:2 (copy) Stream #1:0 -> #0:3 (copy) Press [q] to stop, [?] for help [ipod @ 0x1bd29e0] Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg) av_interleaved_write_frame(): Operation not permitted frame= 1961 fps=0.0 q=-1.0 Lsize= 15962kB time=00:01:21.88 bitrate=1596.8kbits/s video:12060kB audio:3839kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.395979% Conversion failed!
Code:ffmpeg -i movie.m4v -i movie.aac -c copy -bsf:a aac_adtstoasc -map 0 -map 1 new-movie.m4v
Code:[...] Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:1 -> #0:1 (copy) Stream #0:2 -> #0:2 (copy) Stream #1:0 -> #0:3 (copy) Press [q] to stop, [?] for help [NULL @ 0x2732500] Error parsing ADTS frame header! Failed to open bitstream filter aac_adtstoasc for stream 0 with codec copy: Invalid data found when processing input [NULL @ 0x2732500] Error parsing ADTS frame header! Failed to open bitstream filter aac_adtstoasc for stream 0 with codec copy: Invalid data found when processing input [NULL @ 0x2732500] Error parsing ADTS frame header! Failed to open bitstream filter aac_adtstoasc for stream 0 with codec copy: Invalid data found when processing input [...]
Thanks. -
Found the solution, use a mp4 container for the AAC file. This assumes the AC3 track is the first audio track.
Code:ffmpeg -i movie.m4v -map 0:a:0 -vn -acodec libfaac movie.mp4 ffmpeg -i movie.m4v -i movie.mp4 -c copy -map 0 -map 1 new-movie.m4v
-
Here's the Readme file I created to help me the next time I have to do this and the painfully gathered knowledge has evaporated. It's not meant to be used in a "fire and forget" mode. I cut and paste the shell fragments, run each individually, verify the results, then go on to the next step.
Cheers!
Paul Pomes, DVM
http://www.FurryFriendsVet.com
Code:# AAC-from-AC3 # # My Roku 3 does not support the AC-3 audio codec. To make all my movies # playable I've created this set of scripts to extract the AC-3 track from # movies that lack an AAC track, convert that to AAC, and layer it back into # the MKV or M4V container as an additional track while preserving all # existing tracks. # This collection of scripts generates action scripts. I'm cautious about # overly-automating conversions since a mistake could trash a lot of effort. # Backups are an excellent idea, however mine are currently on CONUS while # I'm working on Guam with a USB drive copy. Once the action scripts are # created, I test them on a single movie to make sure the results are what # I intend before letting it go full-auto on the rest. # # Paul Pomes, DVM # paul@pomes.org # www.FurryFriendsVet.com # Identify which files lack an AAC track rm -i mkv-files m4v-files for i in *mkv do mediainfo "$i" | grep -q AAC if [ $? -ne 0 ] ; then echo $i >> mkv-files ; fi done for i in *m4v do mediainfo "$i" | grep -q AAC if [ $? -ne 0 ] ; then echo $i >> m4v-files ; fi done # Identify which audio track is the main AC-3 track. Almost always this will be # track 1. Exceptions - say it's track 3 - can be handled by hand edits of # the extraction scripts. For MKV files change "1:[...]" to "3:[...]" # (see examples below). For M4V change "-map 0:a:0" to "-map 0:a:2". # Create extraction and conversion scripts. First is for MKV containers, # the second for M4V. AC-3 to AAC is the slowest part of this whole process # which for 40 movies took overnight. while read i do j=`basename -s .mkv "$i"` echo -n "mkvextract tracks \"$i\" " mkvmerge -i "$i" | grep AC3 | head -1 | sed -e "s/.*\(.\):.*/\1:\"$j.ac3\" ; \\\\ /" echo "ffmpeg -i \"$j.ac3\" -acodec libfaac \"$j.aac\"" done < mkv-files while read i do j=`basename -s .m4v "$i"` echo -n "ffmpeg -i \"$i\" -map 0:a:" echo -n $((`mkvmerge -i "$i" | grep AC3 | head -1 | sed -e "s/.*\(.\):.*/\1/"` - 1)) echo " -vn -acodec libfaac \"$j.mp4\"" done < m4v-files # Mux the new AAC files into the original containers while read i do j=`basename -s .mkv "$i"` k="$j-new.mkv" echo "mkvmerge -o \"$k\" \"$i\" \"$j.aac\"" echo "ls -lh \"$k\" \"$i\"" echo "mkvmerge -i \"$i\"" echo "mkvmerge -i \"$k\"" echo "mv -i \"$k\" \"$i\"" done < mkv-files while read i do j=`basename -s .m4v "$i"` k="$j-new.m4v" echo "ffmpeg -i \"$i\" -i \"$j.mp4\" -c copy -map 0 -map 1 \"$k\"" echo "ls -lh \"$k\" \"$i\"" echo "mkvmerge -i \"$i\"" echo "mkvmerge -i \"$k\"" echo "mv -i \"$k\" \"$i\"" done < m4v-files
Similar Threads
-
Add MP3 Track to M4V video?
By Rugratskid in forum AudioReplies: 1Last Post: 5th Apr 2014, 12:14 -
Add an audio track or replace the audio track of an AVI
By abrafax in forum Newbie / General discussionsReplies: 9Last Post: 1st Oct 2012, 14:34 -
How to Merge multiple Video tracks into one with a separate Audio track
By Mark97213 in forum Authoring (Blu-ray)Replies: 2Last Post: 30th Aug 2012, 00:36 -
HOW do I extract 1 audio track from a .ts / .m2ts with 4 audio tracks?!
By elgy in forum DVB / IPTVReplies: 25Last Post: 23rd Jan 2011, 23:28 -
How to choose audio track in avi file with two audio tracks
By newnews in forum AudioReplies: 3Last Post: 26th Oct 2010, 05:26