4

I am using h264 for optimising MP4 for web. I have a video which has some supposedly corrupt frame(s) within it's initial 1-2 seconds. (Frame provided below)Corrupt Frame As seen in VLC Media Player.

On transcoding using :

ffmpeg -i orig.mp4 -c:v libx264 -crf 25 -vf scale="-2:min(ih\,720)" -b:v 600K -g 90 -c:a libfdk_aac output.mp4

The output MP4 has these frames dropped out and I have my output with it's start about 1 to 2 seconds delayed from original video, thus resulting in overall less time duration in output video.

Moreover, most media players also skip these frames in playback (like quicktime player, etc). But VLC media player was able to play this video without skipping these frames.

Is there a way to not drop frames using ffmpeg? And if possible is it possible to identify and fix these frames in a video?

Note: I tried encoding same video using AWS Elastic transcoder which actually fixed these frames (Frame provided below) : Frame from video transcoded by Elastic Transcoder

Note: Original video can be found here - https://drive.google.com/file/d/0B9VkhR9Zu60ybXFDeno3RGpQTUE/view?usp=sharing Video transcoded by AWS Elsatic transcoder can be found here - https://drive.google.com/file/d/0B9VkhR9Zu60yWUVHQk5MTk05QVk/view?usp=sharing

EDIT1: As suggested by @Mulvya in comments, TS-transcoded video can be found here - (https://drive.google.com/file/d/0B9VkhR9Zu60yU0t6T0dMME9ZMmc/view?usp=sharing)

Community
  • 1
  • 1
t6nand
  • 710
  • 1
  • 8
  • 20
  • I can't reproduce the behaviour with your original video. – Gyan Jul 13 '17 at 07:50
  • Hi. Try opening original video using VLC media player. You will be able to observe corrupt frame within 1st 1 to 2 seconds. Also Take a look at this video transcoded by AWS elastic transcoder - (https://drive.google.com/file/d/0B9VkhR9Zu60yWUVHQk5MTk05QVk/view?usp=sharing) . You will clearly see the difference in initial frames and video time duration. This transcoding was done using original video provided in question. – t6nand Jul 13 '17 at 07:59
  • And just to add if it helps to reproduce the issue, I tried extracting every frame from original video both using ffmpeg and vlc media player. Ffmpeg started it's extraction after these corrupted frames. However, using video scene filter on VLC to extract frames I was able to get these corrupted frames as one shown in question. – t6nand Jul 13 '17 at 11:18
  • Run `ffmpeg -i orig.mp4 -c copy orig.ts` and transcode that. – Gyan Jul 13 '17 at 11:26
  • Hi, Thanks. It worked and transcoded videos were correct. But is it possible to detect such issues in videos firsthand and only run this command when there is some problem. – t6nand Jul 13 '17 at 11:54
  • Check the start time. It should be only slightly negative e.g. `-0.05` at most. `0` or positive is also fine. – Gyan Jul 13 '17 at 11:56
  • This method appears to copy first frame of video in initial 1-2 seconds. It's not exactly what I want. Checked it by extracting frames and first 18 frames were 1st frame copied. Can you confirm this? – t6nand Jul 13 '17 at 12:07
  • No. Don't rely on frame extraction to check. FFmpeg defaults to CFR emulation unless set [otherwise](https://stackoverflow.com/q/45066008/5726027), so it will duplicate frames. Check the first few frames of aws and TS-transcode in a player. – Gyan Jul 13 '17 at 12:28
  • On comparing AWS and TS-transcoded videos for first few frames in a player there are visible differences. AWS transcoded video appears to have fixed all corrupted frames, but in TS-transcoded video there was duplication of frame as you explained earlier. Here is TS-transcoded video for reference (https://drive.google.com/file/d/0B9VkhR9Zu60yU0t6T0dMME9ZMmc/view?usp=sharing) – t6nand Jul 13 '17 at 12:56

2 Answers2

3

Your source video has some frames without timestamps.

In this particular case, extracting to raw bitstream and then transcoding works:

ffmpeg -i orig.mp4 -c copy orig.264

ffmpeg -i orig.264 -i orig.mp4 -map 0 -map 1:a -c:v libx264 -crf 25 -vf scale="-2:min(ih\,720)" -b:v 600K -g 90 -c:a libfdk_aac output.mp4
Gyan
  • 85,394
  • 9
  • 169
  • 201
1

Converted video to raw video only file

ffmpeg -i VID_1550287359485.mp4 -vcodec copy -an -bsf:v h264_mp4toannexb raw2.h264
ffmpeg -framerate 24 -i raw2.h264  -c copy output-a.mp4

Extracting audio from video in mp3 format

ffmpeg -i VID_1550287359485.mp4 -b:a 192K -vn music2.mp3

Fixing the issue with audio and video length

ffprobe -i  music2.mp3  -show_entries  format=duration  -v quiet  -print_format json
ffprobe -i  output-a.mp4  -show_entries  format=duration  -v quiet  -print_format json
ffmpeg  -i music2.mp3 -filter:a atempo="0.827415438" new-latest2.mp3

Rotate video 90 degree anticlockwise

ffmpeg -i output-a.mp4 -vf "transpose=2" output-new.mp4

Merging the video and audio to make the output file

ffmpeg -i output-new.mp4 -i new-latest2.mp3 -c:v libx264 -c:a aac -strict experimental -shortest output-second.mp4
Akhilraj N S
  • 9,049
  • 5
  • 36
  • 42