]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/segafilmenc.c
avformat/vivo: set packet duration
[ffmpeg] / libavformat / segafilmenc.c
index 524230e461c769a67566543dea71be3fe6970915..29851444b32fbdae868c0cecead646ab196700ef 100644 (file)
@@ -45,7 +45,6 @@ typedef struct FILMPacket {
 } FILMPacket;
 
 typedef struct FILMOutputContext {
-    const AVClass *class;
     int audio_index;
     int video_index;
     int64_t stab_pos;
@@ -70,7 +69,7 @@ static int film_write_packet_to_header(AVFormatContext *format_context, FILMPack
         info2 = pkt->duration;
         /* The top bit being set indicates a key frame */
         if (!pkt->keyframe)
-            info1 |= (1 << 31);
+            info1 |= 1U << 31;
     }
 
     /* Write the 16-byte sample info packet to the STAB chunk in the header */
@@ -147,10 +146,8 @@ static int get_audio_codec_id(enum AVCodecID codec_id)
     case AV_CODEC_ID_PCM_S8_PLANAR:
     case AV_CODEC_ID_PCM_S16BE_PLANAR:
         return 0;
-        break;
     case AV_CODEC_ID_ADPCM_ADX:
         return 2;
-        break;
     default:
         return -1;
     }
@@ -183,13 +180,24 @@ static int film_init(AVFormatContext *format_context)
                 av_log(format_context, AV_LOG_ERROR, "Sega FILM allows a maximum of one video stream.\n");
                 return AVERROR(EINVAL);
             }
+            if (st->codecpar->codec_id != AV_CODEC_ID_CINEPAK &&
+                st->codecpar->codec_id != AV_CODEC_ID_RAWVIDEO) {
+                av_log(format_context, AV_LOG_ERROR,
+                       "Incompatible video stream format.\n");
+                return AVERROR(EINVAL);
+            }
+            if (st->codecpar->format != AV_PIX_FMT_RGB24) {
+                av_log(format_context, AV_LOG_ERROR,
+                       "Pixel format must be rgb24.\n");
+                return AVERROR(EINVAL);
+            }
             film->video_index = i;
         }
+    }
 
-        if (film->video_index == -1) {
-            av_log(format_context, AV_LOG_ERROR, "No video stream present.\n");
-            return AVERROR(EINVAL);
-        }
+    if (film->video_index == -1) {
+        av_log(format_context, AV_LOG_ERROR, "No video stream present.\n");
+        return AVERROR(EINVAL);
     }
 
     if (audio != NULL && get_audio_codec_id(audio->codecpar->codec_id) < 0) {
@@ -203,7 +211,7 @@ static int film_init(AVFormatContext *format_context)
 static int shift_data(AVFormatContext *format_context, int64_t shift_size)
 {
     int ret = 0;
-    int64_t pos, pos_end = avio_tell(format_context->pb);
+    int64_t pos, pos_end;
     uint8_t *buf, *read_buf[2];
     int read_buf_id = 0;
     int read_size[2];
@@ -295,11 +303,6 @@ static int film_write_header(AVFormatContext *format_context)
         }
     }
 
-    if (video->codecpar->format != AV_PIX_FMT_RGB24) {
-        av_log(format_context, AV_LOG_ERROR, "Pixel format must be rgb24.\n");
-        return AVERROR(EINVAL);
-    }
-
     /* First, write the FILM header; this is very simple */
 
     ffio_wfourcc(pb, "FILM");
@@ -322,9 +325,6 @@ static int film_write_header(AVFormatContext *format_context)
     case AV_CODEC_ID_RAWVIDEO:
         ffio_wfourcc(pb, "raw ");
         break;
-    default:
-        av_log(format_context, AV_LOG_ERROR, "Incompatible video stream format.\n");
-        return AVERROR(EINVAL);
     }
 
     avio_wb32(pb, video->codecpar->height);
@@ -364,8 +364,6 @@ static int film_write_header(AVFormatContext *format_context)
 
     avio_wb32(pb, film->packet_count);
 
-    avio_flush(pb);
-
     /* Finally, write out each packet's data to the header */
     packet = film->start;
     while (packet != NULL) {
@@ -378,12 +376,6 @@ static int film_write_header(AVFormatContext *format_context)
     return 0;
 }
 
-static const AVClass film_muxer_class = {
-    .class_name     = "Sega FILM muxer",
-    .item_name      = av_default_item_name,
-    .version        = LIBAVUTIL_VERSION_INT,
-};
-
 AVOutputFormat ff_segafilm_muxer = {
     .name           = "film_cpk",
     .long_name      = NULL_IF_CONFIG_SMALL("Sega FILM / CPK"),
@@ -394,5 +386,4 @@ AVOutputFormat ff_segafilm_muxer = {
     .init           = film_init,
     .write_trailer  = film_write_header,
     .write_packet   = film_write_packet,
-    .priv_class     = &film_muxer_class,
 };