Home... Help... Search... Computers...


Editing an MP4 Video in Linux using Avidemux and avconv

I needed to edit a short video as it had a incorrect word on some of the frames: "One" when it should have had "Won".

Here is how I achieved it. I'm sure there are better ways, and maybe I'll find one another time. For now, mission accomplished.

1. Avidemux showed me I had 4080 frames at 29.97 frames per second. It also showed me which frames I needed to edit. I also saved the audio as an MP3 file: Audio > Save ...

2. I used avconv (the replacement for ffmpeg) to output the frames from the video.

avconv -i original-video.mp4 -r 30 -f image2 %04d.png

This produces 0001.png, 0002.png, etc. The "%04d.png" controls the number of digits, so adjust as needed, eg, if you have between 10,000 and 99,999 frames, use "%05d.png".

3. I edited the incorrect frames using GIMP. Since they were all the same (part of a song's lyrics) I edited one and saved it as 0000-new.png. I just erased the word "One" from the image, then used GIMP's text tool to put in "Won". Before I saved it I needed to remove the "Alpha Channel", so that the format was plain RGB, same as the other frames. avconv will hit a error and drop frames if it finds a format change. In GIMP, Layer > Transparency > Remove Alpha Channel.

4. I used a BASH script to copy the edited frame over the target frames:-

#!/bin/sh
# fixFrames.sh

count=2273
while :
do
	COUNT=`awk -v x=$count ' { printf ("%0004d\n",x)}' 1.txt` 
	echo $count  $COUNT
	if [ $count -gt 2392 ]; then
		exit
	else
		cp 0000-new.png $COUNT.png
	fi
	count=`expr $count + 1`
done

Run it as ./fixFrames.sh

This replaces frames 2273 to 2392 inclusive with the edited one.

5. avconv then stitched the frames back into a new MP4 file (but without any audio).

avconv -r 30 -i %04d.png -s vga -vcodec libx264 -r 30 new-video.mp4

6. Back to Avidemux to put it all together:

Open the new-video.mp4 file in Avidemux.

Then add in the audio: Audio > Main Track > Select source as external MP3, then browse for the file saved in step 1.

Finally, save the video with the audio. I found that saving the video in "MPEG-4 AVC" form and the audio in "MP3 (lame)" form worked well.

All done.


Home... Help... Search... Computers...


This page http://tardus.net/editMP4.html published: 9 November 2016

About Tardus

Contact me, "Tardus" Copyright powered by txt2tags

Search tardus.net