Edit MP4 videos with AviSynth and save back to MP4 using AviDemux

Started by lukalev, August 02, 2013, 11:28:34 PM

Previous topic - Next topic



i'd like to share my experience and describe how to process/edit MP4(AAC) videos in  windows 7 (x64) using scripting with AVISynth and saving them back to MP4 using Avidemux.
MP4 containers are harder to process compared to AVIs and this process also isn't straight forward as i thought it would be...
I've tried lots of combinations (virtualDub+plugins+converters,avanti,ffmpeg,etc) which didn't work for me in some details
so i ended with Avidemux Proxy with custom AVISynth script which worked perfectly!

My goal was to crop/cut multiple videos with different frame rates and dimensions to a 3 minutes length (dynamically with calculation of frames), append a blank/black 1 minute long clip or a image with embedded text using a single script.

Here are the steps needed:
(since i've tried/installed lots of things i could be describing unnecessary additional steps but it doesn't hurt:)
1. install last version of AviSynth
2. install last version of Haali Media Splitter (MatroskaSplitter installer)
3. install ffdshow, assign AviSynth checkbox, after installation open video decoder configuration->Codecs->Raw video=all supported
4. download Win7DSFilterTweaker 5.9, extract it and run Win7DSFilterTweaker_5.9.exe.
Go to preffered decoders and select ffdshow on MP4, AAC,etc
5. install avidemux (assign AviSynth checkbox)
6. download and unzip ffmpegsource avysinth plugin. Copy its conent wherever you want.
I've opened myself a common folder for testing on c:\video. Inside i've copied ffmpegsource files, created my avs file, copied mp4 files, images, etc...

Write a avisynth script into notepad and save it with avs extension. Bellow is my code (look at avisynth wikipedia for syntax and functions descriptions).
After you save the file open this same .avs file with media player to see if it works. Any syntax errors should be displayed to you in media player itself...
Final step is to save .avs script back to MP4. To do this open AVIDemux Proxy GUI, select custom script tab and insert your avs script in there.
Click create proxy. Open AViDemux program, go to file->connect to avsproxy and you should be able to see the video inside Avidemux.
Now you can play with the Output settings. I usually leave Video output to Copy or select MPEG-4, select Audio source AAC Faac and Output format MP4 Muxer.
Finally go to file->save, type filename.mp4 and save it!

Thats it. Note that your process may not be exactly the same as mine because we all have different systems, installed programs, different register values, etc.
If it does not work for you, you may want to uninstall everything and begin from zero.

Good luck,

#A=DirectShowSource(file, video=False)
openv1=FFmpegSource2(file, atrack = -1)
#openv1=FFmpegSource2(file, atrack = -1, colorspace="YV12")
#v1 = cap1.ChangeFPS(4)
#v2 = cap2.ChangeFPS(4)
videoLength=FrameCount(openv1)<=videoLength ? FrameCount(openv1) : videoLength
Subtitle("Some text here", first_frame=FrameCount(openv1)-int(UCLength),font="arial", size=24, text_color=$FFFFFF, align=5)